I am working on a project using OpenCV243, I need to get the foreground during the stream, my problem is that I use cv :: absdiff to get it, it really does not help, here is my code and the result.
#include <iostream> #include<opencv2\opencv.hpp> #include<opencv2\calib3d\calib3d.hpp> #include<opencv2\core\core.hpp> #include <opencv2\highgui\highgui.hpp> int main (){ cv::VideoCapture cap(0); cv::Mat frame,frame1,frame2; cap >> frame; frame.copyTo(frame1); cv::imwrite("background.jpeg",frame1); int key = 0; while(key!=27){ cap >> frame; cv::absdiff(frame, frame1, frame2); // frame2 = frame -frame1 cv::imshow("foreground", frame2); if(key=='c'){ //frame.copyTo(frame2); cv::imwrite("foreground.jpeg", frame2); key = 0; } cv::imshow("frame",frame); key = cv::waitKey(10); } cap.release(); return 0; }

as you can see the subtraction works, but what I want to get is only the values ββthat have been changed, for example, if the pixel in the background is from [130,130,130] and the same pixel has [200,200,200] in the frame I want to get exactly last values, not [70,70,70] I already saw this tutorial: http://mateuszstankiewicz.eu/?p=189 but I canβt understand the code and I have problems installing cv :: BackgroundSubtractorMOG2 with my version openCV
in advance for help
source share