我使用c ++和opencv创建了一个检测和跟踪黄色的程序。 这个程序通常在我的电脑上运行Windows和ubuntu操作系统,但是这个程序无法在我的debian arm miniPC中运行。
我收到错误: opencv错误:getMat中的断言失败(k == STD_VECTOR_MAT)。文件/build/buildd-opencv_2.3.1-11-armhf-d9JIli/opencv-2.3.1/modules/ core / src / matrix.cpp,第918行
我试着评论下面的代码,我发现其中一个问题是函数inRange(),但我不知道它有什么问题,因为这个程序可以在我的电脑上运行。
我正在使用qtcreator 2.5.0 qt 4.8.2和opencv 2.3.1-11
#include <vector>
using namespace std;
using namespace cv;
//VARIABLE LIST///////////////////////////////////////
int cap_x_size=320;
int cap_y_size=240;
int posx,posy;
//matrix1
bool betulyellow1;
string yellow1="yellow";
string yellowind = "yellow";
int yellow1posx, yellow1posy;
//matrix2
bool betulyellow2;
string yellow2="yellow";
int yellow2posx, yellow2posy;
vector<vector<Point> > leftcontur;
vector<vector<Point> > rightcontur;
vector<vector<Point> >::const_iterator itc;
Moments momon;
double momon01,momon10,momonrea;
/////////////////////////////////////////////////////
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
Mat left(240, 320, CV_8UC3);
Mat right(240, 320, CV_8UC3);
Mat lefthsv(240, 320, CV_8UC3),righthsv(240, 320, CV_8UC3);
Mat LYellow(240, 320, CV_8UC3),RYellow(240, 320, CV_8UC3);
VideoCapture cap;
VideoCapture cap2;
cap.open(0);
cap.set(CV_CAP_PROP_FRAME_WIDTH, cap_x_size);
cap.set(CV_CAP_PROP_FRAME_HEIGHT, cap_y_size);
cap2.open(1);
cap2.set(CV_CAP_PROP_FRAME_WIDTH, cap_x_size);
cap2.set(CV_CAP_PROP_FRAME_HEIGHT, cap_y_size);
while(1)
{
cap>>left;
cap2>>right;
////////////////////////////////////////////
////////////////////////////////////////////
cvtColor(left,lefthsv,CV_BGR2HSV);
cvtColor(right,righthsv,CV_BGR2HSV);
inRange(lefthsv,Scalar(22,100,100), Scalar(38,255,255),LYellow);
inRange(righthsv,Scalar(22,100,100), Scalar(38,255,255),RYellow);
Mat erodeElement = getStructuringElement( MORPH_RECT,Size(3,3));
Mat dilateElement = getStructuringElement( MORPH_RECT,Size(8,8));
//left
erode(LYellow,LYellow,erodeElement);
dilate(LYellow,LYellow,dilateElement);
//right
erode(RYellow,RYellow,erodeElement);
dilate(RYellow,RYellow,dilateElement);
//left
findContours(LYellow,leftcontur,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
drawContours(LYellow,leftcontur,-1,Scalar(255),1);
//right
findContours(RYellow,rightcontur,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
drawContours(RYellow,rightcontur,-1,Scalar(255),1);
//left
for(itc = leftcontur.begin(); itc<leftcontur.end(); itc++)
{
momon = moments(Mat(*itc));
momon10 = momon.m10;
momon01 = momon.m01;
momonrea= momon.m00; // momonrea is area
posx = momon10/momonrea;
posy = momon01/momonrea;
circle(left,Point(posx,posy),2, Scalar(0,255,255),2);
putText(left,yellow1,Point(posx,posy-20),1,1,Scalar(0,255,0));
putText(left,intToString(posx)+ " , " + intToString(posy),Point(posx,posy+20),1,1,Scalar(0,255,0));
if(yellow1 == yellowind)
{
betulyellow1 = true;
}
else
{
betulyellow1 = false;
}
}
if(betulyellow1)
{
yellow1posx=posx;
yellow1posy=posy;
betulyellow1=false;
}
else
{
yellow1posx=0;
yellow1posy=0;
}
//right
for(itc = rightcontur.begin(); itc<rightcontur.end(); itc++) //brapa objek yang uda di konturin
{
momon = moments(Mat(*itc));
momon10 = momon.m10;
momon01 = momon.m01;
momonrea= momon.m00; // momonrea is area
posx = momon10/momonrea;
posy = momon01/momonrea;
circle(right,Point(posx,posy),2, Scalar(0,255,255),2);
putText(right,yellow1,Point(posx,posy-20),1,1,Scalar(0,255,0));
putText(right,intToString(posx)+ " , " + intToString(posy),Point(posx,posy+20),1,1,Scalar(0,255,0));
if(yellow2 == yellowind)
{
betulyellow2 = true;
}
else
{
betulyellow2 = false;
}
}
if(betulyellow2)
{
yellow2posx=posx;
yellow2posy=posy;
betulyellow2=false;
}
else
{
yellow2posx=0;
yellow2posy=0;
}
/////////////////////////////////////////////
/////////////////////////////////////////////
imshow("left",LYellow);
imshow("right",RYellow);
imshow("left ori",left);
imshow("right ori",right);
if(waitKey(10)==27)//press esc to exit
{
destroyAllWindows();
break;
}
}
return a.exec();
}
我该如何解决这个问题?
感谢您的帮助
编辑:堆叠结果:
level Function File Line
0 ?? /lib/arm-linux-gnueabihf/libc.so.6 0
1 raise /lib/arm-linux-gnueabihf/libc.so.6 0
2 abort /lib/arm-linux-gnueabihf/libc.so.6 0
3 __gnu_cxx::_... /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 0
4 ?? /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 0
5 ?? /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 0
答案 0 :(得分:0)
inRange()返回灰度输出。即,是否在范围内的像素。你应该将Lyellow和Ryellow声明为1通道Mat结构,如CV_8UC1。