Face detection model doesn't detect any face (OpenCV with IE) [closed]

asked 2020-06-21 14:29:47 -0500

VCAS gravatar image

Hi, I've compile OpenCV with inference engine (IE) successfully. Since I'm using OpenCVSharp, I've also complied it with OpenCV with IE. Then, when I try to detect faces with the model face-detection-adas-0001 it doesn't detect any faces. The model is loaded successfully, it seems to do the foward pass but the output Mat has always col=-1 and row=-1. Although I'm using C#, if someone has already used this model in C++, please clarify how the input blob should be. I think that is probably what I'm getting wrong. Here is the code:

var net = CvDnn.ReadNet(model, modeltxt);
var image = System.IO.Path.Combine(Location, sampleImage);
var frame = Cv2.ImRead(image);
net.SetPreferableBackend(Net.Backend.INFERENCE_ENGINE);
net.SetPreferableTarget(Net.Target.CPU);

var frame = Cv2.ImRead(image);
var test = new Mat();
frame.ConvertTo(test, MatType.CV_8U);
var blob = CvDnn.BlobFromImage(test, 1.0, new OpenCvSharp.Size(672, 384), default, false, false);
net.SetInput(blob);
var outNames = net.GetUnconnectedOutLayersNames();

using (var predictions = net.Forward(outNames[0]))
{
       PrintMat(predictions);
}

image description

Thanks!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by VCAS
close date 2020-06-21 15:51:09.277441

Comments

OpenCVSharp,

sorry to say so, but totally off-topic/unsupported 3rd party effort

(don't get me wrong, i like it, but noone here will be able to help you with specific api bugs of that)

berak gravatar imageberak ( 2020-06-21 15:24:38 -0500 )edit

frame.ConvertTo(test, MatType.CV_8U);

bs. it's already like that (CV_8UC3, to be exact)

berak gravatar imageberak ( 2020-06-21 15:26:59 -0500 )edit

did you ever check, if var frame = Cv2.ImRead(image);

is valid ? `

berak gravatar imageberak ( 2020-06-21 15:34:45 -0500 )edit

Hi, I've managed to solve it. The code is correct but I was not accessing the output data from the net correctly. So here is the code if anyone needs in the future:

Mat detectionMat = new Mat(detection.Size(2), detection.Size(3), MatType.CV_32F, predictions.Ptr(0));
VCAS gravatar imageVCAS ( 2020-06-21 15:50:34 -0500 )edit