Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This code worked for me:

Mat image = Imgcodecs.imread("my_image_path", Imgcodecs.IMREAD_LOAD_GDAL | Imgcodecs.IMREAD_COLOR);
StructuredEdgeDetection p = Ximgproc.createStructuredEdgeDetection("model/model.yml.gz");
Mat fsrc = new Mat();
image.convertTo(fsrc, CvType.CV_32F, 1.0 / 255.0);
Mat edges = new Mat(fsrc.size(), fsrc.type());
p.detectEdges(fsrc, edges);
for (int row = 0; row < edges.rows(); row++) 
        for (int col = 0; col < edges.cols(); col++) 
        edges.put(row, col, edges.get(row, col)[0] * 255);
Imgcodecs.imwrite("my_path" + "edges.png", edges);

This test java code worked for me:StructuredEdgeDetection

Mat image = Imgcodecs.imread("my_image_path", Imgcodecs.IMREAD_LOAD_GDAL | Imgcodecs.IMREAD_COLOR);
StructuredEdgeDetection p = Ximgproc.createStructuredEdgeDetection("model/model.yml.gz");
Mat fsrc = new Mat();
image.convertTo(fsrc, CvType.CV_32F, 1.0 / 255.0);
Mat edges = new Mat(fsrc.size(), fsrc.type());
p.detectEdges(fsrc, edges);
for (int row = 0; row < edges.rows(); row++) 
        for (int col = 0; col < edges.cols(); col++) 
        edges.put(row, col, edges.get(row, col)[0] * 255);
Core.multiply(edges, new Scalar(255), fsrc);
Imgcodecs.imwrite("my_path" + "edges.png", edges);
fsrc);