Skip to main content

Compile Opencv with GStreamer for Visual Studio 2019 on windows 10 with and contribution modules

The goal of this tutorial is a simple step by step compilation of Opencv 4.2 with contribution extra modules with GStreamer as a bonus. The environment is Windows 10, Visual Studio 2019 C++ application. This took me almost one day of correcting of CMake setting. The goal of this tutorial is: compiled a set of OpenCV libraries with GStreamer and FFmpeg on Windows. I focus mainly on GStreamer. It is a little bit more tricky. You will reach the following information about your Opencv environment by compile and run this simple code. The Opencv GStreamer is turned as YES. GStreamer gives you a great opportunity to stream OpenCV output video outside of your program, for example, web application.

I recently compiled with opencv 4.4. The update at the end of the post. 
It is working!! wow, The working app and configuration in future tutorials.
opencv on web video stream

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main()
    std::cout << "Hello World!\n";
    std::cout << cv::getBuildInformation() << std::endl; 
Visual studio opencv gstreamer

Environment for opencv under windows compiled with extra modules and GStreamer

1) Get Opencv source. I would like to reccomand to take released version. I took Opencv 4.2 source code zip on the left and released opencv_contrib 4.2 zip on the right. 

2) Get Cmake, I will recommend downloading the 3.17 release candidate 3 for 64-bit Windows. I failed with 3.16.5.
3) Extract OpenCV source into opencv-4.2.0
4) Extract OpenCV source into opencv_contrib-4.2.0
5) Extract Cmake for example into the same root folder
6) Create the empty build folder as you can see on the image with directories. 
7) Download and install GStreamer from
MSVC 64-bit (VS 2019), You can download and install both, but the1.16.2 development installer for MSVC 64-bit (VS 2019) is important.
The result of the installation is this directory structure.  It will be linked with our Cmake configuration later on.  
8) Make sure you have Visual Studio 2019 with all C++ functionality

Configure Cmake to compile Opencv with GStreamer on windows

I have a problem with this for a long time. I installed OpenCV with FFmpeg and GStreamer on Linux Debian and on Ubuntu for many times. I installed OpenCV with contribution and FFmpeg libraries on windows as well many times. The Opencv GStreamer took me almost whole weekend to let this works. It is not so difficult at all. 
9)  Open cmake/bin folder and start cmake-gui.exe
10)Add "where is the source code" as main /opencv-4.2.0 folder
11)Add "where to build the binaries" as new created /build folder
12) Hit configure button and select Visual Studio 2019
13) Wait for the end of configuration and ADD OENCV_EXTRA_MODULES_PATH
to point into /opencv_contrib-master/modules
14) Lesson learned Correct the path of extra modules with this /
If you use path c:\opencv_contrib-master\modules the error message when parsing string problem will occur. 
15) Set all GStreamer path as follows:
Note: Some points directly to xx.lib which is important!! Some points into the header include directory.

16) Hit Configure
17) Hit Generate if the configuration is OK
18) Open project if 16- 17 are DONE

Build a Visual Studio Opencv project with GStreamer on windows

19) Change project to Release and x64
20) Right-click on whole solution and select build solution
21) After the solution is successfully built, install the solution by build just INSTALL in the solution  

22) installation is done, The ready to use libraries and headers are located under build/install

Visual Studio 2019 Opencv with GStreamer configuration

24) Create a new C++ console application in Visual Studio 2019
25) Change the project to x64, I am using Release configuration. 
26) Open property of your project and set Additional include directory. This variable points into the include directory under install folder. (picture above)
27) Under Linker- General- Additional Library Directories set- path to your install lib directory example c:\xxx\xxx\build3\install\x64\vc16\lib

28) Under Linker-Input -Set Additional dependencies variable- Set names of OpenCV libraries as opencv_core420.lib

29) Copy opencv_core420.dll into your project next to testOpencvGstreamer.exe or set environment variables to find your OpenCV dlls.
30) Compile the project and with the expected result

The next tutorial will be about the OpenCV GStreamer program example.


To use GStreamer you need to add path system environment variables to access GStreamer runtime as follows. 
gstreamer windows 10 opencv

Opencv GStreamer youtube tutorial for Visual studio

Youtube tutorial build OpenCV from source with Gstreamer on windows

This will be a future tutorial, How to build the Opencv Gstreamer app on windows.

Thanks for sharing: How to compile Opencv  with GStreamer on Windows Visual Studio

Opencv 4.4 Gstreamer

gstreamer opencv 4.4


  1. Hi, great tutorial!

    I'm trying to use GStreamer with OpenCV too and found your blog, but still I didn't achieve it to work fine in Windows (In Linux my code works perfect ). I got next error on execution:
    [ WARN:0] global C:\opencv\modules\videoio\src\cap_gstreamer.cpp (1274) cv::CvVideoWriter_GStreamer::close_ OpenCV | GStreamer warning: No source in GStreamer pipeline. Ignore
    [ERROR:0] global C:\opencv\modules\videoio\src\cap.cpp (415) cv::VideoWriter::open VIDEOIO(GSTREAMER): raised OpenCV exception:

    OpenCV(4.2.0) C:\opencv\modules\videoio\src\cap_gstreamer.cpp:144: error: (-215:Assertion failed) ptr in function 'cv::`anonymous-namespace'::GSafePtr::get'

    (I also got a similar issue when I'm trying to use VideoCapture).

    Have you see something like that? Do you have any idea?

    BTW, you have a minor mistake when you type "OPENCV_EXTRA_MODULES_PATH" in step 13.


    1. Hi, I have seen this issue. I do not know the resolution. I have clean installation. I will try to reproduce it. I remember the problems with final pipeline that works in Linux and not worked in windows. It was somethink like extra space after the last character in pipeline: max=0 sync=true " It fixed my problem. Another issue can be problem with set up windows environmental variables of GStreamer for runtime. I will try to replicate your problem. Just try add extra space at the end of Pipeline and Fix windows environmental variables.

      VideoWriter writer(
      "appsrc ! videoconvert ! videoscale ! video/x-raw,width=320,height=240 ! theoraenc ! oggmux ! tcpserversink host= port=8080 recover-policy=keyframe sync-method=latest-keyframe unit-format=buffers units-max=1 buffers-max=0 sync=true ",
      Size(320, 240),

    2. Update : I have a same problem with Opencv 4.4 . IT was tested on 4.2. Stil this can be a configuration problme.


Post a Comment

Popular posts from this blog

Opencv 3.1 Tutorial Optical flow (calcOpticalFlowFarneback)

Farneback Optical flow Opencv simple C++ tutorial and code to achieve optical flow and farneback optical flow of moving an object in opencv video. Lets check the video example and the achieved result on my blog. Working and well describe code is included. 

Optical Flow Farneback parameters remarksYou need 2 images at least to calculate optical flow, the previous image (prevgray) and current image (img).  !! The previous image must be initialized first !!  Both images have to be gray scale. 
Result is computer in flowUmat which has same size as inputs but format is CV_32FC2

0.4- image pyramid or simple image scale
1 is number of pyramid layers. 1 mean that flow is calculated only from previous image.  12 is win size.. Flow is computed over the window larger value is more robust to the noise.  2 mean number of iteration of algorithm 8 is polynomial degree expansion recommended value are 5 - 7 1.2 standard deviation used to smooth used derivatives recommended values from 1.1 - 1,5

Fast Opencv people pedestrian detection Tutorial by CascadeClassifier

Simple Opencv C++ tutorial and example of people detection in video samples and pictures. There is nothing you cannot achieve in few simple steps. People detection and performace tasks in opencv could be solved if you have little bit knowledge of programing. Or just simple follow the steps..  Opencv tutorial instalation of opencv You can simple prepare the project inside the Visual Studio 2015 by Nuget Packages. This approach is easy for beginers and better than standard installation with all the environmental variables problems. Just follow the installation steps inside here 

Opencv is great and complex tools. There is lot of image processing and also machine learning features. You can simply learn your own detector. I would like to prepare some tutorial how to learn your own detector. It is long time run. 
All, you need to do, is some experience and basic opencv tools.  under opencv/build/x64/vc14/bin
Prepare your dataset and files w…

Install opencv Visual Studio 2015

Install opencv for Visual Studio 2015  Opencv tutorial how to build opencv from source in Visual Studio 2015. This is usefull when the new version just release and there is no prebuild library awailable..  If you download prebuild libs for windows Visual studio some times agou there is problem the newest VS just mussing. Lets checkt the version of libraries and VS.
Prebuild libs are only for version VC11 and VC12. This mean Visual Studio 2012 and 2013.

This step helps you compile your own opencv libs for VC14  - Visual Studio 2015 Community edition.

Important !!
 Now a days just use NUGET packages in Visual studio and you can code under 1 minutes. here.

Prepare third party libs for opencv  This step depends on your requirements. If you want python lets install python. But i can reccomend to install following parts. 
Intel © Threading Building Blocks (TBB)Intel © Integrated Performance Primitives (IPP) Build opencv 3.0.0  Download Opencv 3.0.0 gold…

Opencv C++ Tutorial, Mat Roi, Region of interest

Opencv ROI, Region of Interest Simple opencv C++ tutorial how to work with ROI. Code example about selecting the rectangle region of interest inside the image and cut or display part of the image from the bigger picture. There is nothing what is difficult about this. Only trick is about one line of code. 
Rect RectangleToSelect(x,y,width,height) Mat source; Mat roiImage = source(RectangleToSelect);
This is first post from this series. This simple opencv tutorials are all over the web. I would like to visualize all my steps through the code and //comment them. Each tutorial will contain small amount of step to keep reader focused.  First tutorial about mat resizeing is available under that link Mat Resize
I am using Visual Studio 2015,  How to use Opencv 3.0.0 with Visual Studio can be found here install opencv visual studio 2015. In Visual studio 2015 is best options to use NUGET packages, Here is described how to install Opencv by NUGET. It is easy. Working under one minute after you f…

Opencv VideoCapture File, Web Camera, RTSP stream

Opencv VideoCapture File, Camera and stream Opencv tutorial simple code in C++ to capture video from File, Ip camera stream and also the web camera plug into the computer. The key is to have installed the FFMPEG especially in case of reading the stream of IP cameras. In windows just use Opencv Installation by Nugets packages Here. Simple easy under 2 minutes installation. In Linux you need to follow the instruction below. If you are on Debian Like package system. Under Fedora Red hat dist just use a different approach. Code is simple and installation is the key.. 
Windows use nugets packages Linux you have to install and build Opencv With FFMPEG. Also simple.  It is easy to capture video in OpenCV Video capture
 in OpenCV is a really easy task, but for a little bit experienced user. 
What is the problem?
The problem is the installation of Opencv without recommended dependencies.

Just install all basic libs that are recommended on the website.
# Basic packagessudo apt-get -y install …

Opencv reading IP camera, Video stream, Web camera, images and

Opencv reading video files, reading video stream, Images, IP and Web cameras. I would like to cover this all in one post. Yes, video writer is also important to store your results and achievements in video. There is couple of simple trick and if you follow them, you will never have a problem with the reading and writing video, stream, files in future. Basic opencv web camera reading There is couple think you need to take care. My favorite installation on windows platform is trough NUGET package system. It is easy in few steps. I describe this many times for example VS 2017 here. Nuget set up your project without any linking settings, library path selection, global environmental variables and you can directly start coding in few seconds. Just select and install nuget and compile code below. Nothing else.  You need to take care if you have included several thinks. highgui.hpp core.hpp, imgproc.hpp, videoio, imgcodecs. All of them are not necessary to read the web camera but for example…

Opencv build and install Visual Studio 2017 Contrib library

Easy install and build of Opencv 3+ tested on 3.2 version with contributor library and additional features described step by step, picture by picture. After this tutorial you can modify setting of CMAKE project according to HW possibilities and available libraries to build your own Opencv library. Most of the time, Prebuild libs with already generated DLL, LIBS are used to start project and coding. In case, that new visual studio 2017 is available there is no prebuild libraries for VS141, Thich is from my point of view confusing naming of Libraries compatible with Visual Studio 2017. Opencv VS 2017 install options Alternatives to this tutorial. You can skip this.  There is possibility use some compatibility pack downloaded to VS140 and use same prebuild library as in case of Visual Studio 2015 this is described hereThe second way is to try use some prebuild NUGET package. I am using nugets a lot. Simple installation under one line of code inside nuget packages console. here
Opencv Ins…

Head and people detection in opencv

LBP cascade for detect head and people in opencv  LBP cascade free to download to use in opencv to detect people and heads. Code example and cascade description. All you need to write your own people head detector from the youtube video.
Cascade is trained on my own people and head datasets. There are no perfect but in some cases are better then default opencv cascades. They are just different.. For example you can count that the head detector have much more false detection than the people detector.. The shape and feature space is much more common and close to others shapes than the whole people detector.

Issues with opencv detectMultiScale head and people detector Please let me know if cascades worked as expected.. In code example there is ground threshold settings and reccomentation. 

LBP cascade head detection properties Sure you can find inside file.
<!-- This is just basic 16 stage lbp cascade head detector develop by  V.K. from --> <?xml …

Opencv C++ Tutorial Mat resize

Opencv Mat Resize   Resize the Mat or Image in the Opencv C++ tutorial. It is obviously simple task and important to learn. This tutorial is visualized step by step and well-described each of them. The main trick is in that simple code.

Mat Input;
Mat Resized;
int ColumnOfNewImage = 60;
int RowsOfNewImage = 60;
resize(Input, Resized, Size(ColumnOfNewImage,RowsOfNewImage));

This code just takes an Input image and resized save to output Mat. How big is the resized image is based on the Size? Size just contains two parameters. Simple numbers of how the result should be big. The simple number of columns (width) and rows (height). That is basically it. Enjoy

                                                Boring same face again and again. 

Load Image, resize and save Opencv C++ #include <Windows.h> #include "opencv2\highgui.hpp" #include "opencv2\imgproc.hpp" #include "opencv2\video\background_segm.hpp" #include "opencv2\video\tracking.hpp"
using n…

Opencv 3.1 people detection by CascadeClassifier

People detection by Cascade Classifier Opencv The comparison of Opencv Cascade for people detections. Default opencv cascades are good one. You can simply achive better result but you need to collect the training data. On my blog you can find the datasets for car detection. There is more than 2000 positives car samples available for you and test to learn your own detector..  Here in this article, I just want to show my cascade compare to cascade which are default in opencv.  LBP cascade for people detection Also I recently publish LBP cascade for people detection. You can download 12 stage LBP cascade LBP cascade for download. There is couple or maybe more than 3 tutorials how to use detect multiscale in opencv. Just download the LBP cascade and enjoy coding in Opencv..

Haar Cascade Classifier for People detection In this short tutorial, I would like to test some standard haar cascade in opencv 3.1.  My first note is where you can find this cascades. When you download opencv for wind…