void callback1(int pos, void*){ std::cout << "hmin" << pos << std::endl;}
void callback2(int pos, void*){ std::cout << "smin" << pos << std::endl;}
void callback3(int pos, void*){ std::cout << "vmin" << pos << std::endl;}
void callback4(int pos, void*){ std::cout << "hmax" << pos << std::endl;}
void callback5(int pos, void*){ std::cout << "smax" << pos << std::endl;}
void callback6(int pos, void*){ std::cout << "vmax" << pos << std::endl;}
int _tmain(int argc, _TCHAR* argv[])
{
Mat img = imread("D:\\11.jpg");
namedWindow("img", 0);
imshow("img", img);
Mat hsv, dst;
int hmin = 0;
int smin = 0;
int vmin = 0;
int hmax = 255;
int smax = 255;
int vmax = 255;
cvtColor(img, hsv, CV_RGB2HSV);
createTrackbar("hmin", "img", &hmin, 256, callback1);
createTrackbar("smin", "img", &smin, 256, callback2);
createTrackbar("vmin", "img", &vmin, 256, callback3);
createTrackbar("hmax", "img", &hmax, 256, callback4);
createTrackbar("smax", "img", &smax, 256, callback5);
createTrackbar("vmax", "img", &vmax, 256, callback6);
while (1)//循环包裹,刷新图像
{
inRange(hsv, Scalar(hmin, smin, vmin), Scalar(hmax, smax, vmax), dst);
namedWindow("dst", 0);
imshow("dst", dst);
int c = waitKey(10);
if (c == 'q')
break;
}
return 0;
}