Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Problems with cvFindCornerSubPix results

I have a chessboard grid and found the corners to (about) the nearest pixel okay. I then call cvFindCornerSubPix but the returned points move unexpectedly. I am confident that I am within 1.5 pixels of the corner to begin with.

Here is the code I use for the sub-pixelling. Despite reading the docs I don't really understand what the zeroZone and criteria fields mean so am not sure if I'm supplying good values.

  cvFindCornerSubPix(
  image[lr], &ponintsTemp[lr][0], cornersDetected,
  cvSize(11, 11), // Half sizes of the search window. For example, if win=(5,5) then 5*2+1 x 5*2+1 = 11 x 11 search window is used
  cvSize(-1,-1),  // Half size of the dead region in the middle of the search ... value of (-1,-1) indicates that there is no such size
  cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30, 0.01)
  );

These are the points I am supplying (before passing to cvFindCornerSubPix I also add 0.5): 159,567 ,211,573 ,263,579 ,316,585 ,369,591 ,423,598 ,475,604 ,529,610 ,154,620 ,206,626 ,258,632 ,311,638 ,364,645 ,416,651 ,470,657 ,523,663 ,149,673 ,201,679 ,253,685 ,306,691 ,358,698 ,411,704 ,464,710 ,517,716 ,145,725 ,196,731 ,248,738 ,300,744 ,353,751 ,405,757 ,458,763 ,511,769 ,140,777 ,191,784 ,243,790 ,295,796 ,348,803 ,401,809 ,453,815 ,506,821 ,136,829 ,187,835 ,238,842 ,290,848 ,343,854 ,395,860 ,448,867 ,500,873

These are the returned points from cvFindCornerSubPix: 144.90,568.30, 200.64,574.58, 256.20,580.58, 311.26,586.68, 366.09,592.83, 420.62,598.86, 475.00,604.88, 528.90,610.85, 138.79,622.97, 194.59,628.89, 250.03,634.97, 305.21,640.83, 360.01,646.78, 414.57,652.66, 468.82,658.53, 522.68,664.44, 132.71,677.51, 188.53,683.44, 243.97,689.21, 299.02,695.01, 353.90,700.75, 408.41,706.49, 462.58,712.34, 516.55,718.03, 126.76,732.07, 182.42,737.75, 237.87,743.46, 292.96,749.03, 347.78,754.78, 402.11,760.37, 456.34,765.91, 510.29,771.58, 120.73,786.35, 176.24,792.06, 231.76,797.47, 286.77,803.05, 341.66,808.51, 396.04,813.91, 450.29,819.47, 504.20,824.79, 114.64,840.70, 170.35,846.08, 225.63,851.55, 280.74,856.79, 335.42,862.25, 389.94,867.54, 444.10,872.86, 498.00,878.23

Here is the image (irrelevant bits masked for better image compression): orig-masked.png. In the grid-crop.png image I have drawn the output points and you can see how they are shifted (lots to the left at the left but only a bit on the right). For the top-left I have also drawn a purple dot for the point I supplied so its too far to the left by 14 pixels or so.

Main Question: Is there anything wrong with what I am doing?

I am using version 2.3.1 (so a fairly old version) but I'm sure something serious like this would have been noticed by then. I am reluctant to upgrade to the current version because of possible complications in changes to the interface (although cvFindCornerSubPix still seems to be a vanilla C function and should be fine).

Problems with cvFindCornerSubPix results

I have a chessboard grid and found the corners to (about) the nearest pixel okay. I then call cvFindCornerSubPix but the returned points move unexpectedly. I am confident that I am within 1.5 pixels of the corner to begin with.

Here is the code I use for the sub-pixelling. Despite reading the docs I don't really understand what the zeroZone and criteria fields mean so am not sure if I'm supplying good values.

  cvFindCornerSubPix(
  image[lr], &ponintsTemp[lr][0], cornersDetected,
  cvSize(11, 11), // Half sizes of the search window. For example, if win=(5,5) then 5*2+1 x 5*2+1 = 11 x 11 search window is used
  cvSize(-1,-1),  // Half size of the dead region in the middle of the search ... value of (-1,-1) indicates that there is no such size
  cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30, 0.01)
  );

These are the points I am supplying (before passing to cvFindCornerSubPix I also add 0.5): 159,567 ,211,573 ,263,579 ,316,585 ,369,591 ,423,598 ,475,604 ,529,610 ,154,620 ,206,626 ,258,632 ,311,638 ,364,645 ,416,651 ,470,657 ,523,663 ,149,673 ,201,679 ,253,685 ,306,691 ,358,698 ,411,704 ,464,710 ,517,716 ,145,725 ,196,731 ,248,738 ,300,744 ,353,751 ,405,757 ,458,763 ,511,769 ,140,777 ,191,784 ,243,790 ,295,796 ,348,803 ,401,809 ,453,815 ,506,821 ,136,829 ,187,835 ,238,842 ,290,848 ,343,854 ,395,860 ,448,867 ,500,873

These are the returned points from cvFindCornerSubPix: 144.90,568.30, 200.64,574.58, 256.20,580.58, 311.26,586.68, 366.09,592.83, 420.62,598.86, 475.00,604.88, 528.90,610.85, 138.79,622.97, 194.59,628.89, 250.03,634.97, 305.21,640.83, 360.01,646.78, 414.57,652.66, 468.82,658.53, 522.68,664.44, 132.71,677.51, 188.53,683.44, 243.97,689.21, 299.02,695.01, 353.90,700.75, 408.41,706.49, 462.58,712.34, 516.55,718.03, 126.76,732.07, 182.42,737.75, 237.87,743.46, 292.96,749.03, 347.78,754.78, 402.11,760.37, 456.34,765.91, 510.29,771.58, 120.73,786.35, 176.24,792.06, 231.76,797.47, 286.77,803.05, 341.66,808.51, 396.04,813.91, 450.29,819.47, 504.20,824.79, 114.64,840.70, 170.35,846.08, 225.63,851.55, 280.74,856.79, 335.42,862.25, 389.94,867.54, 444.10,872.86, 498.00,878.23

Here is the image (irrelevant bits masked for better image compression): orig-masked.png. In the grid-crop.png image I have drawn the output points and you can see how they are shifted (lots to the left at the left but only a bit on the right). For the top-left I have also drawn a purple dot for the point I supplied so its too far to the left by 14 pixels or so.

Main Question: Is there anything wrong with what I am doing?

I am using version 2.3.1 (so a fairly old version) but I'm sure something serious like this would have been noticed by then. I am reluctant to upgrade to the current version because of possible complications in changes to the interface (although cvFindCornerSubPix still seems to be a vanilla C function and should be fine).

EDIT: Just got version 2.4.8 going in a VM (actually getting the VM working ended up being harder than updating OpenCV) but the same issue persists - cvFindCornerSubPix still seems to be shifting points to the left the further left in the image they are.