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;
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" );
printf("\nThis sample demonstrates structured forests for fast edge detection\n"
" structured_edge_detection -i=in_image_name -m=model_name [-o=out_image_name]\n\n");
cv::CommandLineParser parser(argc, argv, keys);
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);
printf("Cannot read image file: %s\n", inFilename.c_str());
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);
cv::namedWindow("edges", 1);
cv::imshow("edges", edges);
cv::waitKey(0);
cv::imwrite(outFilename, 255*edges);
运行以上代码的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