Ask Your Question
0

convert a position from a smaller image to a bigger image.

asked 2015-04-23 13:08:22 -0600

215 gravatar image

Hi guys.. I am using the haar cascades to detect faces, and to make it do it faster I work on grayscale image, and wondering if should change the dimensions of the image it applied to.. I mean it makes totally sense that applying it to a smalle image creates less work.

But the face detection is only used to find create a ROI of the face. So how do i detect a face in small picture, and transfer those parameter into the original picture. such that i will know exactly where the face is in i the "big picture" ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-04-24 02:47:38 -0600

sgarrido gravatar image

updated 2015-04-24 02:58:42 -0600

You can transform points from the small image to the big image (or viceversa) by a simple cross-multiplication (rule of three). For example:

    cv::Mat smallImg, bigImg;
    cv::Point2f bigPnt, smallPnt;
    ...
    bigPnt.x = smallPnt.x * float(bigImg.cols) / float(smallImg.cols);
    bigPnt.y = smallPnt.y * float(bigImg.rows) / float(smallImg.rows);

A rectangle (ROI) can be transformed in the same way:

    cv::Mat smallImg, bigImg;
    cv::Rect bigROI, smallROI;
    ...
    bigROI.x = smallROI.x * float(bigImg.cols) / float(smallImg.cols);
    bigROI.y = smallROI.y * float(bigImg.rows) / float(smallImg.rows);
    bigROI.width = smallROI.width * float(bigImg.cols) / float(smallImg.cols);
    bigROI.height = smallROI.height * float(bigImg.rows) / float(smallImg.rows);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-04-23 13:08:22 -0600

Seen: 305 times

Last updated: Apr 24 '15