Reputation: 376
We are currently working on a robotics project where we want to recognize elements with OpenCV. The detection already works in OpenCV with a video.
For the hardware we use a Raspberry Pi B2 with a Raspicam. After long search for something with minimal lag we found http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14
The WebRTC solution is by far the one with the lowest lag 200-300ms. Now we wish to open the WebRTC Stream in Java, however we weren't able so far.
Any pointers how we can open a WebRTC Stream in OpenCV in Java?
Upvotes: 2
Views: 1856
Reputation: 376
For anybody interested here how we were able to connect OpenCV over a h264 stream with a delay of 200-300ms over WLAN:
Follow the tutorial at:
http://www.daveconroy.com/turn-your-raspberry-pi-into-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/
Install uv4l on the raspberry pi:
$ curl http://www.linux-projects.org/listing/uv4l_repo/lrkey.asc | sudo apt-key add -
Add the following line to the file /etc/apt/sources.list :
deb http://www.linux-projects.org/listing/uv4l_repo/raspbian/ wheezy main
$ sudo apt-get update
$ sudo apt-get install uv4l uv4l-raspicam
Detailed instruction and documentation here: http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14
We were using OpenCV installed in ecplise according to this tutorial: http://docs.opencv.org/3.0-beta/doc/tutorials/introduction/java_eclipse/java_eclipse.html
Run the server on the raspberry pi:
Either install the uv4l-server according to the linux-projects website or per command line:
uv4l --auto-video_nr --driver raspicam --width 640 --height 480 --encoding h264 --server-option '--port=8080'
connect to the stream:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat image=new Mat();
VideoCapture capture = new VideoCapture();
capture.open("http://IPADDRESSofRaspberry:8080/stream/video.h264");
capture.read(image);
Important hints and potential errors:
Check the documentation of uv4l for speeds and resolution. We went with 640x480 @ 30fps.
If you want to check if the stream is loading you can open it in VLC mediaplayer, however make sure to set the correct demuxer:
http://www.stardot-tech.com/kb/index.php?View=entry&EntryID=186
Upvotes: 1
Reputation: 10048
Have you take a look at this one: http://www.rs-online.com/designspark/electronics/blog/building-a-raspberry-pi-2-webrtc-camera
Other option is to use a central MCU (check Medooze/McuWeb project) the idea is to connect your Raspberry via Websockets/SIP. This stream will be mixed into the MCU and then you can generate an additional stream back to any server (Example: Wooza) where you can apply OpenVC. Why do you need Java?
Upvotes: 0