繁体   English   中英

OpenCV Harris Corner Detection崩溃

[英]OpenCV Harris Corner Detection crashes

我正在尝试使用OpenCV的Harris Corner检测算法来查找图像中的角点。 我想使用Lucas-Kanade金字塔光流在连续帧中跟踪它。 我有这个C ++代码,由于某种原因似乎不起作用:

#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

void main()

{
    Mat img1, img2;
    Mat disp1, disp2;
int thresh = 200;

vector<Point2f> left_corners;
vector<Point2f> right_corners;
vector<unsigned char> status;
vector<float> error;

Size s;
s.height = 400;
s.width = 400;

img1 = imread("D:\\img_l.jpg",0);
img2 = imread("D:\\img_r.jpg",0);

resize(img2, img2, s, 0, 0, INTER_CUBIC);   
resize(img1, img1, s, 0, 0, INTER_CUBIC);


disp1 = Mat::zeros( img1.size(), CV_32FC1 );
disp2 = Mat::zeros( img2.size(), CV_32FC1 );

int blockSize = 2;
int apertureSize = 3;
double k = 0.04;

 cornerHarris( img1, disp1, blockSize, apertureSize, k, BORDER_DEFAULT );
  normalize( disp1, disp1, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );

  for( int j = 0; j < disp1.size().height ; j++ )
     { 
         for( int i = 0; i < disp1.size().width; i++ )
          {
            if( (int) disp1.at<float>(j,i) > thresh )
              { 
                left_corners.push_back(Point2f( j, i )); 
              }
          }
     }

  right_corners.resize(left_corners.size());

  calcOpticalFlowPyrLK(img1,img2,left_corners,right_corners,status,error, Size(11,11),5);     
  printf("Vector size : %d",left_corners.size());


  waitKey(0);
}

当我运行它时,我收到以下错误消息:

Microsoft Visual Studio C运行时库已在OpenCVTest.exe中检测到致命错误。 (OpenCVTest是我项目的名称)

OpenCV Error: Assertion failed ((npoints = prevPtsMat.checkVector(2, CV_32F, true)) >= 0) in unknown function, file ..\..\OpenCV-2.3.0-win-src\OpenCV-2.3.0\modules\video\src\lkpyramid.cpp, line 71

我一直试图从昨天开始调试,但是徒劳无功。 请帮忙。

正如我们在源代码中看到的,如果先前的点数组在某种程度上有问题,则抛出此错误。 究竟是什么让它变得很难很难说,因为checkVector的文档有点粗略。 您仍然可以查看代码以查找。 但我的猜测是你的left_corners变量有错误的类型(不是CV_32F)或错误的形状。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM