首页 > 解决方案 > OpenCV CV findHomography 断言错误计数器 = > 4

问题描述

我正在使用 Features2D + findHomography 编译和运行代码来查找已知对象教程,并且我得到了这个错误计数器 = > 4 ;我更改了我的代码并在任何地方使用显式命名空间说明符,但问题没有解决。如果可以的话,请帮我解决这个问题,或者说哪个函数与 findHomography 做同样的事情,并且不要让程序崩溃。这是我的代码#include "opencv2/opencv.hpp" using namespace cv;

int main()
{
    vector<Point2f> t1;
    vector<Point2f> t2;
    vector<Point2f> t3;
    t3.push_back(Point2f(282, 304));
    t1.push_back ( Point2f(249,456));
    t1.push_back ( Point2f(264, 330));
    t1.push_back ( Point2f(301, 329));
    t1.push_back ( Point2f(308, 327));
    t1.push_back ( Point2f(293, 249));
    t1.push_back ( Point2f(322, 245));
    t1.push_back ( Point2f(321, 225));
    t1.push_back ( Point2f(266, 228));
    t2.push_back ( Point2f(0, 0));
    t2.push_back ( Point2f(15, 994));
    t2.push_back ( Point2f(105, 994));
    t2.push_back ( Point2f(120, 1009));
    t2.push_back ( Point2f(90, 2016));
    t2.push_back ( Point2f(180, 2031));
    t2.push_back ( Point2f(180, 2432));
    t2.push_back ( Point2f(0, 2432)); 
     //-- Get the corners from t1 t2
        vector<Point2f>pt4;
    if (t1.size() >=4 && t2.size()>=4 )
   {  
        Mat h =findHomography(t1, t2, CV_RANSAC, 5);
           //-- this may create a mistake;
    perspectiveTransform(t3, pt4, h);
    for (int m = 0; m < pt4.size(); m++)
    cout << pt4[m]<<endl;
 }

它可以在调试模式下成功运行,但不能在发布模式下运行。有什么问题谢谢。

标签: c++opencv

解决方案


这样配置,可能会出现debug可以运行但release下不能运行的情况(比如没有图片加载,内存错误),这是OpenCV从2.4.1开始的一个bug。如果出现这种情况,打开当前工程(注意是当前工程的属性页,不是通用属性页),debug或者release有问题,在“当前”工程属性中添加对应的带或不带D的lib-> [链接器] - > [附加依赖项]


推荐阅读