【问题标题】:Yellow detection program assertion failed黄色检测程序断言失败
【发布时间】:2014-06-20 18:40:05
【问题描述】:

我创建了一个程序来使用 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

【问题讨论】:

    标签: c++ linux opencv arm


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复。我将 LYellow 和 RYellow 的声明更改为 Mat LYellow(240,320, CV_8UC1),但仍然出现相同的错误
    • 你能调试你的代码吗,inrange 现在应该没有问题了。事实上,它看起来像一个捕获/highgui 问题。你也可以复制堆栈输出吗?你安装了其他的opencv版本吗?
    • 抱歉,堆栈输出是什么?我没有安装任何其他 opencv 版本。如果我评论 inRange() 和轮廓,程序运行并且输出将是带有腐蚀和扩张的 hsv 输出。
    • 堆栈跟踪,抛出异常时调用底层方法
    • 是这个吗? getMat. 中的断言失败 (k==STD_VECTOR_MAT),文件 /build/buildd-opencv_2.3.1-11-armhf-d9JIli/opencv-2.3.1/modules/core/src/matrix.cpp,第 918 行
    猜你喜欢
    • 1970-01-01
    • 2018-01-29
    • 2019-09-25
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 2011-05-27
    • 2017-04-10
    相关资源
    最近更新 更多