Android 上的 OpenCV:net.forward 产生“215 断言失败”

因 net.forward 上的断言失败而崩溃,我无法在其他任何地方解决/找到。

认为这个问题看起来很相似,并试图通过修复/问题发现。然而,重新开始讨论和试验表明它可能不一样。我最初使用的是 3.4.3,它以某种方式不支持相同的 Mat 类型。现在更新到 3.4.7,可以确认 blob 大小没问题(从图像生成)。还尝试了其他各种 prototxt 和 caffemodels,但现在怀疑问题出在那里(如果文件没问题就可以工作,否则网络加载失败)。关键代码应该是这样的:

// Load a network.

public void onCameraViewStarted(int width, int height) {

    String proto = getPath("deploy.prototxt", this);

    String weights = getPath("MobileNetSSD_deploy.caffemodel", this);

    net = Dnn.readNetFromCaffe(proto, weights);

    Log.i(TAG, "Network loaded successfully");

}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    // Get a new frame

    Mat frame = inputFrame.rgba();

    Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2RGB);

    // Forward image through network.

    Mat blob = Dnn.blobFromImage(frame, 0.007843,

            new Size(300, 300),

            new Scalar(127.5, 127.5, 127.5));


    net.setInput(blob);

    Mat detections = net.forward(); //***215 ASSERTION FAILED occurs***

    int cols = frame.cols();

    int rows = frame.rows();

    detections = detections.reshape(1, (int)detections.total() / 7);

    for (int i = 0; i < detections.rows(); ++i) {

        double confidence = detections.get(i, 2)[0];

        if (confidence > 0.2) {

            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);

        }

    }

    return frame;

}


完整的错误信息是


cv::Exception: OpenCV(3.4.7) /build/3_4_pack-android/opencv/modules/dnn/src/layers/batch_norm_layer.cpp:39: 错误: (-215:断言失败) blobs.size() >= 2 在函数 'cv::dnn::BatchNormLayerImpl::BatchNormLayerImpl(const cv::dnn::experimental_dnn_34_v13::LayerParams&)'


我希望它不会崩溃。框架应该没问题(图像已加载),网络不是空的,网络中的层看起来也很好(已检查,因为在 java 中使用 caffe 存在一些差异)。任何帮助表示赞赏!


杨魅力
浏览 143回答 1
1回答

温温酱

帧格式应该是 BGR,而不是 RGB!这意味着Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2BGR);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java