Darknet-Yolo: java.lang.Exception: unknown exception (org.opencv.dnn.Net.forward_4)
In OpenCV-Yolo
I use the following function to use the (.cfg) and (.weights) file for object detection in Java
net = Dnn.readNetFromDarknet(cfg, weights);
float scale = 1.0F / 255.0F;
Mat inputBlob = Dnn.blobFromImage(resized, scale, sz, new Scalar(0), false, false);
net.setInput(inputBlob, "data");
System.out.println("Detect Classes: " + classes_names.length);
java.util.List<Mat> result = new java.util.ArrayList<Mat>(2);
java.util.List<java.lang.String> outBlobNames = new java.util.ArrayList<java.lang.String>(2);
outBlobNames.add(0, "yolo_16");
outBlobNames.add(1, "yolo_23");
net.forward(result, outBlobNames);
Mat result_1 = result.get(0);
Mat result_2 = result.get(1);
for (Mat mat : result) {
ExtractBeanFromMat(mat, im, frame, im_copy);
}
The following is the exception log:
Detect Classes: 2
java.lang.Exception: unknown exception
at org.opencv.dnn.Net.forward_4(Native Method)
at org.opencv.dnn.Net.forward(Net.java:333)
at InheritClass.ObjectDetectionHelper.detect(ObjectDetectionHelper.java:134)
at DetectionCar.DetectCar.detect(DetectCar.java:26)
at InheritClass.ObjectDetectionHelper.detect(ObjectDetectionHelper.java:94)
at InheritClass.ObjectDetectionHelper.detect_directory(ObjectDetectionHelper.java:227)
at DetectionCar.DetectCar.main(DetectCar.java:31)