Trackbar的使用

来源:互联网 发布:linux修改密码策略 编辑:程序博客网 时间:2024/05/16 17:36
/*author:Maracledate:二〇一六年四月五日content:Function to change between color and grayscalerepresentations of an image using GUI trackbar.*/#include<iostream>#include<opencv2/imgproc/imgproc.hpp>#include<opencv2/highgui/highgui.hpp>using namespace std;using namespace cv;//全局变量char* window_name = "Trackbar app";Mat src;int slider;const int slider_max = 1;//滑动条函数void on_trackbar(int pos, void*){Mat img_converted;if (pos > 0){cvtColor(src, img_converted, CV_RGB2GRAY);}elseimg_converted = src;imshow(window_name, img_converted);}int main(){src = imread("小黄人.png");namedWindow(window_name);imshow(window_name, src);slider = 0;createTrackbar("RGB<->GRAY", window_name, &slider, slider_max, on_trackbar);while (char(waitKey(10)) != 'q'){}return 0;}
<img src="http://img.blog.csdn.net/20160405204332878?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" style="font-family: Arial, Helvetica, sans-serif;" alt="" />
<img src="http://img.blog.csdn.net/20160405204356519?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

0 0
原创粉丝点击