Я получаю следующую ошибку в методе blobFromImage:
Исключение в потоке "main" CvException [org.opencv.core.CvException: cv :: Exception: OpenCV (4.0.0) C: \ build \ master_winpack-bindings-win64-vc14-static \ opencv \ modules \ dnn \ src \ dnn. cpp: 134: ошибка: (-2: неопределенная ошибка) в функции 'void __cdecl cv :: dnn: : dnn4_v20180917 :: blobFromImages (константный класс cv :: _ InputArray &, константный класс cv :: OutputArray &, double, класс cv :: Size , константный класс cv :: Scalar_ &, bool, bool, int) '
Глубина блоба должна быть CV_32F или CV_8U:' ddepth == CV_32F || ddepth == CV_8U ', где' ddepth '- 187104008 (CV_8UC354)], когда я попытался преобразовать цвет в BGR / RGB с помощью cvtColor, я получил ошибку, поскольку
cvtcolr не поддерживается для объектов mat mat
Мой код указан ниже:
public static void main(String[] args) throws InterruptedException { System.load("C:/Sanjeev/softwares/OpenCV/opencv400/opencv/build/java/x64/opencv_java400.dll"); // Load the openCV 4.0 dll // String modelWeights = "C:/Users/sanjeevk/Desktop/solrTest/HandleVideo/yolov3.weights"; //Download and load only wights for YOLO , this is obtained from official YOLO site// String modelConfiguration = "C:/Users/sanjeevk/Desktop/solrTest/HandleVideo/yolov3.cfg.txt";//Download and load cfg file for YOLO , can be obtained from official site// String filePath = "C:/Users/sanjeevk/Desktop/solrTest/HandleVideo/23.mp4"; //My video file to be analysed// VideoCapture cap = new VideoCapture(filePath);// Load video using the videocapture method// cap.set(Videoio.CAP_PROP_FRAME_WIDTH, 288); // width cap.set(Videoio.CAP_PROP_FRAME_HEIGHT, 288); // height
Mat frame = new Mat(288, 288, CvType.CV_32F); // define a matrix to extract and store pixel info from video//
Mat dst = new Mat ();
//cap.read(frame);
JFrame jframe = new JFrame("Video"); // the lines below create a frame to display the resultant video with object detection and localization//
JLabel vidpanel = new JLabel();
jframe.setContentPane(vidpanel);
jframe.setSize(600, 600);
jframe.setVisible(true);// we instantiate the frame here//
Net net = Dnn.readNetFromDarknet(modelConfiguration, modelWeights); //OpenCV DNN supports models trained from various frameworks like Caffe and TensorFlow. It also supports various networks architectures based on YOLO//
//Thread.sleep(5000);
//Mat image = Imgcodecs.imread("D:\\yolo-object-detection\\yolo-object-detection\\images\\soccer.jpg");
Size sz = new Size(288,288);
List<Mat> result = new ArrayList<>();
List<String> outBlobNames = getOutputNames(net);
while (true) {
if (cap.read(frame)) {
Mat blob = Dnn.blobFromImage(frame, 1.0, sz, new Scalar(104.0, 117.0, 123.0, 0), false, false); // We feed one frame of video into the network at a time, we have to convert the image to a blob. A blob is a pre-processed image that serves as the input.//
net.setInput(blob);
net.forward(result, outBlobNames); //Feed forward the model to get output //
// outBlobNames.forEach(System.out::println);
// result.forEach(System.out::println);
float confThreshold = 0.6f; //Insert thresholding beyond which the model will detect objects//
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 ...