OpenCV support about 3 types subtraction algorithm.
Those are MOG, MOG2, GMG algorithms.
Detailed algorithm explain is, please refer to opencv documnet.
In this post, just introduce source code and result of background subtraction.
firstly, see the results of 3 algorithms.
origin imageMOG resultMOG2 resultCMG result Especially, in MOG2 result, we can see the gray pixel color, that means shadow.This is result video of the source code.source code is here-> #include < stdio.h>
#include < iostream>
#include < opencv2\opencv.hpp>
#include < opencv2/core/core.hpp>
#include < opencv2/highgui/highgui.hpp>
#include < opencv2/video/background_segm.hpp>
#pragma comment(lib, "opencv_core247d.lib")
#pragma comment(lib, "opencv_imgproc247d.lib") //MAT processing
#pragma comment(lib, "opencv_objdetect247d.lib") //HOGDescriptor
//#pragma comment(lib, "opencv…
Firstly, to obtain 2 adjacent images
extract good feature to track.
Match each features between 2 images
Get Homography matrix
Warp current image to old image by using H.
However, H is multiplied by cumulatively.
Created Date : 2011.8Language : MatlabTool : Matlab 2010 Library & Utilized : - Reference : Multiple View Geometry (Hartly and Zisserman) etc. : Intrinsic Parameter, 2 adjacent images, matching points
This code is 8 point algorithm.
If we know over 8 corresponding points between two images, we can know Rotation and Translation of camera movement using 8 point algorithm.
The 8 point algorithm is well known in the vision major field.
The algorihtm is introduced at the Multiple View Geometry Book and many websites.
Have you ever listened Fundamental matrix song? The song is very cheerful. ^^
You can download 8 point algorithm at the Peter Covesi homepage.
My code is very simple. so I believe my code will be useful to you.
I will upload RANSAC version later.
So, as the above equation, H matrix convert A matrix to B matrix.In here, A is left, B is right 4 points in fig 1. In OpenCV function, findHomography function gives H matrix.Input parameter is findHomography(A, B). Do not confuse. After get H matrix, we can warp image using various transform functions in opencv.In this example, I use warpPerspective function, because rectangle shape is a trapezoidal model.Input parameter is warpPerspective(Origin_mage, warped_image, H, cv::Size(cols, rows)); see the test video of this example source code in herehttps://www.youtube.com/watch?v=UszvePGFuMQ