Ask Your Question

How change image position inside a VideoCapture

asked 2014-07-10 20:37:29 -0600

SergioDiaz07 gravatar image

updated 2020-11-14 15:27:09 -0600

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. 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:
  4. Send the thresholded image to the Tracking function:
 void trackObject(Mat threshold, Mat &dst)
       Mat temp;
       Int x,y;
       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.

edit retag flag offensive close merge delete


yes, you an manipulate the images from the capture.

"put an image above the detected object" - that's quite vague, be more specific.

also, we don't know, how your tracking works.

berak gravatar imageberak ( 2014-07-11 05:03:10 -0600 )edit

Thanks berak, i filled the idea :)

SergioDiaz07 gravatar imageSergioDiaz07 ( 2014-07-11 14:54:51 -0600 )edit

ah, good. so, you already got the position, you could start all easy with some simple drawing and here are some more advanced things (like 3d and such)

berak gravatar imageberak ( 2014-07-11 15:00:48 -0600 )edit

1 answer

Sort by » oldest newest most voted

answered 2014-07-11 15:28:47 -0600

SergioDiaz07 gravatar image

updated 2014-07-11 19:11:56 -0600

About the drawing i think that I explain bad jajaja (english is my second languaje xd) i already use the drawing feature, so i want to use the coordinates to put a simple image above the original, like THIS but just move the image. And thanks for the link! i'll take a look to this :D

edit flag offensive delete link more

Question Tools


Asked: 2014-07-10 20:37:29 -0600

Seen: 361 times

Last updated: Jul 11 '14