OpenCV exception can't be caught (out of memory) and kills JVM

Asked by Paul Chambre

Using the 1.1.3 or 1.1.4 API jar, I intermittently get exceptions like this:

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.2) C:\build\3_4_winpack-bindings-win64-vc14-static\opencv\modules\core\src\matrix.cpp:367: error: (-215:Assertion failed) u != 0 in function 'cv::Mat::create'
]
        at org.opencv.imgproc.Imgproc.matchTemplate_1(Native Method)
        at org.opencv.imgproc.Imgproc.matchTemplate(Imgproc.java:2612)
        at org.sikuli.script.Finder2.doFindMatch(Finder2.java:357)
        at org.sikuli.script.Finder2.doFind(Finder2.java:327)
        at org.sikuli.script.Finder2.find(Finder2.java:79)
        at org.sikuli.script.Finder.find(Finder.java:244)
        at org.sikuli.script.Region.runFinder(Region.java:2861)
        at org.sikuli.script.Region.doFind(Region.java:2817)
        at org.sikuli.script.Region.access$300(Region.java:21)
        at org.sikuli.script.Region$RepeatableFind.run(Region.java:3075)
        at org.sikuli.script.Region$Repeatable.repeat(Region.java:3028)
        at org.sikuli.script.Region.exists(Region.java:2378)
        at com.illumon.guitest.IrisGuiTestFramework.multiPatternExists(IrisGuiTestFramework.java:68)
        at com.illumon.guitest.IrisGuiTestFramework.multiPatternExistsExact(IrisGuiTestFramework.java:51)
        at com.illumon.guitest.TestIrisGui.doChartTest(TestIrisGui.java:179)
        at com.illumon.guitest.TestIrisGui.run(TestIrisGui.java:148)
        at com.illumon.guitest.TestIrisGui.main(TestIrisGui.java:372)

Line 179 of TestIrisGui is in the midst of a try/catch(Exception) block, but it does not catch this exception, and, in fact, the whole process tree may get killed when this occurs.

Any ideas?

Thanks,
Paul

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

according to my research in the net, this problem occurs, if internally OpenCV cannot allocate enough memory (so in fact it is an out of memory problem).

possible reasons:
- system memory to small (not enough available for SikuliX)
- images too big (search on whole screen with large monitors)

I will check, wether this exception can be catched internally.

Looks like Java programming: in IDE's (Eclipse, IDEA, ...) you can track the memory consumption.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

It looks like you are using your own OpenCV libs?

Can you tell me more about your setup?

Revision history for this message
Paul Chambre (pchambredh) said :
#3

This setup is a Windows 10 VM running under VirtualBox on OSX.

I am not using my own OpenCV libraries. I am using whatever is built into the 1.1.3 and 1.1.4 SikuliX API SNAPSHOT jars. I have certainly seen this problem with 1.1.3. I don't remember whether I've seen it since switching to 1.1.4.

1.1.4 required me to add a few other jars for runtime support (TigerVNC and bridj) that seemed to have been built-in to the 1.1.3 jar.

The problem seemed to happen more often after the system had been running for a while.... (maybe resource limitations / memory leak causing issues), but looking at Task Manager did not show any obvious shortages of memory or CPU. A reboot did make it go away for a while, though.

Revision history for this message
RaiMan (raimund-hocke) said :
#4

--- I am not using my own OpenCV libraries
C:\build\3_4_winpack-bindings-win64-vc14-static\opencv\modules\core\src\matrix.cpp
where the exception happened is surely not the OpenCV bundled with 1.1.3 nor 1.1.4

--- 1.1.4 required me to add a few other jars for runtime support (TigerVNC and bridj)
then you neither use the sikulixapi.jar (complete with all deps and libs) nor are you running a Maven project with a dep to sikulixapi.

Before doing anything else, you should revise your SikuliX setup according to the docs.

Can you help with this problem?

Provide an answer of your own, or ask Paul Chambre for more information if necessary.

To post a message you must log in.