Guest User

Untitled

a guest
Dec 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. int main ()
  2. {
  3. Mat frame;
  4. Mat back;
  5. Mat fore;
  6. VideoCapture cap1;
  7. cap1.open(0); /*to capture from camera*/
  8. cv::Ptr<BackgroundSubtractorMOG> pMOG = createBackgroundSubtractorMOG();
  9. cv::Ptr<BackgroundSubtractorMOG2> pMOG2 = createBackgroundSubtractorMOG2();
  10. pMOG2->setNMixtures(10);
  11. vector < vector < Point > >contours;
  12. namedWindow ("Frame");
  13. int i=0;
  14.  
  15. for (;;)
  16. {
  17. cap1 >> frame;
  18. pMOG2->operator()(frame, fore);
  19. pMOG2->getBackgroundImage (back);
  20. erode (fore, fore, cv::Mat ());
  21. erode (fore, fore, cv::Mat ());
  22. dilate (fore, fore, cv::Mat ());
  23. dilate (fore, fore, cv::Mat ());
  24. dilate (fore, fore, cv::Mat ());
  25. findContours (fore, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
  26. drawContours (frame, contours, -1, Scalar (255, 255, 255), 1);
  27. Scalar color = Scalar(200,200,200);
  28. int a=0;
  29. vector<Rect> boundRect( contours.size() );
  30. for( int i = 0; i < contours.size(); i++ )
  31. {
  32. boundRect[i] = boundingRect( contours[i] );
  33. }
  34. for( i = 0; i< contours.size(); i++ )
  35. {
  36. if(boundRect[i].width>=40 || boundRect[i].height>=40)//eliminates small boxes
  37. {
  38. a=a+(boundRect[i].height)*(boundRect[i].width);
  39. }
  40. // cout<<"Net contour area is "<<a<<"n";
  41. if(a>=int(frame.rows)*int(frame.cols)/2)//change denominator as per convenience
  42. {
  43. putText(frame,"Tampering",Point(5,30),FONT_HERSHEY_SIMPLEX,1,Scalar(0,255,255),2);
  44. cout<<"a";
  45. }
  46. }
  47. imshow ("Frame", frame);
  48. waitKey(10);
  49. }
Add Comment
Please, Sign In to add comment