0

Hi I have tried to modify the lkdemo.cpp in OpenCV/sample/cpp. I want to get perspective transform and then warpPerspective. So I have added line (1) and (2) to do that. Where declaration for image and output are as follows:

Mat gray, prevGray, image, output;

....

calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize,
                                 3, termcrit, 0, 0.001);

 (1)   CvMat H = getPerspectiveTransform(points[0], points[1]); 
 (2)   cvWarpPerspective(&image, &output, &H,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0));

...

Now when I try to see the output of warp image using imshow() I'm getting this error:

error: (-206) Unrecognized or unsupported array type in function cvGetMat

Backtrace after debugging is as follows:

(gdb) bt
#0  0xb7fdd424 in __kernel_vsyscall ()
#1  0xb77741ef in __GI_raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0xb7777835 in __GI_abort () at abort.c:91
#3  0xb79e313d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#4  0xb79e0ed3 in ?? () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#5  0xb79e0f0f in std::terminate() () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#6  0xb79e105e in __cxa_throw () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#7  0xb7eb9363 in cv::error(cv::Exception const&) () from /usr/local/lib/libopencv_core.so.2.4
#8  0xb7e40496 in cvGetMat () from /usr/local/lib/libopencv_core.so.2.4
#9  0xb7ceb915 in cvImageWidgetSetImage(_CvImageWidget*, void const*) () from /usr/local/lib/libopencv_highgui.so.2.4
#10 0xb7ced4e0 in cvShowImage () from /usr/local/lib/libopencv_highgui.so.2.4
#11 0xb7cea378 in cv::imshow(std::string const&, cv::_InputArray const&) () from /usr/local/lib/libopencv_highgui.so.2.4
#12 0x0804a1ca in main (argc=2, argv=0xbffff724) at lkdemo-1.cpp:141
(gdb) 

Please anyone help me to fix this.

ArtemStorozhuk
  • 8,542
  • 4
  • 30
  • 52
  • You might be interested in taking a look at [this code](http://stackoverflow.com/questions/7838487/executing-cvwarpperspective-for-a-fake-deskewing-on-a-set-of-cvpoint). – karlphillip Jun 29 '12 at 14:56
  • Hi @karlphillip. By gdb, I guess i found what is the problem. Actually the problem is with H = getPerspectiveTransform(points[0], points[1]); and actually getPerspectiveTransform is expecting "Point2f" (double) and I had points as vector points[2]; (may be int) required by calcOpticalFlowPyrLK. So when getPerspectiveTransform is hit then getting this error: OpenCV Error: Assertion failed (src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4) in getPerspectiveTransform – Still Learning Boy Jun 30 '12 at 05:19
  • @Astor - can you please tell me how to get a floating-point array from **vector points[2];** . I believe that _getPerspectiveTransform_ is getting error due to this problem only. Thanks. – Still Learning Boy Jun 30 '12 at 06:10

1 Answers1

1

Actually I am getting above mentioned error due to mismatch in the number of points required for the getPerspectiveTransform method. Error was: error: OpenCV Error: Assertion failed (src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4) in getPerspectiveTransform

Actually it requires four points for the transformation and I am using all points. Here is the correct way of calling getPerspectiveTransform with lk optical flow, in case you need.

    std::vector<Point2f> img1_corners(4);

    img1_corners[0] = cvPoint(0,0); 
    img1_corners[1] = cvPoint( gray.cols, 0 );
    img1_corners[2] = cvPoint( gray.cols, gray.rows ); 
    img1_corners[3] = cvPoint( 0, gray.rows );

    std::vector<Point2f> img2_corners(4);

    vector<uchar> status;
    vector<float> err;
    calcOpticalFlowPyrLK(gray, gray1, img1_corners, img2_corners, status, err, winSize,
            3, termcrit, 0, 0.001);
    //calcOpticalFlowPyrLK(gray, gray1, corner1, corner2, status, err, winSize,
    //      3, termcrit, 0, 0.001);


    Mat H = getPerspectiveTransform(img1_corners, img2_corners);
    //Mat H = getPerspectiveTransform(corner1, corner2);