Ask Your Question
2

Sub-pixel coordinate origin

asked 2016-02-17 16:47:07 -0600

AJW gravatar image

When working with sub-pixel coordinates in OpenCV (e.g. chessboard corners in the camera calibration pipeline), what is the origin of this coordinate system?

I've seen this asked a few times, but the answers are always a bit ambiguous, so just to clarify:

I understand that in the integer pixel coordinate system, the origin is (0,0) at the top-left pixel. But for the coordinate system attached to floating-point sub-pixel coordinates, does (0,0) sit in the middle of the top-left pixel, or the top-left corner of the top-left pixel?

Many thanks!

edit retag flag offensive close merge delete

Comments

1

I would say that it is at the center of the top-left pixel, because else there would be an imbalance in coordinate systems with negative valued axes ...

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-19 06:56:39 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-02-17 18:04:21 -0600

Tetragramm gravatar image

updated 2016-02-20 17:42:56 -0600

My first answer was wrong: (0,0) is the center of the top left pixel.

Code to show this:

cv::Mat img1, img2, affine;
img1.create(10, 10, CV_32F);
img1.setTo(1.0);
affine.create(2, 3, CV_64F);
affine.at<double>(0, 0) = cos(CV_PI);
affine.at<double>(0, 1) = sin(CV_PI);
affine.at<double>(0, 2) = 0;
affine.at<double>(1, 0) = -sin(CV_PI);
affine.at<double>(1, 1) = cos(CV_PI);
affine.at<double>(1, 2) = 0;

cv::warpAffine(img1, img2, affine, cv::Size(10, 10));

cv::imshow("img1", img1);
cv::imshow("img2", img2);
std::cout << img1 << "\n\n";
std::cout << img2 << "\n\n";
cv::waitKey();

Notice that the rotation by 180 degrees leaves the top left pixel perfectly intact. So the center of that pixel is (0,0).

edit flag offensive delete link more

Comments

O lol .. didnt he just say that he understands the concept of the integer pixels...? It is not what he is looking for.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-19 06:55:50 -0600 )edit

I just used the specific wording of his question. He asked if (0,0) was the top left of the top left, or the middle of the top left pixel.

Tetragramm gravatar imageTetragramm ( 2016-02-19 15:35:47 -0600 )edit
1

O wow sorry I completely misread your answer. Are you sure it is not the center pixel?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-20 13:34:51 -0600 )edit
2

Well, that explains some problems I've been having. I went to go show that it was, and I proved myself wrong.

(0,0) is indeed in the center of the top left pixel.

Incidentally, getRectSubPix isn't enforcing it's bounds the way the comments says it does.

Tetragramm gravatar imageTetragramm ( 2016-02-20 17:40:45 -0600 )edit
1

I actually ended up doing my own empirical test, related to what I was doing with calibration. I generated a synthetic chessboard image, with the corners exactly at the pixel boundaries (i.e. where four pixels meet). I then ran it through the OpenCV chessboard corner-finding and all the corner coordinates were (x.5,y.5), which supports the finding that the centres of the pixels correspond to the integer values.

So I think we're in agreement that the sub-pixel origin is the centre of the top-left pixel.

Thanks for your input!

AJW gravatar imageAJW ( 2016-02-21 23:29:16 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-02-17 16:47:07 -0600

Seen: 3,543 times

Last updated: Feb 20 '16