Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

StructuredEdgeDetection - detectEdges method - Android

Hi everyone,

I managed until now with help of the forum to install openCV with extra modules and to get a model for the StructuredEdgeDetection and to implement it correctly to android. My problem now is with method detectEdges which gives an error every time I try to execute it. Here is my code :

    //bitmap to detect it's edges
    Mat rgba = new Mat();
    Utils.bitmapToMat(bitmap, rgba);
    //same bitmap to to greyscale it
    Mat grey = new Mat();
    Utils.bitmapToMat(bitmap, grey);

    StructuredEdgeDetection pDollar = createStructuredEdgeDetection(DATA_PATH + "SEDmodel" + ".yml");

    //convert the source Mat object to float
    Mat src = new Mat();
    rgba.convertTo(src, CvType.CV_32FC3, 1.0 / 255.0);


    //convert the destination Mat to float
    Mat edges = new Mat(grey.size(), CvType.CV_8UC1);
    Imgproc.cvtColor(grey, edges, Imgproc.COLOR_RGB2GRAY, 4);
    grey.convertTo(edges, CvType.CV_32FC3, 1.0 / 255.0);


    //try to detect the edges
    pDollar.detectEdges(src, edges);


    //convert the edges to Mat
    Mat output = new Mat();
    edges.convertTo(output, CvType.CV_8UC1, 255.0);

    //convert Mat to bitmap to display it
    Bitmap resultBitmap = Bitmap.createBitmap(edges.cols(), edges.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(edges, resultBitmap);

    return resultBitmap;

The error that I'm getting :

Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.0-dev) /Users/Chao/opencv_contrib/modules/ximgproc/src/structured_edge_detection.cpp:529: error: (-215) _src.type() == (((5) & ((1 << 3) - 1)) + (((3)-1) << 3)) in function virtual void cv::ximgproc::StructuredEdgeDetectionImpl::detectEdges(cv::InputArray, cv::OutputArray) const

I checked the line 529 in structured_edge_detection.cpp (link) as shown in the error and I saw this :

 * The function detects edges in src and draw them to dst
 *
 * \param _src : source image (RGB, float, in [0;1]) to detect edges
 * \param _dst : destination image (grayscale, float, in [0;1])
 *              where edges are drawn

And to my understanding that's what I did in the code snippet above. Any help is much appreciated.

StructuredEdgeDetection - detectEdges method - Android

Hi everyone,

I managed until now with help of the forum to install openCV with extra modules and to get a model for the StructuredEdgeDetection and to implement it correctly to android. My problem now is with method detectEdges which gives an error every time I try to execute it. Here is my code :

    //bitmap to detect it's edges
    Mat rgba = new Mat();
    Utils.bitmapToMat(bitmap, rgba);
    //same bitmap to to greyscale it
    Mat grey = new Mat();
    Utils.bitmapToMat(bitmap, grey);

    StructuredEdgeDetection pDollar = createStructuredEdgeDetection(DATA_PATH + "SEDmodel" + ".yml");

    //convert the source Mat object to float
    Mat src = new Mat();
    rgba.convertTo(src, CvType.CV_32FC3, 1.0 / 255.0);


    //convert the destination Mat to float
    Mat edges = new Mat(grey.size(), CvType.CV_8UC1);
    Imgproc.cvtColor(grey, edges, Imgproc.COLOR_RGB2GRAY, 4);
    grey.convertTo(edges, CvType.CV_32FC3, 1.0 / 255.0);


    //try to detect the edges
    pDollar.detectEdges(src, edges);


    //convert the edges to Mat
    Mat output = new Mat();
    edges.convertTo(output, CvType.CV_8UC1, 255.0);

    //convert Mat to bitmap to display it
    Bitmap resultBitmap = Bitmap.createBitmap(edges.cols(), edges.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(edges, resultBitmap);

    return resultBitmap;

The error that I'm getting :

Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.0-dev) /Users/Chao/opencv_contrib/modules/ximgproc/src/structured_edge_detection.cpp:529: error: (-215) _src.type() == (((5) & ((1 << 3) - 1)) + (((3)-1) << 3)) in function virtual void cv::ximgproc::StructuredEdgeDetectionImpl::detectEdges(cv::InputArray, cv::OutputArray) const

I checked the line 529 in structured_edge_detection.cpp (link) (link) as shown in the error and I saw this :

 * The function detects edges in src and draw them to dst
 *
 * \param _src : source image (RGB, float, in [0;1]) to detect edges
 * \param _dst : destination image (grayscale, float, in [0;1])
 *              where edges are drawn

And to my understanding that's what I did in the code snippet above. Any help is much appreciated.

StructuredEdgeDetection - detectEdges method - Android

Hi everyone,

I managed until now with help of the forum to install openCV with extra modules and to get a model for the StructuredEdgeDetection and to implement it correctly to android. My problem now is with method detectEdges which gives an error every time I try to execute it. Here is my code :

    //bitmap to detect it's edges
    Mat rgba = new Mat();
    Utils.bitmapToMat(bitmap, rgba);
    //same bitmap to to greyscale it
    Mat grey = new Mat();
    Utils.bitmapToMat(bitmap, grey);

    StructuredEdgeDetection pDollar = createStructuredEdgeDetection(DATA_PATH + "SEDmodel" + ".yml");

    //convert the source Mat object to float
    Mat src = new Mat();
    rgba.convertTo(src, CvType.CV_32FC3, 1.0 / 255.0);


    //convert the destination Mat to float
    Mat edges = new Mat(grey.size(), CvType.CV_8UC1);
    Imgproc.cvtColor(grey, edges, Imgproc.COLOR_RGB2GRAY, 4);
    grey.convertTo(edges, CvType.CV_32FC3, 1.0 / 255.0);


    //try to detect the edges
    pDollar.detectEdges(src, edges);


    //convert the edges to Mat
    Mat output = new Mat();
    edges.convertTo(output, CvType.CV_8UC1, 255.0);

    //convert Mat to bitmap to display it
    Bitmap resultBitmap = Bitmap.createBitmap(edges.cols(), edges.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(edges, resultBitmap);

    return resultBitmap;

The error that I'm getting :

Caused by: CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.0-dev) /Users/Chao/opencv_contrib/modules/ximgproc/src/structured_edge_detection.cpp:529: error: (-215) _src.type() == (((5) & ((1 << 3) - 1)) + (((3)-1) << 3)) in function virtual void cv::ximgproc::StructuredEdgeDetectionImpl::detectEdges(cv::InputArray, cv::OutputArray) const

I checked the line 529 in structured_edge_detection.cpp (link) as shown in the error and I saw this :

 * The function detects edges in src and draw them to dst
 *
 * \param _src : source image (RGB, float, in [0;1]) to detect edges
 * \param _dst : destination image (grayscale, float, in [0;1])
 *              where edges are drawn

And to my understanding that's what I did in the code snippet above. Any help is much appreciated.

EDIT :

With much help from @LBerger I managed to put this together and make it work :

    //bitmap to detect it's edges
    Mat rgba = new Mat();
    Utils.bitmapToMat(bitmap, rgba);

    //convert it to rgb
    Mat rgb = new Mat();
    Imgproc.cvtColor(rgba, rgb, Imgproc.COLOR_BGRA2BGR);


    //convert the source Mat object to float
    Mat src = new Mat();
    rgb.convertTo(src, CvType.CV_32F, 1.0 / 255.0);


    //give the destination Mat the same parameters as the destination Mat
    Mat edges = new Mat(src.size(), src.type());


    //try to detect the edges
    StructuredEdgeDetection pDollar = createStructuredEdgeDetection(DATA_PATH + "SEDmodel" + ".yml");
    pDollar.detectEdges(src, edges);

    //optional -- computes orientation from edge map
    Mat orientation_map = new Mat();
    pDollar.computeOrientation(edges, orientation_map);

    //optional -- suppress edges
    Mat edge_nms = new Mat();
    pDollar.edgesNms(edges, orientation_map, edge_nms, 2, 0, 2, true);

    //convert the edges to Mat
    edges.convertTo(edges, CvType.CV_8U, 255.0);


    //convert Mat to bitmap to display it
    Bitmap resultBitmap = Bitmap.createBitmap(edges.cols(), edges.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(edges, resultBitmap);

    return resultBitmap;