<p dir="auto">Im working on simple image classifier in Java. I`m using OpenCv 3.4.3 and JDK 1.8_192 and i encountered problem with JNI.</p>
<p dir="auto">When i execute this code</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class Main  {

    private static List&lt;String&gt; getOutputNames(Net net) {
        List&lt;String&gt; names = new ArrayList&lt;&gt;();

        List&lt;Integer&gt; outLayers = net.getUnconnectedOutLayers().toList();
        List&lt;String&gt; layersNames = net.getLayerNames();

        outLayers.forEach((item) -&gt; names.add(layersNames.get(item - 1)));
        return names;
    }

    public static void main(String[] args) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        
        String modelWeights = &quot;yolov3.weights&quot;;
        String modelConfiguration = &quot;yolov3.cfg&quot;;

        Net net = Dnn.readNetFromDarknet(modelConfiguration, modelWeights);

        Imgcodecs imageCodecs = new Imgcodecs();
        Mat image = imageCodecs.imread(&quot;test.jpg&quot;);

        Mat blob = Dnn.blobFromImage(image, 1.0, new Size(416, 416), new Scalar(0), false, false);
        net.setInput(blob);

        List&lt;Mat&gt; result = new ArrayList&lt;&gt;();
        List&lt;String&gt; outBlobNames = getOutputNames(net);

        net.forward(result, outBlobNames);
    }
}"><pre class="notranslate"><code class="notranslate">public class Main  {

    private static List&lt;String&gt; getOutputNames(Net net) {
        List&lt;String&gt; names = new ArrayList&lt;&gt;();

        List&lt;Integer&gt; outLayers = net.getUnconnectedOutLayers().toList();
        List&lt;String&gt; layersNames = net.getLayerNames();

        outLayers.forEach((item) -&gt; names.add(layersNames.get(item - 1)));
        return names;
    }

    public static void main(String[] args) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        
        String modelWeights = "yolov3.weights";
        String modelConfiguration = "yolov3.cfg";

        Net net = Dnn.readNetFromDarknet(modelConfiguration, modelWeights);

        Imgcodecs imageCodecs = new Imgcodecs();
        Mat image = imageCodecs.imread("test.jpg");

        Mat blob = Dnn.blobFromImage(image, 1.0, new Size(416, 416), new Scalar(0), false, false);
        net.setInput(blob);

        List&lt;Mat&gt; result = new ArrayList&lt;&gt;();
        List&lt;String&gt; outBlobNames = getOutputNames(net);

        net.forward(result, outBlobNames);
    }
}
</code></pre></div>
<p dir="auto">I get following error</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fe9cf215716, pid=12403, tid=0x00007fe9d075c700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_192-b12) (build 1.8.0_192-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.192-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x6ce716]  jni_CallObjectMethodV+0x76
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try &quot;ulimit -c unlimited&quot; before starting Java again
#
# An error report file with more information is saved as:
# /home/mateusz/detector/hs_err_pid12403.log
Compiled method (c1)     296   18       1       java.util.ArrayList::size (5 bytes)
 total in heap  [0x00007fe9b910ec50,0x00007fe9b910eee0] = 656
 relocation     [0x00007fe9b910ed78,0x00007fe9b910eda0] = 40
 main code      [0x00007fe9b910eda0,0x00007fe9b910ee20] = 128
 stub code      [0x00007fe9b910ee20,0x00007fe9b910eeb0] = 144
 scopes data    [0x00007fe9b910eeb0,0x00007fe9b910eeb8] = 8
 scopes pcs     [0x00007fe9b910eeb8,0x00007fe9b910eed8] = 32
 dependencies   [0x00007fe9b910eed8,0x00007fe9b910eee0] = 8
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#"><pre class="notranslate"><code class="notranslate">#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fe9cf215716, pid=12403, tid=0x00007fe9d075c700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_192-b12) (build 1.8.0_192-b12)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.192-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x6ce716]  jni_CallObjectMethodV+0x76
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/mateusz/detector/hs_err_pid12403.log
Compiled method (c1)     296   18       1       java.util.ArrayList::size (5 bytes)
 total in heap  [0x00007fe9b910ec50,0x00007fe9b910eee0] = 656
 relocation     [0x00007fe9b910ed78,0x00007fe9b910eda0] = 40
 main code      [0x00007fe9b910eda0,0x00007fe9b910ee20] = 128
 stub code      [0x00007fe9b910ee20,0x00007fe9b910eeb0] = 144
 scopes data    [0x00007fe9b910eeb0,0x00007fe9b910eeb8] = 8
 scopes pcs     [0x00007fe9b910eeb8,0x00007fe9b910eed8] = 32
 dependencies   [0x00007fe9b910eed8,0x00007fe9b910eee0] = 8
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#
</code></pre></div>
<p dir="auto">Im using <a href="https://pjreddie.com/media/files/yolov3.weights" rel="nofollow">yolov3.weights</a> and <a href="https://github.com/pjreddie/darknet/blob/master/cfg/yolov3.cfg">yolov3.cfg</a>.</p>
<p dir="auto">Error occurs only when last line of code is executed.</p>
<p dir="auto">EDIT:<br>
It is written under Ubuntu 18.04, problem also occurs on 16.04, but everything works fine on Windows 10.</p>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji></li>
<li>Operating System / Platform =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji></li>
<li>Compiler =&gt; ❔</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<h5 dir="auto">Steps to reproduce</h5>