OpenCV Background subtraction 3.2 version example (for MOG, MOG2, GMG, KNN)

This is example for background subtraction on opencv 3.2 version

previously, I post 2.7 version example on here.

But some usage is changed, and knn subtraction method is added.

Many people ask that example based on opencv 3.2

refer to below source code

Thank you.

< gist code >

< /gist code >


floodFill opencv function example

floodFill function example

< gist >

< /gist >

CallBackFunc, EVENT_LBUTTONDOWN, setMouseCallback, rectangle, floodFill,

video show and write keeping original fps

When the video write, we can set parameter in following function..

outVideo.open(".\\outVideo.avi", askFileTypeBox, capture.get(CV_CAP_PROP_FPS), S, Color);

And we can control play speed by waitKey.

double fps = capture.get(CV_CAP_PROP_FPS);
delay Per Second = 1/fps
in milliseconds = 1/fps * 1000

so we delay, waitKey( 1/fps * 1000 )

by the way, it is not exact fps. because it is delayed including other processing in the loop.
for example, data copy, sobel, imshow ...

< gist code >

< /gist code >





simple code for image coordinate to screen coordinate.

Arslan Ahmed, this is the post for you. ^^

< gist code start >

< gist code end >

mouse event, setMouseCallback, opencv, Total,


AMP dose run on my pc?, AMP(Accelerated Massive Parallelism)

AMP is abbreviation of Accelerated Massive Parallelism.
It is maintained by Microsoft and it run based on DirectX 11.
So as I know, AMP works in windows only, but there seems to be an attempt to run on other os.

Basically, AMP run on these environment
  • Windows 7, Windows 8, Windows Server 2008 R2, or Windows Server 2012 
  • DirectX 11 Feature Level 11.0 or later hardware 
  • For debugging on the software emulator, Windows 8 or Windows Server 2012 is required. For debugging on the hardware, you must install the drivers for your graphics card.
And no need to install for AMP, If you use Visual Studio.
So let's check your computer condition for parallel programming.

< code start >

< code end >

This is my condition.

We can check whether run or not by this.

if, accs.size() == 0, then there is no parallel machine.

I think AMP is easy and usefull to use parallel GPU programming.
This is useful for creating Windows applications.

reference site

Korean blog

MS site

MSDN AMP toturial


what is dp parameter in Hough Circle detection on opencv.

dp parameter is about resolution of voting space.
dp is larger, voting resolution is small compare to image size.
so dp is larger, circle detection accuracy is not exact.
but dp is smaller, voting resolution is higher and circle detection is more accurate but that sensitive with noise ex)other edge..
I increase dp from 1 to 5 step by 0.1..

refer to this source code on here.

< gist code >

< end gist >

and result image.


and other reference.
opencv org

stack overflow

python opencv tutorial

GaussianBlur, HoughCircles, CV_HOUGH_GRADIENT,


Refer to this setting when you build opencv with TBB

When you build opencv with checking with_tbb option, cmake ask crrect paths about tbb.

Refer to this setting.
note, this is set for vc12 and 32bit.






TBB doesn't have CMakelist.txt, go to here.

Intel Threading Building Blocks..

I downloaded the source code here -> https://www.threadingbuildingblocks.org/
and I want to build it with cmake.

But I meet this error -> ...does not appear to contain CMakeLists.txt

Looking for a long time to figure out what to do ..
I found this site -> https://github.com/wjakob/tbb

Thank you.


vtkStructuredGrid example for drawing fan shape grid.

This is example code for drawing fan shape grid using vtkStructuredGrid in vtk.

I've looked at a lot of examples that draw like this, but I could not find it.

So this example help for vtk beginner and want to drawing grid.

< code start >

< code end >

#vtkStructuredGrid, #vtk


class member thread using std

class member function threading

1. No argument
< code start >

< code end >

2. additional arguments
< code start >

< code end >

3. Lambda Express
std::thread t( [&] { x.greeting(); } ); //no argument
std::thread t( [&] { x.greeting( "goodbye" ); } ); //with argument

Static or global function threading

< code start >

< code end >

#thread, #std, #lambda


no override found for 'vtkPolyDataMapper'

When meet this error no override found for 'vtkPolyDataMapper' using VTK.
Add this code

#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)

More detail
refer to this url


Including VTK when building opencv

First, we download VTK and build it.

We set the path where VTK is built, when we build opencv.

Note that, we need to include the build path, not the installed path.

If you go to the above address, I have built VTK 7.1.
And new content will continue to be added.

Good luck!


In MFC, File exist check and delete the file, example source code.

If file exist then delete the file, example source code in MFC

< github code >

MFC Encode / Decode example souce code

WtoC function code is here

And refer to GetMacAddress code

Encode code


Decode code


Unicode CString convert to char *

The returned char * will need to be freed after use.

< gist code start >

< gist code end >

wchar_t, WtoC, WideCharToMultiByte, WideCharToMultiByte

useful site for CString converting


Get Mac Address in MFC

GetMacAddress in MFC

Get by using GetAdaptersInfo function

Get by using ip address
//If localhost -> GetMacAddress(_T("*"));
//if have ip -> GetMacAddress(_T(""));//