Ask Your Question

Jim OSullivan's profile - activity

2020-11-30 01:20:13 -0500 received badge  Good Question (source)
2017-02-04 10:52:23 -0500 received badge  Famous Question (source)
2016-06-09 05:02:11 -0500 received badge  Notable Question (source)
2016-02-24 12:22:43 -0500 received badge  Nice Question (source)
2016-01-28 08:04:56 -0500 received badge  Popular Question (source)
2015-07-09 14:55:55 -0500 received badge  Student (source)
2015-04-13 17:49:35 -0500 asked a question IP camera video corruption - solutions?

Has anyone been able to get an HD (720p or higher) IP camera working with OpenCV consistently and reliably? If so, did you use the standard VideoCapture interface or something else?

Many OpenCV users such as here and here have reported similar problems with using OpenCV to receive video from network cameras. The typical problem involves getting a bunch of decode errors in the console as well as seeing the image corrupted as follows:

image description

Some have reported that appending '?tcp' to the camera URL fixes the problem at the cost of latency, but this fix works only sometimes.

To characterize the problem, I've run a simple OpenCV video display program under various operating systems and configurations and each of the configurations below gets decoding errors:

  • Windows, OCV 2.4.11, with WIN32 graphics, no TBB
  • Windows, OCV 2.4.11, without WIN32 graphics, with TBB
  • Windows, OCV 2.4.11, with WIN32 graphics, with TBB
  • Windows, OCV 3, with WIN32 graphics
  • Windows, OCV 3, without WIN32 graphics, with TBB
  • Ubuntu, OCV 2.4.11, with ffmpeg, TBB and graphics
  • Ubuntu, OCV 2.4.11, no ffmpeg "Couldn't open the video file."
  • RPi Raspbian, OCV 2.4.11, with TBB and graphics

For testing, I'm using a Hikvision DS-2CD2032-i 1080p color H.264 IP camera. As a control case, I used the ffplay utility of FFMPEG to play the RTSP video stream from this camera for a day and a night with no errors.

I also tested OpenCV 2.4.11 and 3.0.0 beta under Windows 7SP1 x64, and OpenCV 2.4.11 under Ubuntu and Raspbian, with and without TBB.

Every configuration using OpenCV experienced decode errors, though under Linux the errors were less frequent. If I first record the video stream from the camera to a disk file then play the video file from disk, there are no errors.

The errors seem to occur when compressed video is streamed from a camera over the network and played back via OpenCV. Also, the frequency of decode errors seems proportional to the video bit rate. Also, the errors occur even when only 3% of a quad-core 4 GHz CPU is being used for decoding/display, so it doesn't seem to be a CPU bandwidth issue. My guess is that the problem is in the interface between FFMPEG and OpenCV.

Questions: 1. My test code is below - any obvious problems? 2. If you have an HD IP camera working reliably with OpenCV, did you use FFMPEG and the VideoCapture interface or something else?

Thank you.

#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

Mat frame;
string window_name = "Video Test";

int main(int argc, char *argv[])
{
    int counter = 0;
    VideoCapture capture("rtsp://192.168.1.43?tcp");
    if (!capture.isOpened())
    {
        cout << "Couldn't open the video file." << endl;
        return 1;
    }
    namedWindow(window_name, CV_WINDOW_KEEPRATIO);
    for (;;)
    {
        capture >> frame;
        counter++;
        if (frame.empty())
            break;
//        if ((counter % 20) == 0)
            imshow(window_name ...
(more)
2015-04-13 17:06:52 -0500 answered a question Opencv VideoCapture tcp stream

Compile with FFMPEG enabled - it handles interfacing to network video sources.

2015-04-11 00:18:52 -0500 received badge  Enthusiast
2015-01-30 22:10:58 -0500 asked a question WITH_WIN32UI + WITH_TBB errors compiling OpenCV 2.4.10 with mingw

I'm trying to compile OpenCV 2.4.10 on Windows 7 using MinGW 4.8.1, and get the following error when both WITH_TBB and WITH_WIN32UI are checked in CMake (3.1.0). OpenCV compiles and runs fine if built with either of those two options checked, but not both.

Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/window_w32.cpp.obj cd /d C:\opencv\my_build\modules\highgui && D:\MinGW\bin\g++.exe -DCVAPI_EXPORTS -DHIGHGUI_EXPORTS -fsigned-char -mstackrealign -W -Wall -Werror=return-type -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 -fdiagnostics-show-option -march=i686 -fomit-frame-pointer -ffast-math -msse -msse2 -mfpmath=sse -ffunction-sections -Wno-deprecated-declarations -DNDEBUG @CMakeFiles/opencv_highgui.dir/includes_CXX.rsp -include "C:/opencv/my_build/modules/highgui/precomp.hpp" -Winvalid-pch -o CMakeFiles\opencv_highgui.dir\src\window_w32.cpp.obj -c C:\opencv\sources\modules\highgui\src\window_w32.cpp C:\opencv\sources\modules\highgui\src\window_w32.cpp: In function 'void cvSetModeWindow_W32(const char*, double)': C:\opencv\sources\modules\highgui\src\window_w32.cpp:463:47: error: 'MONITOR_DEFAULTTONEAREST' was not declared in this scope hMonitor = MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);

Others have run into this issue with 2.4.8, but the fixes they reported are already incorporated into 2.4.10 and the problem occurs anyway. Any help would be greatly appreciated, thanks.