"断言失败(m.dims> = 2)在Mat" Raspberry Pi OpenCV

时间:2015-12-22 19:53:36

标签: c++ opencv image-processing raspberry-pi threshold

我下载了一个允许通过OpenCV从Pi相机模块获取帧的项目。当我尝试运行下载的代码时,它没有问题。我只想在帧上应用简单的trheshold操作,但是我得到了如下所示的错误。

我检查框架'类型和渠道。 image.channels()返回1而image.type()返回0.我无法查看阈值操作错误的任何原因。

这是什么问题?

错误:

enter image description here

守则:

 #include "cap.h"
 #include <opencv2/opencv.hpp>
 #include <opencv2/highgui/highgui.hpp>

 using namespace cv;
 using namespace std;

 int main() {
 namedWindow("Video");

// Create capture object, similar to VideoCapture
// PiCapture(width, height, color_flag);
// color_flag = true  => color images are captured,
// color_flag = false => greyscale images are captured
PiCapture cap(320, 240, false);

Mat image,binary;
double time = 0;
unsigned int frames = 0;


cout << "Press 'q' to quit" << endl;
while(char(waitKey(1)) != 'q') {
    double t0 = getTickCount();
    image = cap.grab();

std::cout<<image.channels()<< endl;//check for channel
cout<<image.type()<< endl;//check for type
threshold(image,binary,150,255,THRESH_BINARY);//threshold operation

frames++;
    if(!image.empty()) imshow("Hello", image);
    else cout << "Frame dropped" << endl;

    time += (getTickCount() - t0) / getTickFrequency();
    cout << frames / time << " fps" << endl;
}

return 0;
}

1 个答案:

答案 0 :(得分:-1)

断言m.ndims&gt; = 2是检查所讨论的矩阵是否是有效的二维图像。虽然您有条件仅在图像不为空时显示图像。但是在程序达到条件之前,断言必定是失败的。因此,您不应该看到任何图像窗口弹出。