How can I resolve a crash with opencv::FindContour()?

Hi There.

I’m working on a project with opencv 2.4.9.

I linked the library and all the functions work fine exept for cv::FindContour().
The exeption thrown is “Access violation writing location 0x00000010”.
Threads related to this problems exist and suggest raising the stack size.
However I can’t seem to be able to do this on EU4 projects.

Any idea ? does anyone tried to do this ?

link text here is the source code of my class :

Same problem here :-S

Any help or update would be very appreciated
Best regards

The same with UE 4.8.3 and OpenCV 2.4. Crash in FMallocTBB::free after [external code].
cv::cvtColor and cv::imshow works but cv::FindContours does not.

I have found one way. I moved my code with cv::findContours to different project and compiled my own DLL. Then I’ve linked it in UE4 like opencv and it works.

P.S.: I guess the problem in the vector of vector of Point param and other like it. Garbage Collector from UE4 destroys them (not confirmed).

1 Like

Yep, I’ve implemented the same solution and it worked for me too.

Looks like Unreal reflection system doesn’t know how to free a vector which has been filled inside an openCV method. In this case FindCountours.

Anyways I was looking for another solution because current one makes us precompile a library for each system/platform we need to use and when developing it becomes a bit annoying to compile the *.dll, copy-paste dll, lib and new *.h into corresponding directories (source and binary folders). I know I could create a building routine to make all the stuff in one execution, but I’ve been a little lazy about this and I kept on looking for more possible solutions.

Anybody knows how to tell unreal’s reflection system to “ignore” some portion of code?
Thanks for the update and if I can find another solution I’ll post here as well :slight_smile:
Best regards,

Hi,
I have the same problem now and i try to bulid my own dll like this: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums
But I have a problem with if (DLLHandle != NULL), because the DLLHandle stay free and my function coms from dll doesn’t work.
Can you upload your code or share any solutions for me?

Hi evryone. I’m creating a world which uses OpenCV. I’m not sure, but i feel that i found a reason of this issue. All because of unreal’s Paper2D plugin’s function, there you can check it: https://docs.unrealengine.com/latest/INT/API/Plugins/Paper2D/UPaperSprite/FindContours/index.html

Thanks . I would add to your answer that I had to compile my DLL with “/MT” to make it work (/MD makes it crash as before)

Hey , i have the same problem here but don’t know what you exactly mean with “compiled my own DLL.” Can you explain it in more detail? Thank you and many greetings from Germany

I have a couple of examples: markers-detector/source at master · rnixik/markers-detector · GitHub and face-recognition-ue4/source at master · rnixik/face-recognition-ue4 · GitHub You build separate DLL and use it in your UE-project. Wiki: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums and A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

I know I’m kind of reviving a dead thread, but I tried putting this into an external dll and I’m still getting the same issues. Do you remember what version of OpenCV you used?

Hi,

Lightact media server allows you to use OpenCV with UE4. Have a look at this tutorial here, if you are interested.

DISCLAIMER: I am the founder of Lightact.

I am afraid there is no other solution at this moment. The garbage collector is still failing to release memory reserved from third-party libraries and, as far as I know, there is no way to tell the GC to ignore a portion or some of your variables giving you the full responsibility for releasing them properly… :frowning:
If you find a way, please, do not hesitate in answering again this “dead” thread xDD

Reviving a dead thread, but have you been able to fix this issue without compiling your own DLL ? For many reasons, I would rather not do that either.
But I’m still having the vector> issue with UE4.21 GC…

I didn’t find a solution yet… I was forced to learn how to build a .dll, a .lib and also how to do an Android .so library on my own… Now I have a library which is using OpenCV, cv::findContours on its own, and I’m calling it from an Unreal plugin. What a mess.

Hello sorry to bother you all guys by reviving this old thread but I got the same issue that people seems to have on this thread and I still havn’t be able to solve it. Could someone explain me how you solved the problem ?

Hello, sorry to revive this thread again, but I’ve encountered the same problem and I don’t understand which solution your talking about. How did you solve the problem ? Thank you by advance

That’s a great solution. Actually, besides cv::function, once there are some functions not supported by UE platform, e.g. std::vector related functions, we can always compile our own DLL as a third-party plugin to solve this problem.