Ask Your Question

tiwaria9034's profile - activity

2014-04-23 15:21:10 -0500 answered a question Video Stabilization using opencv

In your "warpAffine(frame,warped,Transform_avg,Size( frame.cols, frame.rows));" function, you must specify FLAG as WARP_INVERSE_MAP for stabilization.

Sample code I have written:

Mat src, prev, curr, rigid_mat, dst;

VideoCapture cap("test_a3.avi");

while (1) { bool bSuccess = cap.read(src); if (!bSuccess) //if not success, break loop { cout << "Cannot read the frame from video file" << endl; break; }

cvtColor(src, curr, CV_BGR2GRAY);

if (prev.empty())
{
    prev = curr.clone();
}

rigid_mat = estimateRigidTransform(prev, curr, false);

warpAffine(src, dst, rigid_mat, src.size(), INTER_NEAREST|WARP_INVERSE_MAP, BORDER_CONSTANT);


// ---------------------------------------------------------------------------//

imshow("input", src);
imshow("output", dst);

Mat dst_gray;
cvtColor(dst, dst_gray, CV_BGR2GRAY);
prev = dst_gray.clone();

waitKey(30);

}

Hoping this will solve your problem :)