Introduction
In this tutorial you will learn how to use structured forests for the purpose of edge detection in an image.
Examples
image
image
image
image
image
image
image
image
image
image
image
image
- Note
- binarization techniques like Canny edge detector are applicable to edges produced by both algorithms (Sobel and StructuredEdgeDetection::detectEdges).
Source Code
13 using namespace cv::ximgproc;
17 "{i || input image name}"
19 "{o || output image name}"
22 int main(
int argc,
const char** argv )
24 bool printHelp = ( argc == 1 );
25 printHelp = printHelp || ( argc == 2 &&
String(argv[1]) ==
"--help" );
26 printHelp = printHelp || ( argc == 2 &&
String(argv[1]) ==
"-h" );
30 std::cout <<
"\nThis sample demonstrates structured forests for fast edge detection\n"
32 " structured_edge_detection -i=in_image_name -m=model_name [-o=out_image_name]\n\n";
37 if ( !parser.check() )
51 if ( modelFilename.size() == 0)
56 Mat edges(image.size(), image.type());
60 pDollar->detectEdges(image, edges);
64 pDollar->computeOrientation(edges, orientation_map);
68 pDollar->edgesNms(edges, orientation_map, edge_nms, 2, 0, 1,
true);
70 if ( outFilename.size() == 0 )
75 imshow(
"edges nms", edge_nms);
79 imwrite(outFilename, 255*edges);
Explanation
- Load source color image
{
printf("Cannot read image file: %s\n", inFilename.c_str());
return -1;
}
- Convert source image to [0;1] range
- Run main algorithm
pDollar->detectEdges(image, edges);
- Show results
if ( outFilename == "" )
{
}
else
Literature
For more information, refer to the following papers :Dollar2013Lim2013