How to start programming Computer Vision with OpenCV and IP Camera in Windows 10, Visual Studio 2019 C++. Part 1

Kirill Mityugin
3 min readNov 5, 2020
It’s me)

There is a lot articles about developing CV in Python and/or Ubuntu OS everywhere, but not so much about C++ and VS2019 though it’s native for OpenCV libraries and most powerful language for Deep Learning & Computer Vision projects.

I’ll try to collect in this article what you need to start your first project detecting objects in real time with your IP(or USB) Camera.

First you need a powerful computer for such project because on my CPU Intel Core i5 9400f, 16Gb RAM, 1Tb M.2 NVMe SSD I get a couple FPS of CV that is unacceptable, next we will use GPU acceleration on CUDA cores, so you also need a powerful NVIDIA graphics card.

You have Windows 10, Visual Studio 2019 with C++ components, that’s great, I also developing helping tools in C# such as Discovery Tool for ONVIF IP cameras where you can get IP address for your next project

or just View your Camera with OpenCV in a beautiful WPF App:

To start programming in C++ with OpenCV you need:

  1. Download binaries for Windows and source code from https://opencv.org/releases/ and place it usually to C:\opencv:
C:\opencv folder

2. There is great article how to add dependancies to your new project, so just not repeat it again look inside:

All you need to change there is file name for current version of library opencv_world420d.lib => opencv_world450d.lib

3. Source code for your first project so here it is:

https://gist.github.com/YashasSamaga — great author for OpenCV projects

as well as examples on OpenCV site

I changed it for my purposes so here is my variant:

You need download DNN model files yolov4-tiny.cfg and yolov4-tiny.weights (using here mini YOLOv4 models, you can change to full) and classes80.txt for classes list and place all to folder C:\TEMP

(All files you can download from my Github project)

classes80.txt looks like this so you can change what to detect (using 80, full list contains about 9k classes):

  • person
  • bicycle
  • car
  • motorcycle
  • cat
  • dog

My changes to original code:

using namespace cv;
using namespace std;

— for shorter names

std::ifstream class_file(“C:\\TEMP\\classes80.txt”);

— path to classes TXT file

string video = “rtsp://192.168.0.30:554/user=admin_password=tlJwpbo6_channel=0_stream=1.sdp?real_stream”;
VideoCapture source;
source.open(video.c_str());

auto net = cv::dnn::readNetFromDarknet(“C:\\TEMP\\yolov4-tiny.cfg”, “C:\\TEMP\\yolov4-tiny.weights”);

— URL to my IP cam RTSP stream (using 1.sdp for low resolution and higher FPS or 0.sdp for FullHD resolution and low rate)

— Path to YOLOv4 models, you can change here for full models or use another DNN framework

4. Don’t forget to change DEBUG in VS2019 to x64 and Run:

That’s all simple as it is folks :-) Next time I’ll use CUDA GPU accelerating in the same code, because 1–2 FPS not good))

Thanks for reading! Clap here if you liked it…

--

--