OpenCV DNN Java - PullRequest
       1

OpenCV DNN Java

0 голосов
/ 06 января 2020

Я пытался запустить программу OpenCV для запуска DNN на устройстве Android, используя модуль DNC OpenCv с Tensorflow и SSD. Тем не менее, я продолжаю получать эту ошибку, когда я пытаюсь запустить программу. CvException - cv :: Exception: OpenCV (4.1.0) /build/master_pack-android/opencv/modules/dnn/src/dnn.cpp:692: ошибка: (-2.15: сбой подтверждения) input.size () == requiredOutputs в функции 'getMemoryShapes' Я не знаю, как исправить эту ошибку, потому что, насколько я знаю, мой код для доступа к текстовому файлу protobuf и protobuf кажется правильным. Мой код для доступа к переменным и чтения из них кажется правильным, и другие загрузчики OpenCV находятся в других классах, которые, кажется, работают нормально. Мой код для доступа к pb и файлу pbtxt перечислены ниже:

public Mat processFrame(Mat inputFrame) {
    final int IN_WIDTH = 300;
    final int IN_HEIGHT = 300;
    final double IN_SCALE_FACTOR = 1;
    final double MEAN_VAL = 0;
    final double THRESHOLD = 0.85;

    // Get a new frame
    Imgproc.cvtColor(inputFrame, inputFrame, Imgproc.COLOR_RGBA2RGB);

    // Forward image through network.
    Mat blob = Dnn.blobFromImage(inputFrame, IN_SCALE_FACTOR, new Size(IN_WIDTH, IN_HEIGHT), new Scalar(MEAN_VAL, MEAN_VAL, MEAN_VAL), true, false);
    net.setInput(blob);

    List<List<Double>> blobList = new ArrayList<>();

    Mat detections = net.forward();

    int cols = inputFrame.cols();
    int rows = inputFrame.rows();


    detections = detections.reshape(1, (int) detections.total() / 7);
    for (int i = 0; i < detections.rows(); ++i) {
        System.out.println(detections);
        double confidence = detections.get(i, 2)[0];

        if (confidence > THRESHOLD) {
            int classId = (int) detections.get(i, 1)[0];
            int left = (int) (detections.get(i, 3)[0] * cols);
            int top = (int) (detections.get(i, 4)[0] * rows);
            int right = (int) (detections.get(i, 5)[0] * cols);
            int bottom = (int) (detections.get(i, 6)[0] * rows);

            List<Double> list = new ArrayList<>();
            list.add(confidence);
            list.add(Double.valueOf(left));
            list.add(Double.valueOf(top));
            list.add(Double.valueOf(right));
            list.add(Double.valueOf(bottom));
            list.add(Double.valueOf(classId));

            blobList.add(list);
        }
    }

    Collections.sort(blobList, new Comparator<List<Double>>() {
        @Override
        public int compare(List<Double> a, List<Double> b) {
            return a.get(0) > b.get(0) ? 1 : -1;
        }
    });

    Collections.reverse(blobList);

    int maxIndex = blobList.size() > 6 ? 6 : blobList.size();
    int numOfSkystone = 0;

    for (int i = 0; i < 6; i++) {
        List<Double> blobStuff = blobList.get(i);
        String detectedObj = "";


        double v = blobStuff.get(5).doubleValue();
        if (v == 3.0) {
            detectedObj = "Skystone";
            numOfSkystone++;
        } else if (v == 4.0) {
            detectedObj = "Stone";
        } else if (v == 2.0) {
            detectedObj = "Red Foundation";
        } else if (v == 1.0) {
            detectedObj = "Blue Foundation";
        } else {
            detectedObj = "Unknown";
        }

        String label = detectedObj + ": " + blobStuff.get(0);
        int[] baseLine = new int[1];
        Size labelSize = Imgproc.getTextSize(label, FONT_HERSHEY_SIMPLEX, 0.5, 1, baseLine);
        Imgproc.rectangle(inputFrame, new Point((int) blobStuff.get(1).intValue(), (int) blobStuff.get(2).intValue() - labelSize.height),
                new Point((int) blobStuff.get(1).intValue() + labelSize.width, (int) blobStuff.get(2).intValue() + baseLine[0]),
                new Scalar(255, 255, 255), Imgproc.FILLED);
        // Write class name and confidence.
        Imgproc.putText(inputFrame, label, new Point(blobStuff.get(0), blobStuff.get(2)),
                FONT_HERSHEY_SIMPLEX, 0.5, new Scalar(0, 0, 0));
    }
    return inputFrame;
}

Насколько я знаю, код для этого кажется правильным, но я чувствую, что ошибка может быть в файле pbtxt, но я понятия не имею, как это исправить. Файл pbtxt должен был быть атакован как ссылка, главным образом из-за того, что он очень и очень длинный, около 5000 строк, и я запустил файл tf_graph_ssd.py, чтобы сгенерировать его. Тем не менее, все строки в этом тоже кажутся правильными, может кто-нибудь помочь мне понять, что с ним не так?

PB файл, Pbtxt, config: https://drive.google.com/drive/folders/19g7xnC9ekjUHeFNtgcvSn2J1ioWmrb_L

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...