Cleanup
This commit is contained in:
parent
8215d20dbf
commit
b000663a88
@ -79,14 +79,7 @@
|
|||||||
//#define ENABLE_TRIM_COL_ROW
|
//#define ENABLE_TRIM_COL_ROW
|
||||||
|
|
||||||
//#define DEBUG_CHESSBOARD
|
//#define DEBUG_CHESSBOARD
|
||||||
#ifdef DEBUG_CHESSBOARD
|
|
||||||
# include "opencv2/opencv_modules.hpp"
|
|
||||||
# ifdef HAVE_OPENCV_HIGHGUI
|
|
||||||
# include "opencv2/highgui.hpp"
|
|
||||||
# else
|
|
||||||
# undef DEBUG_CHESSBOARD
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifdef DEBUG_CHESSBOARD
|
#ifdef DEBUG_CHESSBOARD
|
||||||
static int PRINTF( const char* fmt, ... )
|
static int PRINTF( const char* fmt, ... )
|
||||||
{
|
{
|
||||||
@ -400,38 +393,6 @@ bool icvBinarizationHistogramBased( unsigned char* pucImg, int iCols, int iRows
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
static void
|
|
||||||
icvCalcAffineTranf2D32f(CvPoint2D32f* pts1, CvPoint2D32f* pts2, int count, CvMat* affine_trans)
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
int real_count = 0;
|
|
||||||
for( j = 0; j < count; j++ )
|
|
||||||
{
|
|
||||||
if( pts1[j].x >= 0 ) real_count++;
|
|
||||||
}
|
|
||||||
if(real_count < 3) return;
|
|
||||||
cv::Ptr<CvMat> xy = cvCreateMat( 2*real_count, 6, CV_32FC1 );
|
|
||||||
cv::Ptr<CvMat> uv = cvCreateMat( 2*real_count, 1, CV_32FC1 );
|
|
||||||
//estimate affine transfromation
|
|
||||||
for( i = 0, j = 0; j < count; j++ )
|
|
||||||
{
|
|
||||||
if( pts1[j].x >= 0 )
|
|
||||||
{
|
|
||||||
CV_MAT_ELEM( *xy, float, i*2+1, 2 ) = CV_MAT_ELEM( *xy, float, i*2, 0 ) = pts2[j].x;
|
|
||||||
CV_MAT_ELEM( *xy, float, i*2+1, 3 ) = CV_MAT_ELEM( *xy, float, i*2, 1 ) = pts2[j].y;
|
|
||||||
CV_MAT_ELEM( *xy, float, i*2, 2 ) = CV_MAT_ELEM( *xy, float, i*2, 3 ) = CV_MAT_ELEM( *xy, float, i*2, 5 ) = \
|
|
||||||
CV_MAT_ELEM( *xy, float, i*2+1, 0 ) = CV_MAT_ELEM( *xy, float, i*2+1, 1 ) = CV_MAT_ELEM( *xy, float, i*2+1, 4 ) = 0;
|
|
||||||
CV_MAT_ELEM( *xy, float, i*2, 4 ) = CV_MAT_ELEM( *xy, float, i*2+1, 5 ) = 1;
|
|
||||||
CV_MAT_ELEM( *uv, float, i*2, 0 ) = pts1[j].x;
|
|
||||||
CV_MAT_ELEM( *uv, float, i*2+1, 0 ) = pts1[j].y;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cvSolve( xy, uv, affine_trans, CV_SVD );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CV_IMPL
|
CV_IMPL
|
||||||
int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
||||||
@ -449,11 +410,6 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
const int min_dilations = 0;
|
const int min_dilations = 0;
|
||||||
const int max_dilations = 7;
|
const int max_dilations = 7;
|
||||||
cv::Ptr<CvMat> norm_img, thresh_img;
|
cv::Ptr<CvMat> norm_img, thresh_img;
|
||||||
#ifdef DEBUG_CHESSBOARD
|
|
||||||
cv::Ptr<IplImage> dbg_img;
|
|
||||||
cv::Ptr<IplImage> dbg1_img;
|
|
||||||
cv::Ptr<IplImage> dbg2_img;
|
|
||||||
#endif
|
|
||||||
cv::Ptr<CvMemStorage> storage;
|
cv::Ptr<CvMemStorage> storage;
|
||||||
|
|
||||||
CvMat stub, *img = (CvMat*)arr;
|
CvMat stub, *img = (CvMat*)arr;
|
||||||
@ -487,12 +443,6 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
storage.reset(cvCreateMemStorage(0));
|
storage.reset(cvCreateMemStorage(0));
|
||||||
thresh_img.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
thresh_img.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
||||||
|
|
||||||
#ifdef DEBUG_CHESSBOARD
|
|
||||||
dbg_img = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3 );
|
|
||||||
dbg1_img = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3 );
|
|
||||||
dbg2_img = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3 );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( CV_MAT_CN(img->type) != 1 || (flags & CV_CALIB_CB_NORMALIZE_IMAGE) )
|
if( CV_MAT_CN(img->type) != 1 || (flags & CV_CALIB_CB_NORMALIZE_IMAGE) )
|
||||||
{
|
{
|
||||||
// equalize the input image histogram -
|
// equalize the input image histogram -
|
||||||
@ -627,9 +577,12 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
}
|
}
|
||||||
}//dilations
|
}//dilations
|
||||||
|
|
||||||
|
PRINTF("Chessboard detection result 0: %d\n", found);
|
||||||
|
|
||||||
// revert to old, slower, method if detection failed
|
// revert to old, slower, method if detection failed
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
|
PRINTF("Fallback to old algorithm\n");
|
||||||
// empiric threshold level
|
// empiric threshold level
|
||||||
// thresholding performed here and not inside the cycle to save processing time
|
// thresholding performed here and not inside the cycle to save processing time
|
||||||
int thresh_level;
|
int thresh_level;
|
||||||
@ -671,10 +624,6 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
cvDilate( thresh_img, thresh_img, 0, 1 );
|
cvDilate( thresh_img, thresh_img, 0, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_CHESSBOARD
|
|
||||||
cvCvtColor(thresh_img,dbg_img,CV_GRAY2BGR);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// So we can find rectangles that go to the edge, we draw a white line around the image edge.
|
// So we can find rectangles that go to the edge, we draw a white line around the image edge.
|
||||||
// Otherwise FindContours will miss those clipped rectangle contours.
|
// Otherwise FindContours will miss those clipped rectangle contours.
|
||||||
// The border color will be the image mean, because otherwise we risk screwing up filters like cvSmooth()...
|
// The border color will be the image mean, because otherwise we risk screwing up filters like cvSmooth()...
|
||||||
@ -684,31 +633,6 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
quad_count = icvGenerateQuads( &quads, &corners, storage, thresh_img, flags, &max_quad_buf_size);
|
quad_count = icvGenerateQuads( &quads, &corners, storage, thresh_img, flags, &max_quad_buf_size);
|
||||||
PRINTF("Quad count: %d/%d\n", quad_count, expected_corners_num);
|
PRINTF("Quad count: %d/%d\n", quad_count, expected_corners_num);
|
||||||
|
|
||||||
#ifdef DEBUG_CHESSBOARD
|
|
||||||
cvCopy(dbg_img, dbg1_img);
|
|
||||||
cvNamedWindow("all_quads", 1);
|
|
||||||
// copy corners to temp array
|
|
||||||
for(int i = 0; i < quad_count; i++ )
|
|
||||||
{
|
|
||||||
for (int z=0; z<4; z++)
|
|
||||||
{
|
|
||||||
CvPoint2D32f pt1, pt2;
|
|
||||||
CvScalar color = CV_RGB(30,255,30);
|
|
||||||
pt1 = quads[i].corners[z]->pt;
|
|
||||||
pt2 = quads[i].corners[(z+1)%4]->pt;
|
|
||||||
pt2.x = (pt1.x + pt2.x)/2;
|
|
||||||
pt2.y = (pt1.y + pt2.y)/2;
|
|
||||||
if (z>0)
|
|
||||||
color = CV_RGB(200,200,0);
|
|
||||||
cvLine( dbg1_img, cvPointFrom32f(pt1), cvPointFrom32f(pt2), color, 3, 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
cvShowImage("all_quads", (IplImage*)dbg1_img);
|
|
||||||
cvWaitKey();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if( quad_count <= 0 )
|
if( quad_count <= 0 )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
@ -739,33 +663,6 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
|
|
||||||
PRINTF("Orig count: %d After ordering: %d\n", icount, count);
|
PRINTF("Orig count: %d After ordering: %d\n", icount, count);
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_CHESSBOARD
|
|
||||||
cvCopy(dbg_img,dbg2_img);
|
|
||||||
cvNamedWindow("connected_group", 1);
|
|
||||||
// copy corners to temp array
|
|
||||||
for(int i = 0; i < quad_count; i++ )
|
|
||||||
{
|
|
||||||
if (quads[i].group_idx == group_idx)
|
|
||||||
for (int z=0; z<4; z++)
|
|
||||||
{
|
|
||||||
CvPoint2D32f pt1, pt2;
|
|
||||||
CvScalar color = CV_RGB(30,255,30);
|
|
||||||
if (quads[i].ordered)
|
|
||||||
color = CV_RGB(255,30,30);
|
|
||||||
pt1 = quads[i].corners[z]->pt;
|
|
||||||
pt2 = quads[i].corners[(z+1)%4]->pt;
|
|
||||||
pt2.x = (pt1.x + pt2.x)/2;
|
|
||||||
pt2.y = (pt1.y + pt2.y)/2;
|
|
||||||
if (z>0)
|
|
||||||
color = CV_RGB(200,200,0);
|
|
||||||
cvLine( dbg2_img, cvPointFrom32f(pt1), cvPointFrom32f(pt2), color, 3, 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cvShowImage("connected_group", (IplImage*)dbg2_img);
|
|
||||||
cvWaitKey();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
continue; // haven't found inner quads
|
continue; // haven't found inner quads
|
||||||
|
|
||||||
@ -812,10 +709,13 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
}// for k = 0 -> 6
|
}// for k = 0 -> 6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTF("Chessboard detection result 1: %d\n", found);
|
||||||
|
|
||||||
if( found )
|
if( found )
|
||||||
found = icvCheckBoardMonotony( out_corners, pattern_size );
|
found = icvCheckBoardMonotony( out_corners, pattern_size );
|
||||||
|
|
||||||
|
PRINTF("Chessboard detection result 2: %d\n", found);
|
||||||
|
|
||||||
// check that none of the found corners is too close to the image boundary
|
// check that none of the found corners is too close to the image boundary
|
||||||
if( found )
|
if( found )
|
||||||
{
|
{
|
||||||
@ -830,36 +730,38 @@ int cvFindChessboardCorners( const void* arr, CvSize pattern_size,
|
|||||||
found = k == pattern_size.width*pattern_size.height;
|
found = k == pattern_size.width*pattern_size.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( found && pattern_size.height % 2 == 0 && pattern_size.width % 2 == 0 )
|
PRINTF("Chessboard detection result 3: %d\n", found);
|
||||||
|
|
||||||
|
if( found )
|
||||||
{
|
{
|
||||||
|
if ( pattern_size.height % 2 == 0 && pattern_size.width % 2 == 0 )
|
||||||
|
{
|
||||||
int last_row = (pattern_size.height-1)*pattern_size.width;
|
int last_row = (pattern_size.height-1)*pattern_size.width;
|
||||||
double dy0 = out_corners[last_row].y - out_corners[0].y;
|
double dy0 = out_corners[last_row].y - out_corners[0].y;
|
||||||
if( dy0 < 0 )
|
if( dy0 < 0 )
|
||||||
{
|
{
|
||||||
int n = pattern_size.width*pattern_size.height;
|
int n = pattern_size.width*pattern_size.height;
|
||||||
for(int i = 0; i < n/2; i++ )
|
for(int i = 0; i < n/2; i++ )
|
||||||
{
|
{
|
||||||
CvPoint2D32f temp;
|
CvPoint2D32f temp;
|
||||||
CV_SWAP(out_corners[i], out_corners[n-i-1], temp);
|
CV_SWAP(out_corners[i], out_corners[n-i-1], temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cv::Ptr<CvMat> gray;
|
||||||
if( found )
|
if( CV_MAT_CN(img->type) != 1 )
|
||||||
{
|
{
|
||||||
cv::Ptr<CvMat> gray;
|
gray.reset(cvCreateMat(img->rows, img->cols, CV_8UC1));
|
||||||
if( CV_MAT_CN(img->type) != 1 )
|
cvCvtColor(img, gray, CV_BGR2GRAY);
|
||||||
{
|
}
|
||||||
gray.reset(cvCreateMat(img->rows, img->cols, CV_8UC1));
|
else
|
||||||
cvCvtColor(img, gray, CV_BGR2GRAY);
|
{
|
||||||
}
|
gray.reset(cvCloneMat(img));
|
||||||
else
|
}
|
||||||
{
|
int wsize = 2;
|
||||||
gray.reset(cvCloneMat(img));
|
cvFindCornerSubPix( gray, out_corners, pattern_size.width*pattern_size.height,
|
||||||
}
|
cvSize(wsize, wsize), cvSize(-1,-1),
|
||||||
int wsize = 2;
|
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 15, 0.1));
|
||||||
cvFindCornerSubPix( gray, out_corners, pattern_size.width*pattern_size.height,
|
|
||||||
cvSize(wsize, wsize), cvSize(-1,-1), cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 15, 0.1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(...)
|
catch(...)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user