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 <opencv2/ximgproc.hpp>

 #include "opencv2/highgui.hpp"

 #include "opencv2/core/utility.hpp"

 

 using namespace cv;

 using namespace cv::ximgproc;

 

 const char* keys =

扫描二维码关注公众号,回复: 2968409 查看本文章

 {

  "{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<std::string>("m");

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

  std::string outFilename = parser.get<std::string>("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<float>::type, 1/255.0);

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

 

  cv::Ptr<StructuredEdgeDetection> 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

猜你喜欢

转载自blog.csdn.net/jiao_mrswang/article/details/81905182