Monday 15 June 2015

Mat ROI coordinate

I remember a joke in Friends, when Chandler tells Joey it is a J in joincidence, not a C in coincidence.

In opencv, rect is often used when setting the roi of a mat. However, the coordinate could be confusing. Take an example in here, what should be the lower left of an image? It should be Rect( 0, image.rows/2, image.cols/2, image.rows/2 ), instead of Rect( image.rows/2, 0, image.cols/2, image.rows/2 ).

Unlike accessing elements in a mat directly, for instance image.at<float>(row, col), the rect takes in (x, y), corresponding to (col, row). Therefore, the rect is always set by Rect(int x, int y, int width, int height), where width = no. of columns while height = no. of rows.

A good illustration of opencv image coordinate system can be found here
cvcoordinate
Bear in mind this coordinate system when converting opencv image coordinates to camera coordinates, like this
enter image description here

No comments:

Post a Comment