Skip to content

Instantly share code, notes, and snippets.

@ivder
Created February 19, 2019 03:54
Show Gist options
  • Save ivder/e177483c38639e32b2a7c051f691892a to your computer and use it in GitHub Desktop.
Save ivder/e177483c38639e32b2a7c051f691892a to your computer and use it in GitHub Desktop.
Check black frame by splitting video color channel
int main(int argc, char *argv[]) {
int frameidx;
int blackframecnt = 0;
VideoCapture capture("black.mp4");
Mat frame;
while (true) {
if (!capture.read(frame)) {
break;
}
Mat output(frame.size(), frame.type());
vector<Mat> rgb;
//vector<Mat> hsv;
//vector<Mat> ycrcb;
//cvtColor(frame,output,CV_RGB2YCrCb);
namedWindow("Orginal");
imshow("Orginal", frame);
//split(frame, rgb);
split(frame, rgb);
frameidx = capture.get(CV_CAP_PROP_POS_FRAMES);
if (countNonZero(rgb[0]) == 0) {
//cout << frameidx << endl;
if (blackframecnt++ % 300 == 0) {
cout << "black frame" << endl;
PlaySound(L"alert4.wav", NULL, SND_FILENAME | SND_SYNC);
}
}
/*else {
cout << frameidx << endl;
}*/
/*namedWindow("b");
namedWindow("g");
namedWindow("r");*/
/*imshow("b", rgb[0]);
imshow("g", rgb[1]);
imshow("r", rgb[2]);*/
if (waitKey(25) >= 0)
break;
}
waitKey(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment