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?