Structured forests for fast edge detection

opencv实现P. Dollár的《Structured forests for fast edge detection》

代码网址:https://docs.opencv.org/3.1.0/d0/da5/tutorial_ximgproc_prediction.html

代码如下:

 #include

 #include "opencv2/highgui.hpp"

 #include "opencv2/core/utility.hpp"

 

 using namespace cv;

 using namespace cv::ximgproc;

 

 const char* keys =

 {

  "{i || input image name}"

  "{m || model name}"

  "{o || output image name}"

 };

 

 int main( int argc, const char** argv )

 {

  bool printHelp = ( argc == 1 );

  printHelp = printHelp || ( argc == 2 && std::string(argv[1]) == "--help" );

  printHelp = printHelp || ( argc == 2 && std::string(argv[1]) == "-h" );

 

  if ( printHelp )

  {

  printf("\nThis sample demonstrates structured forests for fast edge detection\n"

  "Call:\n"

  " structured_edge_detection -i=in_image_name -m=model_name [-o=out_image_name]\n\n");

  return 0;

  }

 

  cv::CommandLineParser parser(argc, argv, keys);

  if ( !parser.check() )

  {

  parser.printErrors();

  return -1;

  }

  std::string modelFilename = parser.get("m");

  std::string inFilename = parser.get("i");

  std::string outFilename = parser.get("o");

  cv::Mat image = cv::imread(inFilename, 1);

  if ( image.empty() )

  {

  printf("Cannot read image file: %s\n", inFilename.c_str());

  return -1;

  }

  image.convertTo(image, cv::DataType::type, 1/255.0);

  cv::Mat edges(image.size(), image.type());

 

  cv::Ptr pDollar =

  createStructuredEdgeDetection(modelFilename);

  pDollar->detectEdges(image, edges);

  if ( outFilename == "" )

  {

  cv::namedWindow("edges", 1);

  cv::imshow("edges", edges);

  cv::waitKey(0);

  }

  else

  cv::imwrite(outFilename, 255*edges);

  return 0;

 }

运行以上代码的bat文件如下:

resize.exe structured_edge_detection -i=G:\bluetooth\1color.png -m=G:\opencv310\model.yml.gz -o=G:\bluetooth\edge.png

pause

对以上bat文件的解释:resize.exe是由以上代码成功编译生成的。

参考文章:https://stackoverflow.com/questions/33317152/model-file-for-opencvs-structured-edge-detector

https://ask.csdn.net/questions/665539#answer_584624

 

你可能感兴趣的:(Structured forests for fast edge detection)