问题
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
回答1:
I solved this problem by making a copy of the model from the asset folder to the phone storage and reading it from there.
来源:https://stackoverflow.com/questions/49734695/structured-edge-detection