Java OpenCV SIGSEGV JVM 崩溃

问题描述 投票:0回答:0

我正在开发一个从视频中获取帧然后将其分成 4 个部分的应用程序。然后将这 4 个部分进一步拆分。这一切都发生在几个线程上。一旦它有视频部分的有用部分,它就会通知观察者该文件已准备好被检测到。一切正常,但在向检测器提交了这么多次之后,它开始使 JVM 崩溃。我完全不知道如何解决这个问题。

我基本上是循环遍历每一帧并进行处理,然后调用它以将其提交给检测器:

detector.addFrame(gameWindow1DecisionFrameData);

这是我的探测器:

public class Detection {
    private Mat img;
    private int ID;
    private int networkWidth;
    private int networkHeight;
    private String weightsPath;
    private String modelPath;
    private float minThresh;
    
    public Detection(Mat img, int ID, int networkWidth,int networkHeight, String weightsPath, String modelPath, float minThresh){
        this.img = img;
        this.ID = ID;
        this.networkWidth = networkWidth;
        this.networkHeight = networkHeight;
        this.weightsPath = weightsPath;
        this.modelPath = modelPath;
        this.minThresh = minThresh;
    }
    
    public String Run() throws Exception{
        Net net = Dnn.readNetFromDarknet(modelPath, weightsPath);
        Size sz = new Size(networkWidth, networkHeight);
        Mat blob = Dnn.blobFromImage(img, 0.00392, sz, new Scalar(0), true, false);
        net.setInput(blob);

        List<Mat> result = new ArrayList<>();
        List<String> outBlobNames = getOutputNames(net);      

        net.forward(result, outBlobNames);
        
        
        float confThreshold = minThresh;
        List<Integer> clsIds = new ArrayList<>();
        List<Float> confs = new ArrayList<>();
        List<Rect2d> rects = new ArrayList<>();
        
        for (int i = 0; i < result.size(); ++i)
        {
            // each row is a candidate detection, the 1st 4 numbers are
            // [center_x, center_y, width, height], followed by (N-4) class probabilities
            Mat level = result.get(i);
            for (int j = 0; j < level.rows(); ++j)
            {
                Mat row = level.row(j);
                Mat scores = row.colRange(5, level.cols());
                
                Core.MinMaxLocResult mm = Core.minMaxLoc(scores);
                
                float confidence = (float)mm.maxVal;
                Point classIdPoint = mm.maxLoc;
                if (confidence > confThreshold)
                {
                    int centerX = (int)(row.get(0,0)[0] * img.cols());
                    int centerY = (int)(row.get(0,1)[0] * img.rows());
                    int width   = (int)(row.get(0,2)[0] * img.cols());
                    int height  = (int)(row.get(0,3)[0] * img.rows());
                    int left    = centerX - width  / 2;
                    int top     = centerY - height / 2;

                    clsIds.add((int)classIdPoint.x);
                    confs.add((float)confidence);
                    rects.add(new Rect2d(left,top,width,height));
                }
                
                row.release();
                scores.release();
            }
        }
        // Apply non-maximum suppression procedure.
        float nmsThresh = .50f;
        
        MatOfFloat confidences = new MatOfFloat(Converters.vector_float_to_Mat(confs));
        Rect2d[] boxesArray = rects.toArray(new Rect2d[0]);
        MatOfRect2d bbox = new MatOfRect2d();
        bbox.fromList(rects);
        MatOfInt indices = new MatOfInt();
        Dnn.NMSBoxes(bbox, confidences, confThreshold, nmsThresh, indices);

         
        // Grab Results
        int tempID = -1;
        int [] ind = indices.toArray();  
        float confy = 0;
        int classID = -1;
        for (int i = 0; i < ind.length; ++i)
        {
            int idx = ind[i];
            Rect2d box = boxesArray[idx];
            Imgproc.rectangle(img, box.tl(), box.br(), new Scalar(0,0,255), 2);
            classID = clsIds.get(idx);
            Float confidence = confs.get(idx);
            System.out.println(clsIds.get(idx) + " CONFIDENCE: " + confidence);
            confy = confidence;
        }
        
        
        
        return classID + "," + confy;
    
    }
    
    
     private List<String> getOutputNames(Net net) {
        List<String> names = new ArrayList<>();

        List<Integer> outLayers = net.getUnconnectedOutLayers().toList();
        List<String> layersNames = net.getLayerNames();

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

检测器每 100 毫秒调用一次:

private void submitDetection(FrameData frame){
        if (frame.getObject() == null)
        {
            return;
        }
        
        switch(frame.getObjectID())
        {
            case -10://Decision
                System.out.println("Submitting Decision 1 for Detection");
                detectDescision(frame, .80f);
                break;
            
            case 0://Other section of screen to detect
               
                break;
        }
    }

这叫:

public void detectDescision(FrameData data, float weight){
        String result = "";
                try
                {
                    Mat test = new BuildImage(data.getObject(), data.getID(),data.getID(), 640, 128).Build().getObject();
                    Detection detector = new Detection(test,0,640,128,"/home/user/nn/UI/UI_best.weights","/home/user/nn/UI/UI.cfg",weight);
                    result = detector.Run();
                    detector = null;
                if (!result.isEmpty())
                {
                    String[] vals = result.split(",");
                   
                    System.out.println(vals[0] + " " + vals[1]);
                    
                    
                }
                }
                catch (Exception e)
                {
                    //Logger.getLogger(CardDetector.class.getName()).log(Level.SEVERE, null, e);
                }
        
        
    }

视频以 30fps 的速度播放,并在新帧准备就绪时更新 observable。它会这样做,直到视频中没有更多帧为止。如果我注释掉

detectDescision(frame, .80f);
就不会崩溃。

崩溃日志:

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000242ff4005, pid=89045, tid=0x00007f9a203ad640
#
# JRE version: OpenJDK Runtime Environment (8.0_362-b09) (build 1.8.0_362-8u362-ga-0ubuntu1~22.04-b09)
# Java VM: OpenJDK 64-Bit Server VM (25.362-b09 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  0x0000000242ff4005
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x00007f9a94253000):  JavaThread "Timer-0" [_thread_in_native, id=89107, stack(0x00007f9a202ae000,0x00007f9a203ae000)]

siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000242ff4005

Registers:
RAX=0x00007f9812e130e0, RBX=0x00007f97e6e76ca8, RCX=0x0000000000000000, RDX=0x0000000000000000
RSP=0x00007f9a203ac198, RBP=0x00007f97cce7eff0, RSI=0x0000000000000003, RDI=0x00007f97a0d922f0
R8 =0x00007f97e6e76e70, R9 =0x0000000000000000, R10=0x0000000000000000, R11=0x0000000000000000
R12=0x00007f97e6e76c80, R13=0x00007f97e6e75220, R14=0x0000000000000000, R15=0x00007f97cce7efb0
RIP=0x0000000242ff4005, EFLAGS=0x0000000000010246, CSGSFS=0x002b000000000033, ERR=0x0000000000000014
  TRAPNO=0x000000000000000e

Top of Stack: (sp=0x00007f9a203ac198)
0x00007f9a203ac198:   00007f9a3187b0d5 00007f97cce7efb0
0x00007f9a203ac1a8:   00007f9a203ac290 00007f97a0d922f0
0x00007f9a203ac1b8:   00007f9812e0e410 00007f9a203ac250
0x00007f9a203ac1c8:   00007f9a203ac200 0000000000000000
0x00007f9a203ac1d8:   0000300623dadb66 00007f97e6e77880
0x00007f9a203ac1e8:   00007f97e6e77888 00007f9812e11cf0
0x00007f9a203ac1f8:   00007f9a319320f1 0000000000000000
0x00007f9a203ac208:   00007f9a00000000 00007f9a0000000e
0x00007f9a203ac218:   0000000679ef3da8 0000000000000000
0x00007f9a203ac228:   0000000000000000 00007f9a94253000
0x00007f9a203ac238:   00007f9a94253850 00007f9a94253890
0x00007f9a203ac248:   a579defb74072e00 00007f97e6e812d0
0x00007f9a203ac258:   00007f97e6e81330 00007f97e6e81330
0x00007f9a203ac268:   00007f9a9a2ae9cc 00007f9901050000
0x00007f9a203ac278:   00007f9a203ac250 0000000000000000
0x00007f9a203ac288:   00007f9a203ac380 00007f9702050000
0x00007f9a203ac298:   00007f97e6e75af0 0000000000000000
0x00007f9a203ac2a8:   00007f9812e11cf0 00007f9a02050000
0x00007f9a203ac2b8:   00007f97e6e75b20 0000000000000000
0x00007f9a203ac2c8:   00007f9a31881071 0000000000000000
0x00007f9a203ac2d8:   00007f9a00000000 000000000000000c
0x00007f9a203ac2e8:   00007f995c000e58 00007f9a94253000
0x00007f9a203ac2f8:   a579defb74072e00 00007f9a203ac3d0
0x00007f9a203ac308:   a579defb74072e00 00007f9a203ac340
0x00007f9a203ac318:   ffffffffffffff80 0000000000000002
0x00007f9a203ac328:   00007f97e6e76520 00007f9a203ac420
0x00007f9a203ac338:   00007f97e6e76528 00007f97e6e77480
0x00007f9a203ac348:   00007f9a9b6a54d3 0000000000000010
0x00007f9a203ac358:   00007f97e6e76528 00007f97e6e76520
0x00007f9a203ac368:   00007f97e6e77490 00007f97e6e76528
0x00007f9a203ac378:   00007f9a3188491b 00007f97e6e77480
0x00007f9a203ac388:   00007f97e6e77490 0000000000000000 

Instructions: (pc=0x0000000242ff4005)
0x0000000242ff3fe5:   
[error occurred during error reporting (printing registers, top of stack, instructions near pc), id 0xb]

Register to memory mapping:

RAX=0x00007f9812e130e0 is an unknown value
RBX=0x00007f97e6e76ca8 is an unknown value
RCX=0x0000000000000000 is an unknown value
RDX=0x0000000000000000 is an unknown value
RSP=0x00007f9a203ac198 is pointing into the stack for thread: 0x00007f9a94253000
RBP=0x00007f97cce7eff0 is an unknown value
RSI=0x0000000000000003 is an unknown value
RDI=0x00007f97a0d922f0 is an unknown value
R8 =0x00007f97e6e76e70 is an unknown value
R9 =0x0000000000000000 is an unknown value
R10=0x0000000000000000 is an unknown value
R11=0x0000000000000000 is an unknown value
R12=0x00007f97e6e76c80 is an unknown value
R13=0x00007f97e6e75220 is an unknown value
R14=0x0000000000000000 is an unknown value
R15=0x00007f97cce7efb0 is an unknown value


Stack: [0x00007f9a202ae000,0x00007f9a203ae000],  sp=0x00007f9a203ac198,  free space=1016k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  0x0000000242ff4005

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
J 1707  org.opencv.dnn.Net.forward_4(JJLjava/util/List;)V (0 bytes) @ 0x00007f9a85879c98 [0x00007f9a85879c40+0x58]
J 1755 C1 org.opencv.dnn.Net.forward(Ljava/util/List;Ljava/util/List;)V (30 bytes) @ 0x00007f9a85890a5c [0x00007f9a858908c0+0x19c]
J 1618 C2 watcher.ai.Detection.Run()Ljava/lang/String; (633 bytes) @ 0x00007f9a858270a0 [0x00007f9a85826e40+0x260]
J 1788 C2 watcher.observers.DetectionSubmission.update(Ljava/lang/Object;)V (18 bytes) @ 0x00007f9a858ce57c [0x00007f9a858ccf00+0x167c]
J 1886 C2 watcher.subjects.DetectSub.Notify()V (41 bytes) @ 0x00007f9a85935ef8 [0x00007f9a85935e00+0xf8]
J 1687 C1 watcher.helpers.Manager$1.run()V (19 bytes) @ 0x00007f9a8586970c [0x00007f9a85869600+0x10c]
j  java.util.TimerThread.mainLoop()V+221
j  java.util.TimerThread.run()V+1
v  ~StubRoutines::call_stub

任何帮助将不胜感激

我已经试过这个:

To debug, run 'gdb /proc/19661/exe 19661'; then switch to thread 140706361476672 (0x00007ff8c0b18640)

这导致:

sudo gdb /proc/19661/exe 19661
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /proc/19661/exe...
(No debugging symbols found in /proc/19661/exe)
Attaching to program: /proc/19661/exe, process 19661
[New LWP 19665]
[New LWP 19666]
[New LWP 19667]
[New LWP 19668]
[New LWP 19669]
[New LWP 19670]
[New LWP 19671]
[New LWP 19672]
[New LWP 19673]
[New LWP 19674]
[New LWP 19675]
[New LWP 19676]
[New LWP 19677]
[New LWP 19678]
[New LWP 19679]
[New LWP 19680]
[New LWP 19681]
[New LWP 19682]
[New LWP 19683]
[New LWP 19684]
[New LWP 19685]
[New LWP 19686]
[New LWP 19687]
[New LWP 19688]
[New LWP 19689]
[New LWP 19690]
[New LWP 19691]
[New LWP 19692]
[New LWP 19693]
[New LWP 19694]
[New LWP 19695]
[New LWP 19696]
[New LWP 19697]
[New LWP 19698]
[New LWP 19699]
[New LWP 19700]
[New LWP 19701]
[New LWP 19702]
[New LWP 19703]
[New LWP 19704]
[New LWP 19705]
[New LWP 19706]
[New LWP 19707]
[New LWP 19708]
[New LWP 19709]
[New LWP 19710]
[New LWP 19711]
[New LWP 19712]
[New LWP 19713]
[New LWP 19714]
[New LWP 19715]
[New LWP 19716]
[New LWP 19717]
[New LWP 19718]
[New LWP 19719]
[New LWP 19720]
[New LWP 19721]
[New LWP 19722]
[New LWP 19723]
[New LWP 19724]
[New LWP 19725]
[New LWP 19726]
[New LWP 19727]
[New LWP 19728]
[New LWP 19729]
[New LWP 19730]
[New LWP 19731]
[New LWP 19732]
[New LWP 19733]
[New LWP 19734]
[New LWP 19735]
[New LWP 19736]
[New LWP 19737]
[New LWP 19738]
[New LWP 19739]
[New LWP 19740]
[New LWP 19741]
[New LWP 19742]
[New LWP 19743]
[New LWP 19744]
[New LWP 19745]
[New LWP 19746]
[New LWP 19747]
[New LWP 19748]
[New LWP 19749]
[New LWP 19750]
[New LWP 19751]
[New LWP 19752]
[New LWP 19753]
[New LWP 19754]
[New LWP 19755]
[New LWP 19756]
[New LWP 19757]
[New LWP 19760]
[New LWP 19761]
[New LWP 19762]
[New LWP 19763]
[New LWP 19764]
[New LWP 19765]
[New LWP 19766]
[New LWP 19767]
[New LWP 19768]
[New LWP 19769]
[New LWP 19770]
[New LWP 19771]
[New LWP 19772]
[New LWP 19773]
[New LWP 19774]
[New LWP 19775]
[New LWP 19776]
[New LWP 19777]
[New LWP 19778]
[New LWP 19779]
[New LWP 19780]
[New LWP 19781]
[New LWP 19782]
[New LWP 19783]
[New LWP 19784]
[New LWP 19785]
[New LWP 19786]
[New LWP 19787]
[New LWP 19788]
[New LWP 19789]
[New LWP 19790]
[New LWP 19791]
[New LWP 19792]
[New LWP 19793]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
__futex_abstimed_wait_common64 (private=128, cancel=true, abstime=0x0, op=265, expected=19665, futex_word=0x7ff8c0b18910) at ./nptl/futex-internal.c:57
57  ./nptl/futex-internal.c: No such file or directory.
--Type <RET> for more, q to quit, c to continue without paging--
Installing openjdk unwinder
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so-gdb.py", line 52, in <module>
    class Types(object):
  File "/usr/share/gdb/auto-load/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server/libjvm.so-gdb.py", line 66, in Types
    nmethodp_t = gdb.lookup_type('nmethod').pointer()
gdb.error: No type named nmethod.
(gdb) 
opencv java-8 crash javacv
© www.soinside.com 2019 - 2024. All rights reserved.