Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes there is a builtin-function if your small image is a real ROI of your larger image matrix, i.e. it was created via cv::Rect(), cv::Range(), cv::rowRange(), cv::colRange(), cv::row(), cv::col(): it is called locateROI(), see http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-locateroi.

Example usage:

cv::Size orig_img_size;
cv::Point offset;
roi_matrix.locateROI(orig_img_size, offset);
// offset will now contain the offset of the ROI to your image 
// this you need to add to your locale point-coordinate p.

If you haven't created it by one of the mentioned functions (hope I haven't forgotten one), e.g. if you have saved the small image to your harddrive before without saving the offset parameter, then you can get the shift using matchTemplate() (see http://docs.opencv.org/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#matchtemplate) and applying minMaxLoc() onto its output (see http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#minmaxloc).