Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
183 Views

face detection with face-detection-adas-0001 in opencv

Jump to solution

Hello everybody

I am developing a face detection APP with opencv in c++,i wanna use the ace-detection-adas-0001 model in my app.

System information :

OS : ubuntu 18.04

framework :Qt

compiler :GCC

openvino : l_openvino_toolkit_p_2020.2.120

opencv : openvino pre-built opencv 4.3.0

 

This is my tets code :

Net net = readNet("face-detection-adas-0001.bin","face-detection-adas-0001.xml");

Mat image = imread("image.jpg");

Mat blob = blobFromImage(image,1.0,cv::Size(672, 384),0);

net.setInput(blob);

Mat res = net.forward();

Mat objectMask(res.size[2], res.size[3],CV_32F, res.ptr<float>(0,1));

objectMask = objectMask.reshape(1, objectMask.total() / 7);

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

{

float score = objectMask.at<float>(i, 2);

cout<<objectMask.at<float>(i, 0)<<endl;

if(score > 0.5)

{

int classId = static_cast<int>(objectMask.at<float>(i, 1));

//cout<<classId<<endl;

int left = static_cast<int>(image.cols * objectMask.at<float>(i, 3));

int top = static_cast<int>(image.rows * objectMask.at<float>(i, 4));

int right = static_cast<int>(image.cols * objectMask.at<float>(i, 5));

int bottom = static_cast<int>(image.rows * objectMask.at<float>(i, 6));

left = max(0, min(left, image.cols - 1));

top = max(0, min(top, image.rows - 1));

right = max(0, min(right, image.cols - 1));

bottom = max(0, min(bottom, image.rows - 1));

Rect box = Rect(left, top, right - left + 1, bottom - top + 1);

rectangle(image, Point(left, top), Point(right,bottom), Scalar(255, 0, 0));

}

}

imshow("sss",image);

waitKey(0);

I can build and run my test code successfully in Qt.

But it gives me very bad results and can not detect any face properly.

Can the problem be the openvino or opencv ?
I have not any idea about the problem.

Any help would be greatly appreciated
Thanks in advance.

0 Kudos

Accepted Solutions
Highlighted
183 Views

Mat objectMask(res.size[2], res.size[3],CV_32F, res.ptr<float>());

The pointer to the result should be provided as the parameter to the objectMask. For more details, Please refer this Documentation.

Regards,

Ram prasad

View solution in original post

0 Kudos
4 Replies
Highlighted
183 Views

Hi Naserpiltan,

Could you please try to replace the below line

Mat objectMask(res.size[2], res.size[3],CV_32F, res.ptr<float>(0,1));

to

Mat objectMask(res.size[2], res.size[3],CV_32F, res.ptr<float>());

Hope this helps

Regards,

Ram prasad

0 Kudos
Highlighted
Beginner
183 Views

Hello Ram prasad

Thank you so so much.Yeah now i can detect face very nice and it works like a charm with your solution.

But can you describe what was my prblem ?

i was picking the 0 and 1 dimentions of ouput tenosr in my test code. but what about now ?we are picking all dimentions ?why?

Thank you

0 Kudos
Highlighted
184 Views

Mat objectMask(res.size[2], res.size[3],CV_32F, res.ptr<float>());

The pointer to the result should be provided as the parameter to the objectMask. For more details, Please refer this Documentation.

Regards,

Ram prasad

View solution in original post

0 Kudos
Highlighted
Beginner
183 Views

@Ram prasad i got it .
Thank you so much.

0 Kudos