Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main ()
- {
- Mat frame;
- Mat back;
- Mat fore;
- VideoCapture cap1;
- cap1.open(0); /*to capture from camera*/
- cv::Ptr<BackgroundSubtractorMOG> pMOG = createBackgroundSubtractorMOG();
- cv::Ptr<BackgroundSubtractorMOG2> pMOG2 = createBackgroundSubtractorMOG2();
- pMOG2->setNMixtures(10);
- vector < vector < Point > >contours;
- namedWindow ("Frame");
- int i=0;
- for (;;)
- {
- cap1 >> frame;
- pMOG2->operator()(frame, fore);
- pMOG2->getBackgroundImage (back);
- erode (fore, fore, cv::Mat ());
- erode (fore, fore, cv::Mat ());
- dilate (fore, fore, cv::Mat ());
- dilate (fore, fore, cv::Mat ());
- dilate (fore, fore, cv::Mat ());
- findContours (fore, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
- drawContours (frame, contours, -1, Scalar (255, 255, 255), 1);
- Scalar color = Scalar(200,200,200);
- int a=0;
- vector<Rect> boundRect( contours.size() );
- for( int i = 0; i < contours.size(); i++ )
- {
- boundRect[i] = boundingRect( contours[i] );
- }
- for( i = 0; i< contours.size(); i++ )
- {
- if(boundRect[i].width>=40 || boundRect[i].height>=40)//eliminates small boxes
- {
- a=a+(boundRect[i].height)*(boundRect[i].width);
- }
- // cout<<"Net contour area is "<<a<<"n";
- if(a>=int(frame.rows)*int(frame.cols)/2)//change denominator as per convenience
- {
- putText(frame,"Tampering",Point(5,30),FONT_HERSHEY_SIMPLEX,1,Scalar(0,255,255),2);
- cout<<"a";
- }
- }
- imshow ("Frame", frame);
- waitKey(10);
- }
Add Comment
Please, Sign In to add comment