 |
OpenCV
4.2.0
Open Source Computer Vision
|
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
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());
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 : [Dollar2013] [Lim2013]
std::string String
Definition: cvstd.hpp:150
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
@ StsError
unknown /unspecified error
Definition: base.hpp:71
void convertTo(OutputArray m, int rtype, double alpha=1, double beta=0) const
Converts an array to another data type with optional scaling.
Template "trait" class for OpenCV primitive data types.
Definition: traits.hpp:112
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
Ptr< StructuredEdgeDetection > createStructuredEdgeDetection(const String &model, Ptr< const RFFeatureGetter > howToGetFeatures=Ptr< RFFeatureGetter >())
bool empty() const
Returns true if the array has no elements.
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
MatSize size
Definition: mat.hpp:2108
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
virtual void detectEdges(cv::InputArray _src, cv::OutputArray _dst) const =0
The function detects edges in src and draw them to dst.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
Definition: brightedges.hpp:47
n-dimensional dense array class
Definition: mat.hpp:791
int type() const
Returns the type of a matrix element.
Designed for command line parsing.
Definition: utility.hpp:796
virtual void edgesNms(cv::InputArray edge_image, cv::InputArray orientation_image, cv::OutputArray _dst, int r=2, int s=0, float m=1, bool isParallel=true) const =0
The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
bool imwrite(const String &filename, InputArray img, const std::vector< int > ¶ms=std::vector< int >())
Saves an image to a specified file.
"black box" representation of the file storage associated with a file on disk.
Definition: affine.hpp:51
virtual void computeOrientation(cv::InputArray _src, cv::OutputArray _dst) const =0
The function computes orientation from edge image.