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

Asked by Paul Chambre on 2018-11-21

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(
        at org.sikuli.script.Finder2.doFindMatch(
        at org.sikuli.script.Finder2.doFind(
        at org.sikuli.script.Finder2.find(
        at org.sikuli.script.Finder.find(
        at org.sikuli.script.Region.runFinder(
        at org.sikuli.script.Region.doFind(
        at org.sikuli.script.Region.access$300(
        at org.sikuli.script.Region$
        at org.sikuli.script.Region$Repeatable.repeat(
        at org.sikuli.script.Region.exists(
        at com.illumon.guitest.IrisGuiTestFramework.multiPatternExists(
        at com.illumon.guitest.IrisGuiTestFramework.multiPatternExistsExact(
        at com.illumon.guitest.TestIrisGui.doChartTest(
        at com.illumon.guitest.TestIrisGui.main(

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?


Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Last query:
Last reply:
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.

RaiMan (raimund-hocke) said : #2

It looks like you are using your own OpenCV libs?

Can you tell me more about your setup?

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.

RaiMan (raimund-hocke) said : #4

--- I am not using my own OpenCV libraries
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.