Ask Your Question

Revision history [back]

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 * bigImg.cols / smallImg.cols;
    bigPnt.y = smallPnt.y * bigImg.rows / smallImg.rows;

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

    cv::Mat smallImg, bigImg;
    cv::Rect bigROI, smallROI;
    ...
    bigROI.x = smallROI.x * bigImg.cols / smallImg.cols;
    bigROI.y = smallROI.y * bigImg.rows / smallImg.rows;
    bigROI.width = smallROI.width * bigImg.cols / smallImg.cols;
    bigROI.height = smallROI.height * bigImg.rows / smallImg.rows;

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 * bigImg.cols float(bigImg.cols) / smallImg.cols;
float(smallImg.cols);
    bigPnt.y = smallPnt.y * bigImg.rows float(bigImg.rows) / smallImg.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 * bigImg.cols float(bigImg.cols) / smallImg.cols;
float(smallImg.cols);
    bigROI.y = smallROI.y * bigImg.rows float(bigImg.rows) / smallImg.rows;
float(smallImg.rows);
    bigROI.width = smallROI.width * bigImg.cols float(bigImg.cols) / smallImg.cols;
float(smallImg.cols);
    bigROI.height = smallROI.height * bigImg.rows float(bigImg.rows) / smallImg.rows;
float(smallImg.rows);