Guest User

Untitled

a guest
Jun 13th, 2014
259
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <opencv2/core/core.hpp>
  2. #include <opencv2/highgui/highgui.hpp>
  3. #include <opencv2/imgproc/imgproc.hpp>
  4.  
  5. #include <sstream>
  6.  
  7. void distanceTransform(int size)
  8. {
  9.     std::stringstream ss;
  10.     int rectangleSize = size / 4;
  11.  
  12.     // Create sample Mat with white rectangle
  13.     cv::Mat data = cv::Mat::zeros(size, size, CV_8UC1);
  14.     cv::rectangle(data, cv::Point(rectangleSize, rectangleSize), cv::Point(size - rectangleSize, size - rectangleSize), cv::Scalar::all(255), CV_FILLED);
  15.     cv::Mat copy;
  16.     data.copyTo(copy);
  17.  
  18.     ss << size << "-rectangle.tiff";
  19.     cv::imwrite(ss.str(), data);
  20.  
  21.     // distance transform with [Borgefors86]
  22.     cv::distanceTransform(data, data, CV_DIST_L2, CV_DIST_MASK_5);
  23.     ss.str("");
  24.     ss << size << "-borgefors86.tiff";
  25.     cv::imwrite(ss.str(), data);
  26.  
  27.     cv::threshold(data, data, 0, 255, CV_THRESH_BINARY);
  28.     ss.str("");
  29.     ss << size << "-borgefors86-binary.tiff";
  30.     cv::imwrite(ss.str(), data);
  31.  
  32.     // distance transform with [Felzenszwalb04]
  33.     cv::distanceTransform(copy, copy, CV_DIST_L2, CV_DIST_MASK_PRECISE);
  34.     ss.str("");
  35.     ss << size << "-felzenszwalb04.tiff";
  36.     cv::imwrite(ss.str(), copy);
  37.  
  38.     cv::threshold(copy, copy, 0, 255, CV_THRESH_BINARY);
  39.     ss.str("");
  40.     ss << size << "-felzenszwalb04-binary.tiff";
  41.     cv::imwrite(ss.str(), copy);
  42. }
  43.  
  44. int main()
  45. {
  46.     distanceTransform(2500);
  47.     distanceTransform(10000);
  48.  
  49.     return 0;
  50. }
RAW Paste Data