Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model file for OpenCV's structured edge detector

Tags:

c++

opencv

OpenCV implements StructuredEdgeDetection based on the random forest based approach outlined in "Structured Forests for Fast Edge Detection" (2013) by P. Dollár and C. Zitnick. The authors have published an implementation for Matlab and there's also one for Python, both of which also contain a pretrained model based on the BSDS500 dataset.

The OpenCV implementation seems to be lacking a pretrained model and I'm also unable to uncover what format the only constructor it offers expects:

Ptr<cv::StructuredEdgeDetection> createStructuredEdgeDetection(String model)
The only available constructor
Parameters: model – model file name

The documentation also doesn't outline how to train the OpenCV implementation, so I'm left quite in the dark.

To recap, how to use the OpenCV implementation? Is a trained model available? If not, how to train one using OpenCV?

like image 802
Etheryte Avatar asked Oct 24 '15 10:10

Etheryte


People also ask

How do I use Canny edge detection in python?

Canny Edge detection is an Algorithm consisting of 4 major steps: Reduce Noise using Gaussian Smoothing. Compute image gradient using Sobel filter. Apply Non-Max Suppression or NMS to just jeep the local maxima.

How do we detect edges of items in a drawing in OpenCV?

How are Edges Detected? Edges are characterized by sudden changes in pixel intensity. To detect edges, we need to go looking for such changes in the neighboring pixels. Come, let's explore the use of two important edge-detection algorithms available in OpenCV: Sobel Edge Detection and Canny Edge Detection.

What is edge detection in OpenCV?

It is a multi-stage algorithm and we will go through each stages. Noise Reduction. Since edge detection is susceptible to noise in the image, first step is to remove the noise in the image with a 5x5 Gaussian filter. We have already seen this in previous chapters. Finding Intensity Gradient of the Image.


1 Answers

You can use this model from opencv_extra ximgproc test data.

If you want to train your own model, you can follow instructions on OpenCV tutorials.

Image:

enter image description here

Edges:

enter image description here

Code:

#include <opencv2\opencv.hpp>
#include <opencv2\ximgproc.hpp>

using namespace cv;
using namespace cv::ximgproc;

int main()
{
    Ptr<StructuredEdgeDetection> pDollar = createStructuredEdgeDetection("path_to_model.yml.gz");

    Mat3b src = imread("path_to_image");

    Mat3f fsrc;
    src.convertTo(fsrc, CV_32F, 1.0 / 255.0);

    Mat1f edges;
    pDollar->detectEdges(fsrc, edges);

    imshow("Image", src);
    imshow("Edges", edges);
    waitKey();

    return 0;
}
like image 142
Miki Avatar answered Nov 04 '22 11:11

Miki