Created
May 25, 2016 04:47
-
-
Save loveandsheep/84acc5c5bfa3e9fd108db427ce1606a4 to your computer and use it in GitHub Desktop.
cut up checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class liveCamKit{ | |
public: | |
void setup(); | |
void update(); | |
void setVideoSource(ofPtr<ofVideoPlayer> video); | |
bool checkCutUp(); | |
ofPtr<ofVideoPlayer> source; | |
bool CutLastFrame; | |
float means_total; | |
float means_prev; | |
float means_diff; | |
ofImage img_raw; | |
ofImage img_prev; | |
ofImage img_prev_small; | |
ofImage img_diff_small; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment