#includeusing namespace cv; int main() { VideoCapture cap("input.avi"); if (!cap.isOpened()) { return -1; } int frameCount = cap.get(CAP_PROP_FRAME_COUNT); int frameRate = cap.get(CAP_PROP_FPS); Mat frame; int i = 0; while (cap.read(frame)) { if (i % 10 == 0) { imshow("Frame", frame); waitKey(1000 / frameRate); } i++; } cap.release(); destroyAllWindows(); return 0; }
#includeIn this example, we load an image using `imread` and convert it to grayscale using `cvtColor`. We then apply a threshold to the grayscale image to create a binary mask using `threshold`. We then apply the mask to the original image using `img.copyTo` to get a result image that only shows the pixels that pass the threshold condition. We then display the result image using `imshow` and `waitKey`.using namespace cv; int main() { Mat img = imread("input.jpg"); if (img.empty()) { return -1; } Mat grayImg; cvtColor(img, grayImg, COLOR_BGR2GRAY); Mat mask; threshold(grayImg, mask, 100, 255, THRESH_BINARY); Mat result; img.copyTo(result, mask); imshow("Result", result); waitKey(0); return 0; }