简体   繁体   English

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

[英]"assertion failed (m.dims>=2) in Mat" Raspberry Pi OpenCV

I downloaded a project which allows to get frames from Pi camera module with OpenCV.我下载了一个项目,该项目允许使用 OpenCV 从 Pi 相机模块获取帧。 When I try to run the downloaded code, It works without a problem.当我尝试运行下载的代码时,它可以正常工作。 I just want to apply simple trheshold operation on frames but I got the error shown below.我只想对帧应用简单的阈值操作,但出现如下所示的错误。

I check the frames' type and channel.我检查帧的类型和频道。 image.channels() returns 1 and image.type() returns 0. I can't see any reason for the threshold operation error. image.channels()返回 1 和image.type()返回 0。我看不到阈值操作错误的任何原因。

What is the problem here?这里有什么问题?

The error:错误:

在此处输入图片说明

The Code:编码:

 #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;
}

Assertion m.ndims >= 2 is to check that the matrix in question is a valid two dimensional image.断言 m.ndims >= 2 是检查所讨论的矩阵是否是有效的二维图像。 While you have a conditional to show the image only if it's not empty.虽然您有条件仅在图像不为空时才显示图像。 But the assertion must be failing before the program reaches that conditional.但是断言必须在程序达到该条件之前失败。 So you shouldn't be seeing any image window pop up.所以你不应该看到任何图像窗口弹出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM