Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. struct  Thresh
  2. {
  3.     double thMin = 0;
  4.     double thMax = 255;
  5.     double resolution = 1;
  6.     int minTbV = 0;
  7.     int maxTbV = 0;
  8.  
  9.     double Range()
  10.     {return thMax - thMin;}
  11.  
  12.     int Ticks()
  13.     {return cvRound(Range()/resolution);};
  14.  
  15.     double minValue()
  16.     {return thMin + minTbV * Range() / Ticks();}
  17.  
  18.     double maxValue()
  19.     {return thMin + maxTbV * Range() / Ticks();}
  20.  
  21.     //int tbValue = cvRound(Ticks() / 2.0); // start at 50%
  22. };
  23.  
  24. void onTrackBar(int, void* userData)
  25. {
  26.     Thresh *pdata = (Thresh*)userData;
  27.  
  28.     double minTh = pdata->minValue();
  29.     double maxTh = pdata->maxValue();
  30.  
  31.     std::cout << "MIN threshold:" << minTh << endl;
  32.     std::cout << "MAX threshold:" << maxTh << endl;
  33. }
  34.  
  35. Mat open_images(int i)
  36. {
  37.     string fullfileName;
  38.     stringstream ss;
  39.     Mat image;
  40.  
  41.     ss << "C:/Users/Filip/Desktop/DATA/test" << i << ".jpg" << endl;
  42.     ss >> fullfileName;
  43.     image = cv::imread(fullfileName, 1);
  44.     return image;
  45. }
  46.  
  47.  
  48. void changing_thresh()
  49. {
  50.     Thresh data;
  51.     static const char * winName = "MyWindow";
  52.     Mat IMAGE = cv::imread("C:/Users/Filip/Desktop/Frame.jpg", 1);
  53.     Mat img;
  54.     int i = 1;
  55.  
  56.     while (1)
  57.     {
  58.         if (waitKey(30) == 27)
  59.         {
  60.             i++;
  61.             IMAGE = open_images(i);
  62.         }
  63.         cv::namedWindow(winName);
  64.         cv::createTrackbar("MinThresh", winName, &(data.minTbV), data.Ticks(), onTrackBar, &data);
  65.         cv::createTrackbar("MaxThresh", winName, &(data.maxTbV), data.Ticks(), onTrackBar, &data);
  66.         onTrackBar(0, &data);
  67.         img = edgedetect(IMAGE, data.minTbV, data.maxTbV);
  68.         imshow("MyWindow", img);
  69.         char c = (char)waitKey(25);
  70.     }
  71.     cv::waitKey(1);
  72. }
  73.  
  74.  
  75. int main()
  76. {
  77.     changing_thresh();
  78.     waitKey();
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement