twistedfall / opencv-rust

Rust bindings for OpenCV 3 & 4
MIT License
1.86k stars 144 forks source link

FaceDetectorYN.detect throws an error #562

Closed ghost closed 2 months ago

ghost commented 2 months ago
  1. Ubuntu 2204lts
  2. The way you installed OpenCV: package
  3. OpenCV version 454
  4. rustc version 1 76
    
    [ERROR:0] global ./modules/dnn/src/dnn.cpp (3551) getLayerShapesRecursively OPENCV/DNN: [Eltwise]:(252): getMemoryShapes() throws exception. inputs=2 outputs=1/1 blobs=0
    [ERROR:0] global ./modules/dnn/src/dnn.cpp (3557) getLayerShapesRecursively     input[0] = [ 1 64 109 160 ]
    [ERROR:0] global ./modules/dnn/src/dnn.cpp (3557) getLayerShapesRecursively     input[1] = [ 1 64 108 160 ]
    [ERROR:0] global ./modules/dnn/src/dnn.cpp (3561) getLayerShapesRecursively     output[0] = [ 1 64 109 160 ]
    [ERROR:0] global ./modules/dnn/src/dnn.cpp (3567) getLayerShapesRecursively Exception message: OpenCV(4.5.4) ./modules/dnn/src/layers/eltwise_layer.cpp:247: error: (-215:Assertion failed) inputs[vecIdx][j] == inputs[i][j] in function 'getMemoryShapes'

thread 'main' panicked at src/main.rs:20:41: called Result::unwrap() on an Err value: Error { code: "StsAssert, -215", message: "OpenCV(4.5.4) ./modules/dnn/src/layers/eltwise_layer.cpp:247: error: (-215:Assertion failed) inputs[vecIdx][j] == inputs[i][j] in function 'getMemoryShapes'\n" }


```rust
use opencv::{
    core::Size,
    imgcodecs,
    objdetect::FaceDetectorYN,
    prelude::*,
};

fn main() {
    let mut detector = FaceDetectorYN::create_def(
        "./face_detection_yunet_2023mar.onnx",
        "",
        Size::new(100, 100),
    )
    .unwrap();

    let img = imgcodecs::imread("./face.png", imgcodecs::IMREAD_COLOR).unwrap();

    detector.set_input_size(img.size().unwrap()).unwrap();
    let mut faces = Mat::default();
    detector.detect(&img, &mut faces).unwrap();
}

I followed the official tutorial, I took the files from the same place

twistedfall commented 2 months ago

Please check https://github.com/twistedfall/opencv-rust/blob/master/examples/dnn_face_detect.rs for the port of that example to Rust.