IP Camera Capture delay/lag
Hello,
I am trying to so some processing on a IP Camera (Onvif) output image, and it works well, but I see a lag between the real world and the video capture in about 3~4 seconds.
I am using the rtsp:// protocol.
This camera have a web interface (IE / ActiveX) that shows the image with very low lag. (about 200~300 ms).
I have no idea why it's so slow on OpenCV. I wold like some tips to make the capture faster.
edit: It May have something to do with VideoCapture buffer. Is there a way to make it aways use the latest image?
edit2: I could get good lag results on VLC, after reducing cache/buffer to 300ms, I believe network and processing are not to blame. Now I got a stronger feeling that cache is to blame
Thank you!
You can see the code I am using bellow, i also included the output:
CODE
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <thread>
#include <unistd.h>
using namespace cv;
using namespace std;
int main(int argc, char *argv[])
{
cout << getBuildInformation();
VideoCapture cap;
cout << "open stream: " << argv[1] << endl;
if(!cap.open(argv[1]))
exit(-1);
cout << "stream open!\n";
Mat test;
do{
cap >> test;
if(test.empty()){
cout << "Empty!\n";
} else {
imshow("imagem", test);
}
} while(waitKey(1) < 0);
}
Output
leonardo@LeonardoB:~/Desktop/Ether_Test/build$ make ; ./EtherTest rtsp://admin:[email protected]:554/ucast/11
Scanning dependencies of target EtherTest
[ 50%] Building CXX object CMakeFiles/EtherTest.dir/main.cpp.o
[100%] Linking CXX executable EtherTest
[100%] Built target EtherTest
General configuration for OpenCV 3.1.0-dev =====================================
Version control: 3.1.0-1362-gcde9d64
Extra modules:
Location (extra): /home/leonardo/OpenCV/OpenCV3/opencv_contrib/modules
Version control (extra): 3.1.0-297-g246ea8f
Platform:
Timestamp: 2016-09-22T13:20:09Z
Host: Linux 4.7.4-1-ARCH x86_64
CMake: 3.6.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: Release
C/C++:
Built as dynamic libs?: NO
C++ Compiler: /usr/bin/c++ (ver 6.2.1)
C++ flags (Release): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/cc
C flags (Release): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations ...
It May have something to do with VideoCapture buffer. Is there a way to make it aways use the latest image?
I could get good lag results on VLC, after reducing cache/buffer to 300ms, I believe network and processing are not to blame. Now I got a stronger feeling that cache is to blame
I am also like the poster not happy with the delay but in my case it is about 1 second and VLC is about the same. If I set the VLC cache to anything less than 600ms, it drops all frames on the floor as late. There is a way to tell VLC not to drop late frames which may help but I forgot where to find that option.
Real answer is:You need to grab as fast as the camera fps, else it goes to a buffer, and it causes lag.
hello is there any way to have less than a few hundred milliseconds lag on an ip camera? I want to use an infrared camera to focus on an object 1-2 inches away. What camera can have this short focal length ? or do i neeed to use a USB camera ?
I have same question。I change IP Camera' fps to 1,and the delay change to 2s.