dip*_*mac 1 c c++ opencv visual-c++
我正在尝试使用开放式CV FAST算法来检测视频输入中的角点.方法调用和设置似乎很简单,但我遇到了一些问题.当我尝试使用此代码时
while(run)
{
clock_t begin,end;
img = cvQueryFrame(capture);
key = cvWaitKey(10);
cvShowImage("stream",img);
//Cv::FAST variables
int threshold=9;
vector<KeyPoint> keypoints;
if(key=='a'){
//begin = clock();
Mat mat(tempImg);
FAST(mat,keypoints,threshold,true);
//end = clock();
//cout << "\n TIME FOR CALCULATION: " << double(diffClock(begin,end)) << "\n" ;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
OpenCV错误:断言失败(image.data && image.type()== CV_8U)未知函数,文件........\ocv\opencv\src\cvaux\cvfast.cpp,第6039行
所以我认为它的图像深度有问题所以当我添加这个时:
IplImage* tempImg = cvCreateImage(Size(img->width,img->height),8,1);
cvCvtColor(img,tempImg,CV_8U);
Run Code Online (Sandbox Code Playgroud)
我明白了:
OpenCV错误:未知函数中的通道数量不正确(此转换代码的通道数不正确),文件........\ocv\opencv\src\cv\cvcolor.cpp,第2238行
我已经尝试使用Mat而不是IplImage捕获但我一直遇到同样的错误.
有什么建议或帮助吗?提前致谢.
整个文件只是为了让任何人都更容易:
#include "cv.h"
#include "cvaux.hpp"
#include "highgui.h"
#include <time.h>
#include <iostream>
double diffClock(clock_t begin, clock_t end);
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
//Create Mat img for camera capture
IplImage* img;
bool run = true;
CvCapture* capture= 0;
capture = cvCaptureFromCAM(-1);
int key =0;
cvNamedWindow("stream", 1);
while(run)
{
clock_t begin,end;
img = cvQueryFrame(capture);
key = cvWaitKey(10);
cvShowImage("stream",img);
//Cv::FAST variables
int threshold=9;
vector<KeyPoint> keypoints;
if(key=='a'){
//begin = clock();
IplImage* tempImg = cvCreateImage(Size(img->width,img->height),8,1);
cvCvtColor(img,tempImg,CV_8U);
Mat mat(img);
FAST(mat,keypoints,threshold,true);
//end = clock();
//cout << "\n TIME FOR CALCULATION: " << double(diffClock(begin,end)) << "\n" ;
}
else if(key=='x'){
run= false;
}
}
cvDestroyWindow( "stream" );
return 0;
Run Code Online (Sandbox Code Playgroud)
}
每当您使用OpenCV API时遇到问题,请查看源代码中提供的测试/示例:fast.cpp
这种做法非常有用和有教育意义.现在,如果您查看该代码,您会注意到图像在调用之前会转换为灰度cv::FAST():
Mat mat(tempImg);
Mat gray;
cvtColor(mat, gray, CV_BGR2GRAY);
FAST(gray,keypoints,threshold,true);
Run Code Online (Sandbox Code Playgroud)
事实上看起来非常直截了当.