I have read many, many threads about streaming images over IP in OpenCV 2.3.1, but I still cannot get my program to work.
I downloaded IP Webcam for Android from https://market.android.com/details?id=com.pas.webcam&hl=en, and recently learned OpenCV to retrieve images from my Android phone camera.
Its built-in manual said that the image from the phone camera can be located at http://the.phone.ip.address:8080/shot.jpg. I have opened it from browser several times and it always looks fine. I also built OpenCV manually, with FFmpeg support.
So far I've tried
CvCapture* webcam = cvCaptureFromFile("http://192.168.1.220:8080/shot.jpg");
but it returns NULL and outputs
[image2 @ 0xd701e0]Could not find codec parameters (Video: mjpeg, yuv420p)
I also tried replacing http with rtsp, but it still doesn't work. I also tried to replace the url with some other image url (one direct link to random image from Google Images, and one from localhost) and it always kills with a segfault.
Here's my full source
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
CvCapture* webcam = cvCaptureFromFile("http://192.168.1.220:8080/shot.jpg");
if(!webcam)
{
fprintf(stderr, "cannot open webcam\n");
return 1;
}
IplImage* img = cvQueryFrame(webcam);
if(!img)
{
fprintf(stderr, "cannot get image\n");
return 1;
}
cvNamedWindow("test", CV_WINDOW_AUTOSIZE);
cvShowImage("test", img);
cvWaitKey(0);
cvReleaseImage(&img);
/**/ cvReleaseCapture(&webcam); /**/
cvDestroyWindow("test");
return 0;
}
Can OpenCV really read images over IP, or am I missing something?
I'm not specifically familiar with openCV, but having spent a minute looking at the docs, two things jump out at me:-
First off, your're not dealing with a true video stream here: your android app just makes the current JPEG capture available and you have to continually re-sample it. Because it's an Image, not a Video, you should use cvLoadImage()
instead.
Second, you're passing a URL, not a filename. You'll need a way to use HTTP to fetch the image to a local file before you try opening it with openCV.
I'd suggest you save a snapshot of the JPEG file locally from your browser, and then try getting your code working with that. Once you have it working from a local file, try adding the HTTP fetching stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With