0

嗨,我试图修改lkdemo.cppin OpenCV/sample/cpp。我想得到透视变换,然后warpPerspective。所以我添加了第 (1) 和 (2) 行来做到这一点。其中图像和输出的声明如下:

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));

...

现在,当我尝试使用imshow()我看到扭曲图像的输出时,我收到了这个错误:

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

调试后的回溯如下:

(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) 

请任何人帮我解决这个问题。

4

1 回答 1

1

实际上,由于 getPerspectiveTransform 方法所需的点数不匹配,我遇到了上述错误。错误是: 错误:OpenCV 错误:断言失败 (src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4) in getPerspectiveTransform

实际上,转换需要四个点,我正在使用所有点。如果需要,这是使用 lk 光流调用 getPerspectiveTransform 的正确方法。

    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);
于 2012-07-06T05:15:44.477 回答