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:
- Create a Videocapture object, read the frames in a loop and store them in a Mat.
- Convert the frames to HSV.
- Threshold each frame with inRange to show only my interest object using:
inRange(HSV,Scalar(0,203,130),Scalar(256,256,256),threshold);
- 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.