Quantcast
Channel: openFrameworks - Latest posts
Viewing all articles
Browse latest Browse all 40524

Video Track Motion like After Effects

$
0
0

Right, I solve the key tracking using cvMatchTemplate

    //Copy selected portion of the image to the subject image;
    subjectFrame.x = x; // desired track point X
    subjectFrame.y = y; // desired track point Y
    subjectImg.allocate(subjectFrame.width, subjectFrame.height);
    grayImage.setROI(subjectFrame);
    subjectImg = grayImage;
    grayImage.resetROI();
    subjectIsDefined = true;

.

    /* motion track */
    colorImg.setFromPixels(videoPlayer.getPixels());
    grayImage = colorImg;

    if(subjectIsDefined)
    {
        IplImage * result = cvCreateImage(cvSize(desiredWidth - subjectImg.width + 1, desiredHeight - subjectImg.height + 1), 32, 1);

        cvMatchTemplate(grayImage.getCvImage(), subjectImg.getCvImage(), result, CV_TM_SQDIFF);

        double minVal, maxVal;
        CvPoint minLoc, maxLoc;
        cvMinMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, 0);

        subjectLocation.x = minLoc.x;
        subjectLocation.y = minLoc.y;

        cvReleaseImage( & result );
    }

Thanks


Viewing all articles
Browse latest Browse all 40524


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>