SHARE
TWEET

Untitled

a guest Jun 17th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <opencv2/opencv.hpp>
  2. #include <opencv2/highgui/highgui.hpp>
  3. using namespace cv;
  4.  
  5. #define WINDOW_NAME "【GBR调色板+3滑动条】"
  6.  
  7. //色彩取值范围0~255,滑动条取值范围0~100。转换比例为2.55。
  8. const int g_nMaxBlueValue = 255;
  9. int g_nBlueValueSlider;
  10. double g_dBlueValue;
  11. double g_dBetaBlueValue;
  12.  
  13.  
  14. void on_Trackbar(int, void*)
  15. {
  16.     Mat Image;
  17.  
  18.     //求出当前Blue值相对于最大值的比例
  19.     g_dBlueValue = (double)g_nBlueValueSlider / g_nMaxBlueValue;
  20.     //则betaBlue值为1减去Blue值
  21.     g_dBetaBlueValue = (1.0 - g_dBlueValue);
  22.    
  23.     Image = Scalar(g_nBlueValueSlider, g_nBlueValueSlider, g_nBlueValueSlider);
  24.  
  25.     imshow(WINDOW_NAME, Image);
  26. }
  27.  
  28. int main()
  29. {
  30.     //设置滑动条初值为255
  31.     g_nBlueValueSlider = 255;
  32.  
  33.     //创建窗体
  34.     namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE);
  35.  
  36.     //在创建的窗体中创建一个滑动条控件
  37.     char TrackbarName[300];
  38.     sprintf_s(TrackbarName, "颜色控制 %d", g_nMaxBlueValue);
  39.  
  40.     createTrackbar(TrackbarName, WINDOW_NAME, &g_nBlueValueSlider, g_nMaxBlueValue, on_Trackbar);
  41.  
  42.     //结果在回调函数中显示
  43.     on_Trackbar(g_nBlueValueSlider, 0);
  44.  
  45.     //按任意键退出
  46.     waitKey(0);
  47.  
  48.     return 0;
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top