# Adjust sub-pixel coordinates in RefineChessboardCorners

**URL:** <https://forum.opencv.org/t/adjust-sub-pixel-coordinates-in-refinechessboardcorners/24050>\
**Category:** C++\
**Tags:** aruco, features2d, calib3d\
**Created:** [September 24, 2025, 2:06pm UTC](https://forum.opencv.org/t/adjust-sub-pixel-coordinates-in-refinechessboardcorners/24050 "2025-09-24T14:06:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ueli\_Peter](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ueli_peter/32/13760_2.png) [@Ueli\_Peter](https://forum.opencv.org/u/Ueli_Peter)\
**Post date:** [September 24, 2025, 2:06pm UTC](https://forum.opencv.org/t/adjust-sub-pixel-coordinates-in-refinechessboardcorners/24050/1 "2025-09-24T14:06:08Z")

</div>

Hi, in the source code for selectAndRefineChessboardCorners I don’t understand line 161 and 170 here: [opencv/modules/objdetect/src/aruco/charuco\_detector.cpp at 5.x · opencv/opencv · GitHub](https://github.com/opencv/opencv/blob/5.x/modules/objdetect/src/aruco/charuco_detector.cpp)

Before cornerSubPix (0.5, 0.5) is subtracted from the corner, and afterwards (0.5, 0.5) is added back. The line is commented “// adjust sub-pixel coordinates for cornerSubPix”  
Can anyone explain this comment and why the pixel shift is necessary?

---

<div class="post-metadata">

**Author:** ![Steve\_in\_Denver](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Steve\_in\_Denver](https://forum.opencv.org/u/Steve_in_Denver)\
**Post date:** [September 30, 2025, 9:14pm UTC](https://forum.opencv.org/t/adjust-sub-pixel-coordinates-in-refinechessboardcorners/24050/2 "2025-09-30T21:14:43Z")

</div>

It probably has to do with a difference in the origin (where 0,0 is) for a pixel. For example, if cornersubpix operates on pixels and treats the top left of a pixel as the 0,0 reference, but other parts of the processing treat the center of a pixel as the 0,0 reference, then a half pixel shift is needed to transform between those two coordinate systems.

In much (most?) of openCV, the center of the pixel is considered the origin. So if you call cv::projectPoints, for example, and get a result of (0.0,0.0) that means the projected points lands at the **center** of the upper-left pixel, not the top/left of the upper-left pixel. This has implications when warping images to be displayed in a program due to the difference in pixel origin treatment. (I usually build the half pixel into the warp/remap step because it makes it easier to handle on the UI side, but the specific context matters, of course.)
