Skip to main content


OpenCV 4.5 simple optical flow GPU tutorial cuda::FarnebackOpticalFlow

This OpenCV tutorial is a very simple code example of GPU Cuda optical flow in OpenCV written in c++. The configuration of the project, code, and explanation are included for farneback Optical Flow method. Farneback algorithm is a dense method that is used to process all the pixels in the given image. The dense methods are slower but more accurate as all the pixels of the image are processed. In the following example, I am displaying just a few pixes based on a grid. I am not displaying all the pixes. In the opposite to dense method the sparse method like Lucas Kanade using just a selected subset of pixels. They are faster. Both methods have specific applications. Lucas-Kanade is widely used in tracking. The farneback can be used for the analysis of more complex movement in image scene and furder segmentation based on these changes. As dense methods are slightly slower, the GPU and Cuda implementation can lead to great performance improvements to calculate optical flow for all pixels o

Opencv HSL video stream to web

This tutorial will show you all components, configuration, and code needed to steam video output results from Opencv C++ to your Web player. The C++ program will take any video input and process this video. The processed video will be stream outside of OpenCV using the GStreamer pipeline (Windows part). The HLS video produces one Playlist file and several MPEG-TS segments of videos. This several HLS outputs are stored in the Windows file system. I am using WSL 2, windows subsystem for Linux to run Ubuntu distribution. Here the NGINX is installed with the RTMP module. NGINX is distributing a video stream from the windows file system to the web.  Let's have a look at this in more detail.  What is covered? Opencv C++ part + GStreamer pipeline NGINX configuration Architecture Web Player for your HLS stream What is not covered? Detailed instalation of Opencv + Gstreamer more here  GStreamer installation  ,  GStreamer Installation 2  on windows Detailed installation of NGINX + RTMP modul

Video motivation example of Opencv GStreamer HLS video stream output

 This video is a motivation example of how to build OpenCV C++ application that uses the GStreamer pipeline and produces your processed video as HLS stream. This video is describing many problems to reach the goal. You can follow my recommendation and try to build such an app by yourself. I mentioned all the troubles during the dev and the rest is almost easy.  There will be more video tutorials in more detail about this topic.  1. Install OpenCV 4.4 with GStreamer. I already have materials for this.  2. Setup nginx to expose your web with HLS video playlist and video segments.  3. Write your application on Windows and stream the video to a simple website This is the example of Opencv GStreamer HLS output stream to web

Opencv 4 C++ Tutorial simple Background Subtraction

Opencv tutorial C++ Background substraction This method is used to learn what belongs to the background of the image and what belongs to the foreground. The static cameras that monitor the area can very easily recognize, what is part of the image that is always here or there is something that is new and moving over the background.  Background subtraction Visual studio 2019 project setup If you have Opencv 4+ compiled or installed only steps you need to do is set the include directory with OpenCV header files. Set the Additional library Directories that point to \lib folder. Just note that Visual Studio 2019 should use VC16 \lib. Finally, As additional dependencies, specify the libs used to resolve the function implementation in the code. The list for Opencv 420 is here. The different version of opencv is using different numbering for example opencv 440 will use opencv_core440.lib.  opencv_bgsegm420.lib opencv_core420.lib opencv_videoio420.lib opencv_imgproc420.lib opencv_highgui420.

Compile opencv 4 with Cuda and GStreamer on windows

Compile OpenCV with Cuda is an easy task. All you need is the right HW from NVIDIA, drivers, and software. Additionally, the processed output video should be stream out from the OpenCV using the GStreamer. I am putting the GStreamer now as the standard option of my installation of OpenCV on the Windows machine.  Let's go through step by step compilation of OpenCV from source, including Cuda, Gstreamer, and contribution modules. It is just a small increment to my previous tutorial that focuses just on the GStreamer setting in the Windows CMAKE project.  This is a simplified version, verified on a different machine than the previous tutorials.  You can found some details in this tutorial Install Opencv Gstreamer on windows step by step .  Software prerequisites Install cuda, This is my version of network installer cuda_11.0.2_win10_network  Visual Studio 2019 community  Cmake 3.17.4  Opencv 4.4 Opencv_contrib Opencv Compilation in windows steps by step Extract or get through git open