Ask Your Question
0

How to Get Rect from point

asked 2016-02-15 08:26:05 -0600

sarmad gravatar image

Hi

I'm using function Point detectFace(Mat frame, Point priorCenter) to detect face in a video frame

the function gives a Mat object contains detected face , function link

I"m calling this function inside another function , my question is how can I get a rect from the output of this function ?

This is how I'm calling the function

    Point priorCenter(0, 0);
    priorCenter = detectFace(matCapturedGrayImage, priorCenter);

    Rect face (priorCenter.x, priorCenter.y, priorCenter.width(), priorCenter. height());

it is not correct , I need help

Thanks

edit retag flag offensive close merge delete

Comments

No, detectMultiscale has as output a vector of cv::Rect, why do you want to transform it to cv::Point then turn it back to cv::Rect? What is wrong with the Rects in the vector? Why not changing the function so it returns a Rect instead of Point?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-15 09:29:05 -0600 )edit
1

I have posted earlier about the shaky face and eye, this function solves the problem with smooth detection and gives a Mat that contains detected face , I need to get rect to pass it to another function .

sarmad gravatar imagesarmad ( 2016-02-15 09:58:57 -0600 )edit

You should return a cv::Rect of the face that is computed from that point and the w and h used for drawing the ellipse. Point has no width and height

thdrksdfthmn gravatar imagethdrksdfthmn ( 2016-02-16 08:25:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-02-27 10:10:51 -0600

MikeTronix gravatar image

The x and y in a Rect object refer to the upper left hand corner. If you want the new Rect to be centered on the priorCenter point, you need to use something like this:

Rect face(priorCenter.x-priorCenter.width/2,priorCenter.y-priorCenter.height/2,priorCenter.width,priorCenter.height);

Depending on the types, you may need to do some static casts to get all the types right after division.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-02-15 08:26:05 -0600

Seen: 884 times

Last updated: Feb 27 '20