Video Track Motion like After Effects

Hey guys,

Hope everyone well,

I am performing some challenges to myself, trying to code some things of AfterEffects on openframeworks, like this one http://www.videocopilot.net/tutorials/basic_sky_replacement/

  • video : OK
  • image : OK
  • linear wipe (shader/alpha mask) : OK
  • color key (shader) : OK
  • key tracking (openCV how?) : missing
  • post production (fbo + shader) : missing

Somebody can give me a hand to build this Track Point thing? similar like screenshot attached

PS: I am brazillian, so my english be a crap haha

Thanks in advice.

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

for keypoint tracking i would also recommend to look at the example-flow-keypoints of ofxCV

Hey guys, I put the result on git,

First video frame + controls

Track point selection (hold [t] click and drag)

Layer 1 (video) + Layer 2 (sky) disabled to show the color key working

Final result

TODO

Thanks,