streaming mjpg video to opencv: from android IP Webcam to cygwin64+ffmpeg+opencv
Hello,
I am trying to process a MJPG stream from Android phone streaming with IP Webcam to Windows 7 Cygwin+ffmpeg+openv built following (http://hvrl.ics.keio.ac.jp/kimura/opencv/).
Please note from same PC both the following work: 1) VLC open network stream: http://192.168.0.241:8080/video?x.mjpg --> I see my video 2) ffmpeg -i http://192.168.0.241:8080/video?x.mjpg tmp.avi --> codes video to tmp.avi
Using opencv, I can compile with
g++ -o ipwebcam.exe ipwebcam.cpp `pkg-config --cflags --libs opencv`
and run below code but when I run it I get:
$ ./ipwebcam
[tcp @ 0x60001aba0] Failed to resolve hostname 192.168.0.241: Unknown error
Cannot open the video cam
Note that if I use cap.open("tmp.avi") it works. This seems to indicate ffmpeg somehow works!?!?
Browsing code, it seems issue is with libavformat in ffmpeg but I cannot fix it.
Can anybody help and indicate how to solve? I cannot believe that it is not possible to open a network stream with opencv and cygwin... :(
Cheers, AaWnSD
quote ipwecam.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
VideoCapture cap; //
cap.open("http://192.168.0.241:8080/video?x.mjpg");
if (!cap.isOpened()) // if not success, exit program
{
cout << "Cannot open the video cam" << endl;
return -1;
}
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Frame size : " << dWidth << " x " << dHeight << endl;
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
namedWindow("MyNegativeVideo",CV_WINDOW_AUTOSIZE);
while (1)
{
Mat frame;
Mat contours;
bool bSuccess = cap.read(frame); // read a new frame from video
if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}
flip(frame, frame, 1);
imshow("MyVideo", frame); //show the frame in "MyVideo" window
Canny(frame, contours, 500, 1000, 5, true);
imshow("MyNegativeVideo", contours);
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break;
}
}
return 0;
}
/quote
192.168.0.241 will only work in a local network
try to find the 'outer' ip, e.g. by visiting http://ip-lookup.net/ from your phone
Hi, I am on a local network. PC and Android phone are both connected to WiFi router same subnet with IPs 192.168.0.2, 192.168.0.241 respectively and netmask 255.255.255.0. There is routing between the two. It seens issue is with "wrong" attempt to execute getaddinfo in tcp.c libavformat... might be I am wrong though...
Looking at your remark
Browsing code, it seems issue is with libavformat in ffmpeg but I cannot fix it.
it seems to me you should address this to their forum? I do not think this is an OpenCV issue, rather a ffmpeg interface problem.