Ask Your Question

# Sub-pixel coordinate origin

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 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 ...

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

## 1 answer

Sort by ยป oldest newest most voted

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).

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.

( 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.

( 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?

( 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.

( 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!

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

Official site

GitHub

Wiki

Documentation

## Stats

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

Seen: 3,361 times

Last updated: Feb 20 '16