1 | initial version |
just go with the inRange() function since it is more convenient:
Mat mask;
cv::Scalar lowRange = cv::Scalar(0, 0, 0);
cv::Scalar upperRange = cv::Scalar(0, 0, 0);
cv::inRange(frame, lowRange, upperRange, mask); // if the frame has any black pixel, this will be painted in the mask as white
if(countNonZero(mask) = 0) // no black pixels we keep the frame
{
Mat frame1 = frame.clone();
imshow("Output", frame1);
out.write(frame1);
}
2 | No.2 Revision |
just go with the inRange() function since it is more convenient:
Mat mask;
cv::Scalar lowRange lowerb = cv::Scalar(0, 0, 0);
cv::Scalar upperRange upperb = cv::Scalar(0, 0, 0);
cv::inRange(frame, lowRange, upperRange, lowerb, upperb, mask); // if the frame has any black pixel, this will be painted in the mask as white
if(countNonZero(mask) = 0) // no black pixels we keep the frame
{
Mat frame1 = frame.clone();
imshow("Output", frame1);
out.write(frame1);
}
3 | No.3 Revision |
edit: I transformed it to an answer since I could not edit my comment. Now it should be ok.
just go with the inRange() function since it is more convenient:
Mat mask;
cv::Scalar lowerb = cv::Scalar(0, 0, 0);
cv::Scalar upperb = cv::Scalar(0, 0, 0);
cv::inRange(frame, lowerb, upperb, mask); // if the frame has any black pixel, this will be painted in the mask as white
imshow("mask", mask); // show where black pixels are located
if(countNonZero(mask) = == 0) // no black pixels we keep the frame
{
cout << "frame does not have black pixels!!!!" << endl;
Mat frame1 = frame.clone();
// do whatever you want with the frame
}else{
imshow("Output", frame1);
cout << "frame has black pixels!!!" << endl;
out.write(frame1);
// skip frame
}
4 | No.4 Revision |
edit: I transformed it to an answer since I could not edit my comment. Now it should be ok.
just go with the inRange() function since it is more convenient:
Mat mask;
cv::Scalar lowerb = cv::Scalar(0, 0, 0);
cv::Scalar upperb = cv::Scalar(0, 0, 0);
cv::inRange(frame, lowerb, upperb, mask); // if the frame has any black pixel, this will be painted in the mask as white
imshow("mask", mask); // show where black pixels are located
located, visualization reason only
if(countNonZero(mask) == 0) // no black pixels we keep the frame
{
cout << "frame does not have black pixels!!!!" << endl;
// do whatever you want with the frame
}else{
cout << "frame has black pixels!!!" << endl;
// skip frame
}