Ask Your Question

jigarsen18's profile - activity

2013-06-24 01:26:32 -0500 asked a question Help me to track the mistake for measuring angles in opencv

Hi all,

Here i have put my code which is in c++. I am new in OpenCV. So Please Help me.

I found this code in Python and try to convert it in C++ and thanks to chris loughnane who is original author of this thing.click here for more detail.

enter code here
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include<opencv/cv.h>
#include <iostream>
#include <math.h>
#include <string.h>

using namespace cv;
using namespace std;

int main()
{
    CvCapture *capture  = cvCaptureFromCAM(0);
    cvNamedWindow("Target", 1);
    cvNamedWindow("Threshold1",1);
    cvNamedWindow("Threshold2",1);
    cvNamedWindow("hsv",1);

    //#initiate font
    CvFont *font;
    cvInitFont(font,CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 3, 8);
    //instantiate images
    IplImage* hsv_img = cvCreateImage(cvGetSize(cvQueryFrame(capture)),8,3);
    IplImage* threshold_img1 = cvCreateImage(cvGetSize(hsv_img),8,1);
    IplImage* threshold_img1a = cvCreateImage(cvGetSize(hsv_img),8,1);
    IplImage* threshold_img2 = cvCreateImage(cvGetSize(hsv_img),8,1);

    int i=0;
    CvCapture * writer;  // = cvCreateVideoWriter("angle_tracking.avi",CV_FOURCC('M','J','P','G'),30,cvGetSize(hsv_img),1);
    cvCreateVideoWriter("d:/1/1.avi",CV_FOURCC('M','J','P','G'),30,cvGetSize(hsv_img),1);

    while (true)
    {
       // capture the image from the cam
        IplImage *img = cvQueryFrame(capture);

        //convert the image to HSV
        cvCvtColor(img,hsv_img,CV_BGR2HSV);

        //threshold the image to isolate two colors

        cvInRangeS(hsv_img,cvScalar(165,145,100),cvScalar(250,210,160),threshold_img1);     //#red
        cvInRangeS(hsv_img,cvScalar(0,145,100),cvScalar(10,210,160),threshold_img1a);       //#red again
        cvAdd(threshold_img1,threshold_img1a,threshold_img1);                               //#this is combining the two limits for red
        cvInRangeS(hsv_img,cvScalar(105,180,40),cvScalar(120,260,100),threshold_img2);      //#blue


      //  #determine the moments of the two objects
        CvMat stub;
        CvMat *threshold_img1 = cvGetMat(threshold_img1,&stub);
        CvMat *threshold_img2 = cvGetMat(threshold_img2,&stub);

        CvMoments *moments1,*moments2;
        cvMoments(threshold_img1,moments1);
        cvMoments(threshold_img2,moments2);

        double area1 = cvGetCentralMoment(moments1,0,0);
        double area2 = cvGetCentralMoment(moments2,0,0);

        //initialize x and y
        float x1,y1,x2,y2=(1,2,3,4);
        float coord_list=(x1,y1,x2,y2);

        for (i=1; i < 4; i++)
        {
        int x=0;
        //there can be noise in the video so ignore objects with small areas

        if (area1 >200000)
        {
            //x and y coordinates of the center of the object is found by dividing the 1,0 and 0,1 moments by the area
            x1=int(cvGetSpatialMoment(moments1,1,0)/area1);
            y1=int(cvGetSpatialMoment(moments1,0,1)/area1);

            //draw circle
            cvCircle(img,cvPoint(x1,y1),2,CV_RGB(0,255,0),20);

            //write x and y position
            cvPutText(img,char (str(x1)+","+str(y1)),cvPoint(x1,y1+20),font, CV_RGB(255,0,0)); //#Draw the text
        }

        if (area2 >100000)
        {
            //x and y coordinates of the center of the object is found by dividing the 1,0 and 0,1 moments by the area
            x2=int(cvGetSpatialMoment(moments2,1,0)/area2);
            y2=int(cvGetSpatialMoment(moments2,0,1)/area2);

            //draw circle
            cvCircle(img,cvPoint(x2,y2),2,CV_RGB(0,255,0),20);

            //cvPutText(img,str(x2)+","+str(y2),cvPoint(x2,y2+20),font, cvScalar(255)); //#Draw the text
            cvLine(img,cvPoint(x1,y1),cvPoint(x2,y2),CV_RGB(0,255,0),4,CV_AA);
            //#draw ...
(more)
2013-06-17 00:19:04 -0500 commented question imread function not working

i think you have to put semicolon (;) after cout<<"Error!\n" I have check this code work OK.

2013-06-13 05:26:52 -0500 received badge  Critic (source)
2013-06-13 05:18:47 -0500 received badge  Student (source)
2013-06-11 06:06:20 -0500 commented question printf output is Not Display in Windows 7x64 (in Visual Studio 2012)

By the way i find my answer....By Self...

2013-06-11 06:00:59 -0500 commented question printf output is Not Display in Windows 7x64 (in Visual Studio 2012)

Hey man... my problem is different... OK.

look completely my question then comment..... by only reading title line can't predict the copy of anything.

2013-06-11 01:58:29 -0500 asked a question printf output is Not Display in Windows 7x64 (in Visual Studio 2012)

Hi every one,

Heading

const char* name="Hello";
int main(int argc, char** argv)
{
IplImage* img = cvLoadImage(argv[1]);
cvNamedWindow( name, CV_WINDOW_AUTOSIZE);
cvShowImage( name, img);
printf("HelloWorld...");
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow (name);

}

Here i only can see the image but "HelloWorld..." could't display.

What changes can i do for Basic Setting in Propsheet or any other place... Please suggest me..

Thank you in advanced...

2013-06-11 01:02:38 -0500 commented answer convert sequentially camera image to gray scale image

image created from cameraCapture - which form is that..? is it in RGB, HSV or other..? i use simple webcam which is of Laptop.

2013-06-10 01:20:43 -0500 answered a question Motion Detection with OpenCV (C++)

i think you have to start with Learning OpenCV Book - Read it. Here you can get the step by step method to use OpenCV.

yes first you have to link the library of openCv to visual studio. See the link steps to confi. opencv.

2013-06-10 00:44:06 -0500 commented answer convert sequentially camera image to gray scale image

here you can bypass the code line " cvCvtColor(img,img,CV_RGB2GRAY); " from the code then it work OK. but as an change in the image every time get error at the time when execute.

2013-06-10 00:40:05 -0500 received badge  Supporter (source)
2013-06-10 00:39:42 -0500 commented answer convert sequentially camera image to gray scale image

Thanks Notas for giving your valuable time....

one thing i would like to say that even if i change as you mention i couldn't able to execute the program. can you make it more clear.

Thanking you,

2013-06-10 00:16:45 -0500 commented question convert sequentially camera image to gray scale image

yes, i have created that folder...but cant execute the program.

2013-06-07 04:58:07 -0500 received badge  Editor (source)
2013-06-07 04:57:07 -0500 asked a question convert sequentially camera image to gray scale image

hi all,

i am new in programming in OpenCv.

i am not able to do cvCvtcolor command for the sequential images which is captured by cameraCapture command. please do needful.

Thank you in advanced..

my code is here...(I don't get compilation error.. but not get output images..)

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int c=1;
IplImage* img=0;
char buffer[2000];
CvCapture* cv_cap=cvCaptureFromCAM(1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
     img=cvQueryFrame(cv_cap);
  cvShowImage("Video",img);
  cvCvtColor(img,img,CV_RGB2GRAY);

  sprintf(buffer,"D:/1/ImageName%u.jpg",c);

  cvSaveImage(buffer,img);

  c++;
      if (cvWaitKey(100)== 27) break;
}

cvDestroyWindow("Video");
return 0;
}