0

I'm trying to implement SED from OpenCV to android but I'm running into an error. So this is the code I'm using and it requires a model file (trained model to detect edges) which is located in the asset folder :

    private Bitmap StructuredDetectEdges (Bitmap bitmap){
    Mat rgba = new Mat();
    Utils.bitmapToMat(bitmap,rgba);
    Mat edges = new Mat(rgba.size(), CvType.CV_8UC1);
    Imgproc.cvtColor(rgba,edges,Imgproc.COLOR_RGB2GRAY,4);
    StructuredEdgeDetection pDollar = createStructuredEdgeDetection("file:///android_asset/SEDmodel.yml");
    pDollar.detectEdges(edges,edges);
    Bitmap resultBitmap = Bitmap.createBitmap(edges.cols(), edges.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(edges, resultBitmap);
    return resultBitmap;

}

and the error that I get is :

Error: Assertion failed (modelFile.isOpened()) in cv::ximgproc::StructuredEdgeDetectionImpl::StructuredEdgeDetectionImpl(const cv::String&, cv::Ptr<const cv::ximgproc::RFFeatureGetter>), file /Users/Chao/opencv_contrib/modules/ximgproc/src/structured_edge_detection.cpp, line 432

any help is much appreciated

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user 007
  • 821
  • 10
  • 31

1 Answers1

0

I solved this problem by making a copy of the model from the asset folder to the phone storage and reading it from there.

user 007
  • 821
  • 10
  • 31
  • the reason this works is that android assets are kept compressed and AssetManager just reads directly from that zip, anything that doesn't use an InputStream to read from it won't work – Zharf Apr 10 '18 at 13:09