I am having an issue getting OpenCV 2.4 to capture from an MJPEG stream from a Raspberry Pi, I have checked the stream URL in a browser and it seems to be working fine, however when I try to open it in OpenCV it seems to hang when I attempt to open it (I get neither the error or success messages on the terminal).
cv::VideoCapture vcap;
cv::Mat raw_image;
const string videoStreamAddress = "http://192.168.0.28:8080/?action=stream";
if(!vcap.open(videoStreamAddress))
{
cout<<"Error opening video stream"<<endl;
return -1;
}
cout<<"Stream opened"<<endl;
I am using MJPEG-Streamer to provide the stream. The same code works fine when capturing form a RTSP video stream.
EDIT: I tried changing the JPEG quality and resolution of the images captured by raspistill
on the Pi and I now get the message saying the stream failed to open.
I found the answer, it is similar to what Hitesh suggested, I just needed to have a
.
beforemjpg
to make OpenCV think it was a URI to a file.I found this in this answer to a similar question.
Try adding a dummy param, that hints at the mjpeg content: