Created
April 21, 2017 09:27
-
-
Save MareArts/609e96a759d8612f70acd90c90415568 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
VideoCapture stream1(1); //0:note book, 1:usb webcam | |
Mat frame; //current frame | |
Mat gray, binary_otsu, binary_th, binary_ad_m, binary_ad_g; | |
namedWindow("img", 0); | |
namedWindow("otsu", 0); | |
namedWindow("binary_th", 0); | |
namedWindow("binary_adaptive_mean", 0); | |
namedWindow("binary_adaptive_gaussian", 0); | |
//unconditional loop | |
while (true) { | |
if (!(stream1.read(frame))) //get one frame form video | |
break; | |
//printf("%d %d \n", frame.cols, frame.rows); | |
resize(frame, frame, Size(frame.cols/2, frame.rows/2)); | |
cvtColor(frame, gray, CV_RGB2GRAY); | |
threshold(gray, binary_th, 128, 255, CV_THRESH_BINARY); | |
adaptiveThreshold(gray, binary_ad_m, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 9, 5); | |
adaptiveThreshold(gray, binary_ad_g, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 9, 5); | |
GaussianBlur(gray, gray, Size(7, 7), 0); | |
threshold(gray, binary_otsu, 0, 255, CV_THRESH_BINARY + THRESH_OTSU); | |
imshow("img", frame); | |
imshow("otsu", binary_otsu); | |
imshow("binary_th", binary_th); | |
imshow("binary_adaptive_mean", binary_ad_m); | |
imshow("binary_adaptive_gaussian", binary_ad_g); | |
if( waitKey(10)> 0 ) | |
break; | |
} | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment