MJPEG stream fails to open in OpenCV 2.4 - c++

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.

Try adding a dummy param, that hints at the mjpeg content:
const string videoStreamAddress = "http://192.168.0.28:8080/?action=stream&type=mjpg";

I found the answer, it is similar to what Hitesh suggested, I just needed to have a . before mjpg to make OpenCV think it was a URI to a file.
I found this in this answer to a similar question.

Related

Can open some avi files in open cv but others fail to open

Im working on a project which needs to read avi and mp4 files,,i downloaded a project form git https://github.com/andrewssobral/simple_vehicle_counting
CvCapture *capture = 0;
capture = cvCaptureFromFile("v6_(new)/video.avi");
//capture = cvCaptureFromCAM(0);
if(!capture){
std::cerr << "Cannot open video!" << std::endl;
return -1;
}
ive notices that only some videos ,i got 10 sample videos out of which i can read only 2 all others return NULL
Any one have idea whats happening,im using openCv 2.4.1 and VS13
UPDATE:i can open a webcam and stream video without any problems
Thank you

Opencv VideoCapture, not opening some video files

I'm trying to use the opencv librarie to display video files to the screen using sdl-2. I got it to work with smaller files(20.5Mb), but when i tryed using bigger files (100 and 136Mb) it didnt work and i go the message "ERROR: Coudnt load the video < video.avi>".
cv::VideoCapture video;
video.open(videoName);
if (!video.isOpened())
{
SDL_Log("ERROR: Coudnt load the video <%s>", videoName.c_str());
return;
}
I don't know if size was the problem, but that would make the most sense to me. I've not found any documentation on size restrictions thought. Any ideas on how to fix it?
PS: All were .avi files, and the file's name was not the problem. Was able to open them with ffplay if that matters at all. OpenCV version 2.4.8

OpenCV2 codec support

I am reading in video files with openCV, I use the following simple code to do this.
std::string arg = argv[1];
VideoCapture capture(arg); //try to open string, this will attempt to open it as a video file
if (!capture.isOpened()) {
cerr << "Failed to open video file!\n" << endl;
help(argv);
system("Pause");
return 1;
}
I can load and manipulate several videos, but I have problems with others. I imagine this is down to codec issues. I can play the videos using old style win media player, so the codecs are on the system, but I imagine not available in opencv?
Does anyone know what codecs and video format will definitely play on opencv and what is a good option to convert video to these formats?
Many Thanks
Indeed, the supported codec of OpenCV is dependent on your platform and avaible codecs.
This tutorial Creating a video with OpenCV explains the video codec of OpenCV clearly. Though it is meant for writing videos, I think the underlying principle is the same with reading videos.
The function C++: double VideoCapture::get(int propId) can retrieve your loaded video's codec property by setting propId = CV_CAP_PROP_FOURCC. The interpretation of FOURCC can be found on this site. If you have problems with reading .avi videos, it is very likely that the codes is not installed in your platform.

Unable to get Video feed from D-Link DCS 932L using openCv

I am trying to display video feed from IP- Camera(D-Link DCS 932L). I Have gone through topics for the same and tried the code from different posts, but am unable to get the video feed from the camera.
Here's the code which i tried.
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
int main(int argc, char *argv[])
{
Mat frame;
namedWindow("video", 1);
String url = "http://admin:admin#172.32.20.55:80/image/jpeg.cgi";
VideoCapture cap(url);
/* VideoCapture cap(0);*/
while ( cap.isOpened() )
{
cap >> frame;
if(frame.empty()) break;
imshow("video", frame);
if(waitKey(30) >= 0) break;
}
return 0;
}
I tried many different kind of url's but i was unable to display any video feed. I thought it might be code problem so I even tried displaying the USB Webcam and it worked. So now i come to conclusion that the problem seems to be with URL which am passing. Heres the list of urls which I tried. I got this Url options from iSpy.Here are those URL's
(JPEG)http://admin:admin#172.32.20.55:80?IMAGE.JPG
(JPEG)http://admin:admin#172.32.20.55:80/image/jpeg.cgi
(MPEG)http://admin:admin172.32.20.55:80/video.cgi?resolution=VGA
(MPEG)http://admin:admin172.32.20.55:80/video/mjpg.cgi
(MPEG)http://admin:admin172.32.20.55:80/mjpeg.cgi? user=admin&password=admin&channel=0
(MPEG)http://admin:pnqadmin172.32.20.55:80/VIDEO.CGI
Please let me know what can be probable problem for displaying the video feed.
Is their something to do with the setting of the OpenCv or something else.Please note that am using VS2010 and C++ Need help of all the Expert out their.
Thanks in advance.
I solved my problem. The problem was with URL. I changed the URL and it worked smooth..!
The URL i used was as follows.
"http://USER:PWD#IPADDRESS:8088/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg";
I keep getting the same error:
warning: Error opening file <../../modules/highgui/src/cap_ffmpeg_impl.hpp:529>
I was trying to stream MJPG video from a Foscam IP camera. The URL opened just fine but I couldn't read any frames. May be there was some problem with the video codec.
Here's a hack written in Python that worked for me: https://stackoverflow.com/a/18411168/3183051
Perhaps my answer is too late. Check if opencv_ffmpegXXX.dll or opencv_ffmpegXXX_64.dll (if you are building 64bit executable) is in the same folder where your executable is. Replace XXX with the number of opencv version you use.

OpenCV displaying avi file encoded in I420

I am trying to write a video processing application using OpenCV 2.4.2 (in Visual C++ 2010 Express on Windows 7) but I am having trouble displaying certain AVI files. Most display correctly, but when I use an AVI file encoded in I420 format all I get is a striped pink image for every frame (it displays correctly in regular media players).
Output displayed: http://i.imgur.com/BOu6c.png?1
Currently, I am using the C++ API, but the same thing happens when I use the C API (code from this page: http://nashruddin.com/how_to_play_avi_files_with_opencv). I find this strange, because in most answers on this site and resources on the web, they explicitly recommend to use the I420 encoding. Does anyone know what could be causing this or how to fix it?
Here is a trimmed down version of the code I am using:
int main(int argc, char** argv){
string fname = "test.avi";
VideoCapture capture(fname);
if(!capture.isOpened()){
cerr << "error opening " << fname << endl;
return -1;
}
Mat frame;
namedWindow("output");
double rate = capture.get(CV_CAP_PROP_FPS);
int delay = 1000/rate;
while(true){
if(!capture.read(frame)) break;
cv::imshow("output", frame);
if(waitKey(delay) >= 0) break;
}
capture.release();
return 0;
}
I am using is the pre-compiled version of OpenCV if that makes a difference (http://sourceforge.net/projects/opencvlibrary/).
Ok, so I managed to test on a few more computers. One just crashed and, on another, the video played fine. It turns out that it was a problem with FFMPEG being enabled in the default OpenCV compilation having problems with the uncompressed AVI. Recompile OpenCV with FFMPEG disabled or just use a different codec to compress the video.