c++ - OpenCV Background substraction using Absdiff -
i've been working program detect hands background substracting. have tried save first frame of camera background , substract current frame, appeared have different brightness somehow. i've tried several times , dont have , light changing, can problem? image1 image2
#include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include "camera.h" #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/video/background_segm.hpp> using namespace cv; using namespace std; int main() { const int laptop_cam = 0; const int lifecam = 1; const int max_fps = 25; camera cam(lifecam); mat background; cam.takeshot(); cam.mirrorimage(); cam.getframe().copyto(background); //deep copy imshow("background", background); mat diff; while (true) { cam.takeshot(); cam.mirrorimage(); absdiff(cam.getframe(),background , diff); imshow("result", cam.getframe()); imshow("diff", diff); cam.set_fps(max_fps); if (waitkey(1) == 27) break; } }
here "camera.cpp":
#include "camera.h" camera::camera() { } camera::~camera() { } camera::camera(int camnum) { videocapture cap(camnum); _capture = cap; } void camera::takeshot() { _capture >> _frame; } void camera::set_fps(int fps) { if (fps > 25) fps = 25; else if (fps < 1) fps = 1; _capture.set(cv_cap_prop_fps, fps); } mat camera::getframe() { return _frame; } void camera::mirrorimage() { flip(_frame, _frame, 1); }
there should subtle lighting change , absolute subtraction hardly work. if have use absolute different, might want threshold diff
.
however, should background subtraction algorithm. opencv has built-in methods: mog2, knn.
also, can detect hands using skin (color) detection.
Comments
Post a Comment