Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How change image position inside a VideoCapture

Hi everyone, im starting on opencv C++. Im working with object tracking and I want to put an image above the detected object in the Videocapture, but i don't find how to do it. First...it is posible? and if so, how can I do it? i hope you can guide me with anything, I'll appreciate this :D

click to hide/show revision 2
retagged

updated 2014-07-11 05:03:29 -0500

berak gravatar image

How change image position inside a VideoCapture

Hi everyone, im starting on opencv C++. Im working with object tracking and I want to put an image above the detected object in the Videocapture, but i don't find how to do it. First...it is posible? and if so, how can I do it? i hope you can guide me with anything, I'll appreciate this :D

How change image position inside a VideoCapture

Hi everyone, im starting on opencv C++. Im working with object tracking and I want to put an image above the detected object in the Videocapture, but i don't find how to do it. First...it is posible? and if so, how can I do it? i hope you can guide me with anything, I'll appreciate this :D

EDIT: Well my tracking works like:

  1. Create a Videocapture object, read the frames in a loop and store them in a Mat.
  2. Convert the frames to HSV.
  3. Threshold each frame with inRange to show only my interest object using:
    inRange(HSV,Scalar(0,203,130),Scalar(256,256,256),threshold);
  4. Send the thresholded image to the Tracking function:
 void trackObject(Mat threshold, Mat &dst)
    {
       Mat temp;
       Int x,y;
       threshold.copyTo(temp);
       vector< vector<point> > contours;
       vector<vec4i> hierarchy;
       findContours(temp,contours,hierarchy,CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE );
       if (hierarchy.size() > 0) {
           for (int index = 0; index >= 0; index = hierarchy[index][0]) {
              Moments moment = moments((cv::Mat)contours[index]);
              double area = moment.m00;
                  x = moment.m10/área;
                  y = moment.m01/area;
               }//end for
       }//end if
    }

(I deleted some code to simply te explanation)

In resume, I look for the contours, (I rely in a tutorial code, so I don't yet understand the hierarchy part), then i get the white points of the image whit 'Moments' and store the info in 'area'. And finally I get the x,y coordinates of the object calculating the centroid:

     x = moment.m10/área;
     y = moment.m01/area;

So my idea is instead of put a simply draw shape to indicate where is the tracked object, I want to use these coordinates to put above an image, like augmented reality.