Is it normal for "new VideoCapture()" to take AGES?

asked 2014-09-29 12:04:23 -0600

arp gravatar image

I've built an inventory robot for a warehouse. It has two IP cameras (Vivotek CC8130). Its onboard computer is a FitPC, the operator console is a random Lenovo notebook. Both computers run OpenCV 2.4.9 on Debian GNU/Linux Jessie/sid. The onboard program and the operator console share the same codebase. They are written in Java 1.6.

In principle, everything works. I can open a video stream into the cameras from both computers. Both "http" and "rtsp" work. Once the stream is open, performance is reasonable....

...but what absolutely puzzles me: on both computers, it takes AGES (something like one minute per camera) to perform the following operation (both for RTSP and HTTP, but HTTP seems to take especially long):

logger.info("Attempting to open video capture for mast camera.");
vcMast = new VideoCapture("http://127.0.0.1:8001/video2.mjpg");
// VideoCapture vcMast = new VideoCapture("rtsp://127.0.0.1:5554/live2.sdp");

This occurs every time. It occurs when connecting directly and likewise when going through SSH tunnels (the sample code shows "127.0.0.1" for the camera IP, because it was copied during SSH testing). To provide a little context of what I'm doing:

// Import libraries.
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;
/.../
public class ClientMain {
/.../
// Initialize OpenCV
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
/.../
public VideoCapture vcMast = null;
public VideoCapture vcFloor = null;
/.../
logger.info("Welcome to OpenCV " + Core.VERSION);
/.../
try {
logger.info("Attempting to open video capture for mast camera.");
vcMast = new VideoCapture("http://127.0.0.1:8001/video2.mjpg");
// VideoCapture vcMast = new VideoCapture("rtsp://127.0.0.1:5554/live2.sdp");
/.../

....and here it hangs for a whole minute, before getting to:

if (vcMast.isOpened())

P.S. What I notice: when it finally gets unstuck, and I get to call "vcMast.read(frame)", where "frame" is an object of type "Mat"... I immediately get a bunch of past frames, as if they had been accumulating in a buffer somewhere. Once the buffer is spent, I start getting fresh frames.

edit retag flag offensive close merge delete

Comments

P.S. I have by now measured that RTSP works significantly better than HTTP. Unfortunately, I cannot get RTSP to work via SSH tunnels.

I know that for "ffmpeg" (using which, as far as I know, OpenCV does its RTSP work) accepts the command line option "-rtsp_transport tcp", which makes it use TCP. Does anyone know, is there a way to specify this in OpenCV, especially when using the Java API?

arp gravatar imagearp ( 2014-09-29 16:47:56 -0600 )edit

Hi, from me experience with IP cameras they do take awhile to connect with OpenCV, from memory it would take about 30 seconds.

Messina Vision Systems gravatar imageMessina Vision Systems ( 2014-09-29 23:05:05 -0600 )edit