Ask Your Question

Revision history [back]

OpenCV v.4.0 not receiving frames and throwing -215: Assertion Error. !_src.empty() in function 'cvtColor'

We are trying to use an Intel Realsense D435 with OpenCv v4.0 on a Linux Ubuntu 18.04 x64 os. We are able to open the camera. But we are not able to capture/receive frame. We are able to use the camera on two other computers with the same exact code and it runs just fine, so we know the camera works properly and there is not an issue with the code itself as far as syntax and function usage. Does anyone know of a way to get this code to run properly on this setup? Any help/ suggestions are greatly appreciated. The code follows:

#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(;;)
    {
        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;
}