今天早上我遇到了以下错误消息,不知道如何解决。
terminate called after throwing an instance of 'cv::Exception' what():
OpenCV(3.4.3) /home/design/opencv/modules/imgproc/src/color.cpp:181
error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
我正在使用Linux ubuntu版本18.04,并使用OpenCV库在C ++中进行编程。我正在尝试将Intel RealSense depth camera集成到我将在下面上传的代码中。根据我的理解,问题来自cvtColor(frame, edges, COLOR_BGR2GRAY);
行,也就是说Frame
是空的。
我试图解决的问题:
在这一点上,我不知道为什么它可以在其他两台计算机上正常工作,而不是在第三台计算机(我们实际上需要使用的那台)上正常工作。我目前不知道还能尝试什么。如果有人对如何解决此问题有任何了解,我将不胜感激。
我的代码:
#include "opencv2/opencv.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>
using namespace cv;
using namespace std;
Mat dst; //Black background image that we copy the source image ontop of.
Mat img; //source image
Mat cdst; //Standardized hough transformation image with Red lines
Mat cdstP;//Probalistic hough transformation image with Red lines
int main(int, char**)
{
VideoCapture cap(2); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",2);
for(;;)
{
cap >> frame;
if(frame.empty())
{
printf("frame grab unsuccessful\n");
}
if(!frame.empty())
{
printf("frame grab successful\n");
}
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);//output array gray is copy of frame in a gray gradient scale
}
return 0;
}
输出:
frame grab successful
frame grab successful
select timeout
frame grab unsuccessful
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.0.0-pre) /home/design/opencv/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'