(-215:Assertion failed) m.dims >= 2 in function 'cv::Mat::Mat'
Hi
I am trying to load a tin - yolo v3 model into java and do someobject recognition on video streams the following code i wrote with help of this post seems to open files and start image recognition as expected at the very beggining however i get this error after some frames have been analysed
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.0.0-alpha) C:\build\master_winpack-bindings-win64-vc14-static\opencv\modules\core\src\matrix.cpp:405: error: (-215:Assertion failed) m.dims >= 2 in function 'cv::Mat::Mat' ] at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.<init>(Mat.java:113) at org.opencv.core.MatOfFloat.<init>(MatOfFloat.java:27) at sample.yolo.main(yolo.java:112)
What might be happening here ? can anyone please help me out?
Here is the code i am trying to run :
package sample;
import org.opencv.core.*;
import org.opencv.dnn.*;
import org.opencv.utils.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import org.opencv.videoio.VideoCapture;
import java.util.ArrayList;
import java.util.List;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class yolo {
private static 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;
}
public static void main(String[] args) throws InterruptedException {
System.load("C:\\Users\\subhatta\\Downloads\\opencv\\build\\java\\x64\\opencv_java400.dll");
String modelWeights = "D:\\yolov3-tiny.weights";
String modelConfiguration = "D:\\yolov3-tiny.cfg.txt";
String filePath = "D:\\test.avi";
VideoCapture cap = new VideoCapture(filePath);
Mat frame = new Mat();
//cap.read(frame);
JFrame jframe = new JFrame("Video");
JLabel vidpanel = new JLabel();
jframe.setContentPane(vidpanel);
jframe.setSize(600, 600);
jframe.setVisible(true);
Net net = Dnn.readNetFromDarknet(modelConfiguration, modelWeights);
//Thread.sleep(5000);
//Mat image = Imgcodecs.imread("D:\\yolo-object-detection\\yolo-object-detection\\images\\soccer.jpg");
Size sz = new Size(416, 416);
while (true) {
if (cap.read(frame)) {
Mat blob = Dnn.blobFromImage(frame, 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);
outBlobNames.forEach(System.out::println);
result.forEach(System.out::println);
float confThreshold = 0.6f;
List<Integer> clsIds = new ArrayList<>();
List<Float> confs = new ArrayList<>();
List<Rect> 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 ...