Advertisement
Guest User

Untitled

a guest
May 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. void liveCamKit::setup()
  2. {
  3. flag_checkCutUp = true;
  4. lastFrame = 0;
  5. }
  6.  
  7. void liveCamKit::update()
  8. {
  9. if (source && source->isFrameNew())
  10. {
  11. lastFrame = source->getCurrentFrame();
  12. ofxCv::copy(*source.get(), img_raw);
  13. ofxCv::resize(img_raw, img_diff_small);
  14. ofxCv::absdiff(img_prev_small, img_diff_small, img_diff_small);
  15.  
  16. ofxCv::copy(img_raw, img_prev);
  17. ofxCv::resize(img_prev, img_prev_small);
  18.  
  19. img_prev.update();
  20. img_diff_small.update();
  21.  
  22. if (flag_checkCutUp) checkCutLastFrame = checkCutUp();//カットされたかどうかのbool
  23. }
  24. }
  25.  
  26. bool liveCamKit::checkCutUp()
  27. {
  28. if (source)
  29. {
  30. cv::Mat mt = ofxCv::meanCols(img_diff_small).clone();
  31.  
  32. means_total = 0.0;
  33.  
  34. for (int i = 0;i < mt.rows;i++)
  35. {
  36. for (int j = 0;j < 3;j++)
  37. means_total += mt.at<cv::Vec3b>(i)[j];
  38. }
  39. means_total /= float(mt.rows);
  40. means_diff = abs(means_total - means_prev);
  41. means_prev = means_total;
  42.  
  43. return means_diff > 70;
  44. }
  45. else
  46. {
  47. return false;
  48. }
  49. }
  50.  
  51. void liveCamKit::setVideoSource(ofPtr<ofVideoPlayer> video)
  52. {
  53. source = video;
  54.  
  55. ofVec2f scale = ofVec2f(source->getWidth(), source->getHeight());
  56. ofVec2f small = scale / 3.0;
  57.  
  58. img_raw.allocate(scale.x, scale.y, OF_IMAGE_COLOR);
  59. img_prev.allocate(scale.x, scale.y, OF_IMAGE_COLOR);
  60.  
  61. img_prev_small.allocate(small.x, small.y, OF_IMAGE_COLOR);
  62. img_diff_small.allocate(small.x, small.y, OF_IMAGE_COLOR);
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement