Skip to content

Instantly share code, notes, and snippets.

@loveandsheep
Created May 25, 2016 04:47
Show Gist options
  • Save loveandsheep/84acc5c5bfa3e9fd108db427ce1606a4 to your computer and use it in GitHub Desktop.
Save loveandsheep/84acc5c5bfa3e9fd108db427ce1606a4 to your computer and use it in GitHub Desktop.
cut up checker
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);
}
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