Ask Your Question
1

Reading video stream from IP camera in OpenCV Java

asked 2013-11-16 06:07:00 -0600

Will Stewart gravatar image

updated 2013-11-19 19:39:42 -0600

I'm working towards an advanced motion detection plugin for openHab.org using OpenCV Java, and need to be able to read a video stream directly from an IP camera, preferably an h.264 stream.

I have found out how to do the with a webcam, but an IP camera is a very different problem. I would prefer not to store video to a file and read from the file to keep delays at a bare minimum (unless that's the only solution).

How is this best accomplished in OpenCV Java?

Based on a suggestion by Haris below; I tried;

 VideoCapture capture = new VideoCapture();
    capture.open("http://192.168.0.156/view/viewer_index.shtml?id=87&dummyparam=dummy.mjpg");

The results are; Exception in thread "main" java.lang.UnsatisfiedLinkError:
org.opencv.highgui.VideoCapture.VideoCapture_0()J at
org.opencv.highgui.VideoCapture.VideoCapture_0(Native Method) at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:101) at
org.openhab.action.videoanalytics.MotionDetect.main(MotionDetect.java:24)

Per Alexander Smorkalov's suggestion, I updated to 2.4.7.

Now when I execute;

VideoCapture capture = new VideoCapture("http://192.168.0.156/view/viewer_index.shtml?id=87&dummyparam=dummy.mjpg");

it seems to behave, with no errors thrown. I'm using Eclipse as my dev/debug environment, so I'm stepping through (and into many) lines of code with it's debugger.

The following line results in 'true' (and prints out the text), which implies that the VideoCapture connection has been opened;

if (capture.isOpened()) {
    System.out.println("Video is captured");}

But there is nothing there when I go to grab frames from the mjpeg feed;

Inside the C++ VideoCapture class is a 'grab()' operation that is returning 'false';

boolean retVal = grab_0(nativeObj);

And then this error message appears;

GStreamer Plugin: Embedded video playback halted; module decodebin20 reported: Your GStreamer installation is missing a plug-in.

I went to Ubuntu Software Center, did a search on GStreamer and came up with this list of plugins, which are all installed on my system;

GStreamer FFMPEG video plugin, GStreamer extra plugins GStreamer plugins for mms, wavpak, quicktime, musepack GStreamer plugins for aas, xvid, mpeg2, faad

So I went to Synaptic to see what GStreamer plugins where loaded or available. I must say I was rather stunned by the long list, and have not been able to determine which plugin I'm missing. I'm including a screenshot of the list (and there are a few more past the end of the screenshot);

C:\fakepath\GStreamerPlugInList.png

Am I simply declaring it improperly, or is there a better way? @berak has said that this is not yet fully implemented in the baselined code, so do I need to report this as a bug?

Please bear with me, I'm new here and returning to Java programming after 12 years away from hands-on coding.

edit retag flag offensive close merge delete

Comments

1

@Will, not your fault, it's a bug. there's no native open method(or constructor), that takes a string(file/url).

it was fixed in master, but unfortunately not in 2.4

berak gravatar imageberak ( 2013-11-16 11:14:40 -0600 )edit

4 answers

Sort by ยป oldest newest most voted
2

answered 2013-11-16 06:48:46 -0600

Haris gravatar image

You can use OpenCV videoCapture to open network stream as you open your web-cam. You should use something like

IpCam.open("http://192.168.1.30:8080/?dummy=param.mjpg");

Hope these helpful...

edit flag offensive delete link more

Comments

The string the operation is looking for is supposed to be a filename, though I gave it a try anyway. My snippet;

    VideoCapture capture = new VideoCapture();
    capture.open("http://192.168.0.156/view/viewer_index.shtml?id=87");

The results are;

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.VideoCapture.VideoCapture_0()J at org.opencv.highgui.VideoCapture.VideoCapture_0(Native Method) at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:101) at org.openhab.action.videoanalytics.MotionDetect.main(MotionDetect.java:24)

Am I simply declaring it improperly?

Will Stewart gravatar imageWill Stewart ( 2013-11-16 09:46:29 -0600 )edit
1

Try adding a dummy param, at the end, something like capture.open("http://192.168.0.156/view/viewer_index.shtml?id=87?dummy=video.mjpg"); because opencv videCapture expect an extension at file name end.

Haris gravatar imageHaris ( 2013-11-16 11:04:11 -0600 )edit

@Haris, thanks, this has gotten me further down the road. Cheers!

Will Stewart gravatar imageWill Stewart ( 2013-11-16 11:38:17 -0600 )edit
2

@Will Stewart Make sure you are loading the shared library via System.loadLibrary(Core.NATIVE_LIBRARY_NAME).

jverce gravatar imagejverce ( 2014-09-23 12:36:26 -0600 )edit
2

answered 2013-11-18 03:52:16 -0600

Issue with this constructor was fixed in 2.4.7 release. Update OpenCV and try again.

edit flag offensive delete link more

Comments

Good suggestion @Alexander Smorkalov, I've taken it, and it seems to be helpful, as I am further down the road now. My success with MJPEG is limited, as I can now execute this successfully;

VideoCapture capture = new VideoCapture("http://169.254.71.156/view/viewer_index.shtml?id=87&dummyparam=out.mjpg");

It returns 'true' on isOpen(), but does not return 'true' on grab(), so I'm still working to resolve that.

When I shift the camera and code to h264 with the following statement;

VideoCapture capture = new VideoCapture("rtsp://169.254.71.156/axis-media/media.amp");

it seems to capture the camera stream and responds 'true' to isOpen() and grab().

However, it throws a null pointer exception on read(image) or even retrieve(image). I believe I should open a new question.

Will Stewart gravatar imageWill Stewart ( 2013-11-18 21:46:34 -0600 )edit

I am using OpenCV 2.4.9 and getting the same error as reported in this thread. What can be the reason for this?

Tariq gravatar imageTariq ( 2014-09-09 11:30:41 -0600 )edit
0

answered 2016-12-13 03:23:23 -0600

After 3 to 4 weeks of hardwork,I found a 100% working solution for this

First of All you have to load the ffmpeg's dll file Dynamically i-e Using

System.loadLibrary("[NAME OF YOUR DLL FILE]")

You can find the required dll file in opencv/build/x64/vc11/bin The name of DLL in my case is "opencv_ffmpeg2413_64.dll" copy the file to default path of the Project and use

`System.loadLibrary("opencv_ffmpeg2413_64");`//You May have different File Name Depending on the Version of OpenCV Installed on your Computer

Then You can Simply use

VideoCapture ipcamera = new VideoCapture("[RTSP URL OF THE IP Camera]")//I used this Demo Link (rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov)
edit flag offensive delete link more

Comments

It's the holy grail!!!

JJMartinezg gravatar imageJJMartinezg ( 2017-02-20 17:53:37 -0600 )edit
0

answered 2013-11-21 15:07:43 -0600

gieha gravatar image

IP camera response = HTTP/1.1 401 Unauthorized

edit flag offensive delete link more

Comments

giea, please remove your 'answer' s here ( they're no answers, they're new questions )

and ask a new question instead. please!

berak gravatar imageberak ( 2013-11-21 15:19:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2013-11-16 06:07:00 -0600

Seen: 39,034 times

Last updated: Nov 21 '13