Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <opencv2/core/core.hpp>
  3. #include <opencv2/imgcodecs.hpp>
  4. #include <opencv2/highgui/highgui.hpp>
  5. #include <opencv2/imgproc.hpp>
  6.  
  7.  
  8. using namespace cv;
  9. using namespace std;
  10.  
  11.  
  12. const double MAX_VAL = 100;
  13. Mat inp, out;
  14.  
  15.  
  16. double fun (double x, double a)
  17. {
  18.     if (a == 0)
  19.         return x;
  20.     else
  21.         return max(255.0, x / a + a * 2 / x);
  22. }
  23.  
  24. void trackbar_callback (int value, void *user_data)
  25. {
  26.     for (int i = 0; i < inp.rows; i++)
  27.     {
  28.         for (int j = 0; j < inp.cols; j++)
  29.         {
  30.             out.at<float>(i, j) = fun(inp.at<float>(i, j), (double)value / MAX_VAL);
  31.         }
  32.     }
  33. }
  34.  
  35. Mat res;
  36.  
  37. int main ()
  38. {
  39.  
  40.     inp = imread("../../Images/cat.jpeg", CV_32FC1);
  41.     out = inp.clone();
  42.  
  43.     namedWindow("Track_bar", CV_WINDOW_NORMAL);
  44.  
  45.     int cur_pos = 0;
  46.     createTrackbar("parameter", "Track_bar", &cur_pos, MAX_VAL, trackbar_callback);
  47.  
  48.  
  49.     while (1)
  50.     {
  51.         hconcat(inp, out, res);
  52.         imshow("Track_bar", res);
  53.         int key = waitKey(30);
  54.         if (key == ' ')
  55.             break;
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement