1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <stdio.h> #include "math.h"
using namespace cv; Mat src, dst, gray;
int threshold_value = 127; int threshold_max = 255; String s[] = { "input", "output" }; int type_value = 2; int type_max = 4;
void (int, void*); int main(int argc, char** argv) {
src = imread("D:/documents/pictures/test.jpg"); if (!src.data) { printf("could not openn"); return -1; }
namedWindow(s[0], CV_WINDOW_AUTOSIZE); namedWindow(s[1], CV_WINDOW_AUTOSIZE); imshow(s[0], src); createTrackbar("threshold value", s[1], &threshold_value, threshold_max, threshold_demo); createTrackbar("type value", s[1], &type_value, type_max, threshold_demo); threshold_demo(0, 0);
waitKey(0); return 0; }
void (int, void*) { cvtColor(src, gray, CV_BGR2GRAY); threshold(gray, dst,threshold_value, threshold_max, type_value); imshow(s[1], dst); }
|
近期评论