C, opencv - access JPG camera image via ip

I read many, many threads about streaming images over IP in OpenCV 2.3.1 , but I still can't get my program to work.

I downloaded the IP camera for Android from https://market.android.com/details?id=com.pas.webcam&hl=en and recently taught OpenCV how to receive images from my Android phone camera.

His built-in manual states that the image from the phone’s camera can be found at http://the.phone.ip.address: 8080 / shot.jpg . I opened it several times from the browser, and it always looks good. I also created OpenCV manually, with support for FFmpeg .

So far i tried

CvCapture* webcam = cvCaptureFromFile("http://192.168.1.220:8080/shot.jpg"); 

but returns null and outputs

 [image2 @ 0xd701e0]Could not find codec parameters (Video: mjpeg, yuv420p) 

I also tried replacing http with rtsp, but it still does not work. I also tried replacing the url with a different image URL (one direct link to a random image from Google Images and the other from localhost), and it always kills with segfault.

Here is my complete 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 by IP address, or am I missing something?

+6
source share
3 answers

I am not familiar with openCV, but after spending a minute on the documents, two things jump at me: -

First, your case about the true video stream is here: your Android app just makes the current JPEG capture available, and you have to keep repeating it. Since this is an image, not a video, you should use cvLoadImage() .

Secondly, you pass the URL, not the file name. You will need to use HTTP to get the image in the local file before trying to open it using openCV.

I suggest you save a snapshot of the JPEG file locally from your browser, and then try to get your code to work with this. After you work with the local file, try adding material to extract HTTP.

+4
source

As long as it would be / awesome / if it was confirmed, it doesn't seem to be so. Note that OSs handle open files differently from URLs (obviously), so this is not what will be supported by default - you cannot fopen() URLs. If OpenCV specifically supported this, it would be possible, but I have some evidence that they do not:

Here is what you can do:

  • Load the image in another way - perhaps by calling system() on wget , perhaps using the library to load the file into memory
  • At least one source says you can use loadImage() Handling to load from a URL.
+2
source

Further search in response Roddy says I did everything for me.

Unfortunately, this is not nice and only a solution for Windows. But the only way to get jpg from this application is to get http in some way. There are many libs that can help, for example libcurl, boost :: asio. I used urlmon.lib to make me work:

 #inlcude <opencv2\opencv.hpp> #include <UrlMon.h> #include <tchar.h> #pragma comment(lib,"urlmon.lib") int main() { for(;;) { HRESULT hr = URLDownloadToFile(NULL,_T("http://192.168.1.104:8080/shot.jpg"), _T("D:/test.jpg"),0,NULL); IplImage *test = cvLoadImage("D:/test.jpg"); cvShowImage("test",test); cvWaitKey(30); } } 

This application can also transfer mpg, as I suggested in the comments. OpenCV VideoStream seems to be able to read from it, as suggested by Streaming video in openCv mode from the localHost port (http://192.168.1.1:8080) and OpenCV with network cameras . I tried this solution as well, but get mp3 header missing . I hope someone will provide some answer using videofeed from this app.

0
source

Source: https://habr.com/ru/post/905985/


All Articles