Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void liveCamKit::setup()
- {
- flag_checkCutUp = true;
- lastFrame = 0;
- }
- void liveCamKit::update()
- {
- if (source && source->isFrameNew())
- {
- lastFrame = source->getCurrentFrame();
- ofxCv::copy(*source.get(), img_raw);
- ofxCv::resize(img_raw, img_diff_small);
- ofxCv::absdiff(img_prev_small, img_diff_small, img_diff_small);
- ofxCv::copy(img_raw, img_prev);
- ofxCv::resize(img_prev, img_prev_small);
- img_prev.update();
- img_diff_small.update();
- if (flag_checkCutUp) checkCutLastFrame = checkCutUp();//カットされたかどうかのbool
- }
- }
- bool liveCamKit::checkCutUp()
- {
- if (source)
- {
- cv::Mat mt = ofxCv::meanCols(img_diff_small).clone();
- means_total = 0.0;
- for (int i = 0;i < mt.rows;i++)
- {
- for (int j = 0;j < 3;j++)
- means_total += mt.at<cv::Vec3b>(i)[j];
- }
- means_total /= float(mt.rows);
- means_diff = abs(means_total - means_prev);
- means_prev = means_total;
- return means_diff > 70;
- }
- else
- {
- return false;
- }
- }
- void liveCamKit::setVideoSource(ofPtr<ofVideoPlayer> video)
- {
- source = video;
- ofVec2f scale = ofVec2f(source->getWidth(), source->getHeight());
- ofVec2f small = scale / 3.0;
- img_raw.allocate(scale.x, scale.y, OF_IMAGE_COLOR);
- img_prev.allocate(scale.x, scale.y, OF_IMAGE_COLOR);
- img_prev_small.allocate(small.x, small.y, OF_IMAGE_COLOR);
- img_diff_small.allocate(small.x, small.y, OF_IMAGE_COLOR);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement