c++ - 黄色检测程序断言失败

标签 c++ linux opencv arm

我使用 C++ 和 opencv 创建了一个程序来检测和跟踪黄色。 这个程序在我的 windows 和 ubuntu 操作系统的 PC 上运行正常,但是这个程序不能在我的 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() 上,但我不知道它出了什么问题,因为这个程序在我的 PC 上运行。

我正在使用 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

最佳答案

inRange() 返回灰度输出。即像素是否在范围内。您应该将 Lyellow 和 Ryellow 声明为 1 channel Mat 结构,例如 CV_8UC1。

关于c++ - 黄色检测程序断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23455921/

相关文章:

python - C程序字符缓冲区意外溢出

c++ - 如何切换到 OpenCV 3.0 的静态库以便 exe 是独立的?

python - 如何将 numpy.zeros 数组可视化为 RGB 图像?

c++ - using 声明的可变参数扩展

c++ - 变量大小取决于语言机器实现是什么意思?

c++ - 编译器省略外循环

c++ - 什么是最接近 Pex for Visual C++ 的东西?

linux - 扩展 iptables 内核模块

linux - LXD 容器内的 DNS 解析不起作用

c++ - std::vector 元素被覆盖