Ask Your Question

Unable to read model file in structurededgedetection

asked 2019-05-19 10:44:07 -0500

MYCL gravatar image

updated 2019-05-19 12:04:08 -0500

I've created the EdgeBoxes.cpp Example DLL for LabVIEW using OpenCV. I'm trying to open the model file in the DLL but all I get is an assertion fail. I also created VI's for morphology, Corner detection, hough transformation but never got any error messages like that.

I tried:

Every path combination using Forward slashes or back slashes. Putting every file into the same Folder(also in C:). (LabVIEW VI, DLL, ModelFile) To open it in LabVIEW first with "Open/Create/" To open the extracted model.yml file instead of model.yml.gz That's the point where I'm clueless:

string filename = "C:/model.yml.gz"
Ptr<StructuredEdgeDetection> pDollar; = createStructuredEdgeDetection(filename);

Error Message I'm receiving:

Error -1002 occurred at OpenCV(4.0.1-dev) C:\OpenCV\opencv_contrib-master\modules\ximgproc\src\structured_edge_detection.cpp:432: error: (-215:Assertion failed) modelFile.isOpened() in function 'cv::ximgproc::StructuredEdgeDetectionImpl::StructuredEdgeDetectionImpl'

I tried to read the file with ifstream and it seems like I can acess the file without any Problems (Code below). So the reason why it won't work seems to be in context with OpenCV?

std::ifstream is(filename, std::ifstream::binary);
is.seekg(0, is.end);
int length = is.tellg();
is.seekg(0, is.beg);

char * buffer = new char[length];, length);
delete[] buffer;    // buffer contains the entire file

Now I tried to open the file like OpenCV does after calling:

createStructuredEdgeDetection(filename); After that OpenCV tries to open the file with: See Row 431

cv::FileStorage modelFile(filename, FileStorage::READ)

Why does it work with


Do I have to recompile the "structured_edge_detection.cpp or cv::Filestorage with cmake?

Thanks for looking into this with me.

edit retag flag offensive close merge delete


string filename = "C:\model.yml.gz" -- in the end, it's a sillly path problem ? you either have to use / or \\

(-215:Assertion failed) modelFile.isOpened() -- believe it. it means what it says. there was nothing to open.

berak gravatar imageberak ( 2019-05-19 11:43:45 -0500 )edit

As I said I tried every path combination / or \ it didn‘t work. And still I don‘t get it why the path above works with ifstream :: binary option.

MYCL gravatar imageMYCL ( 2019-05-19 11:49:52 -0500 )edit

however, it's wrong in your question, so how would we know better ?

but the ' binary' hint is somewhat interesting !

berak gravatar imageberak ( 2019-05-19 11:54:28 -0500 )edit

1 answer

Sort by » oldest newest most voted

answered 2019-05-23 03:58:46 -0500

MYCL gravatar image

I solved my problem. All you need to do is to pay attention linking only the librarys with a "d" if you are using debug mode in Visual Studio. I was using both like:

opencv_imgproc401d.lib, opencv_imgproc401.lib, opencv.ximg....

After changing the additional linker dependencies only to the debug librarys


everything worked fine for me.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-05-19 10:44:07 -0500

Seen: 59 times

Last updated: May 23