Subversion Repositories seema-scanner

Rev

Rev 42 | Rev 50 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 42 Rev 49
Line 6... Line 6...
6
 
6
 
7
#include <stdio.h>
7
#include <stdio.h>
8
 
8
 
9
namespace cvtools{
9
namespace cvtools{
10
 
10
 
-
 
11
// Lightly modified OpenCV function which accepts a line width argument
-
 
12
void drawChessboardCorners(cv::InputOutputArray _image, Size patternSize, cv::InputArray _corners, bool patternWasFound, int line_width=1){
-
 
13
    Mat corners = _corners.getMat();
-
 
14
    if( corners.empty() )
-
 
15
        return;
-
 
16
    Mat image = _image.getMat(); CvMat c_image = _image.getMat();
-
 
17
    int nelems = corners.checkVector(2, CV_32F, true);
-
 
18
    CV_Assert(nelems >= 0);
-
 
19
    cvDrawChessboardCorners( &c_image, patternSize, (CvPoint2D32f*)corners.data,
-
 
20
                             nelems, patternWasFound, line_width);
-
 
21
}
-
 
22
 
-
 
23
void cvDrawChessboardCorners(CvArr* _image, CvSize pattern_size, CvPoint2D32f* corners, int count, int found, int line_width=1){
-
 
24
    const int shift = 0;
-
 
25
    const int radius = 4;
-
 
26
    const int r = radius*(1 << shift);
-
 
27
    int i;
-
 
28
    CvMat stub, *image;
-
 
29
    double scale = 1;
-
 
30
    int type, cn, line_type;
-
 
31
 
-
 
32
    image = cvGetMat( _image, &stub );
-
 
33
 
-
 
34
    type = CV_MAT_TYPE(image->type);
-
 
35
    cn = CV_MAT_CN(type);
-
 
36
    if( cn != 1 && cn != 3 && cn != 4 )
-
 
37
        CV_Error( CV_StsUnsupportedFormat, "Number of channels must be 1, 3 or 4" );
-
 
38
 
-
 
39
    switch( CV_MAT_DEPTH(image->type) )
-
 
40
    {
-
 
41
    case CV_8U:
-
 
42
        scale = 1;
-
 
43
        break;
-
 
44
    case CV_16U:
-
 
45
        scale = 256;
-
 
46
        break;
-
 
47
    case CV_32F:
-
 
48
        scale = 1./255;
-
 
49
        break;
-
 
50
    default:
-
 
51
        CV_Error( CV_StsUnsupportedFormat,
-
 
52
            "Only 8-bit, 16-bit or floating-point 32-bit images are supported" );
-
 
53
    }
-
 
54
 
-
 
55
    line_type = type == CV_8UC1 || type == CV_8UC3 ? CV_AA : 8;
-
 
56
 
-
 
57
    if( !found )
-
 
58
    {
-
 
59
        CvScalar color = {{0,0,255}};
-
 
60
        if( cn == 1 )
-
 
61
            color = cvScalarAll(200);
-
 
62
        color.val[0] *= scale;
-
 
63
        color.val[1] *= scale;
-
 
64
        color.val[2] *= scale;
-
 
65
        color.val[3] *= scale;
-
 
66
 
-
 
67
        for( i = 0; i < count; i++ )
-
 
68
        {
-
 
69
            CvPoint pt;
-
 
70
            pt.x = cvRound(corners[i].x*(1 << shift));
-
 
71
            pt.y = cvRound(corners[i].y*(1 << shift));
-
 
72
            cvLine( image, cvPoint( pt.x - r, pt.y - r ),
-
 
73
                    cvPoint( pt.x + r, pt.y + r ), color, 1, line_type, shift );
-
 
74
            cvLine( image, cvPoint( pt.x - r, pt.y + r),
-
 
75
                    cvPoint( pt.x + r, pt.y - r), color, 1, line_type, shift );
-
 
76
            cvCircle( image, pt, r+(1<<shift), color, 1, line_type, shift );
-
 
77
        }
-
 
78
    }
-
 
79
    else
-
 
80
    {
-
 
81
        int x, y;
-
 
82
        CvPoint prev_pt = {0, 0};
-
 
83
        const int line_max = 7;
-
 
84
        static const CvScalar line_colors[line_max] =
-
 
85
        {
-
 
86
            {{0,0,255}},
-
 
87
            {{0,128,255}},
-
 
88
            {{0,200,200}},
-
 
89
            {{0,255,0}},
-
 
90
            {{200,200,0}},
-
 
91
            {{255,0,0}},
-
 
92
            {{255,0,255}}
-
 
93
        };
-
 
94
 
-
 
95
        for( y = 0, i = 0; y < pattern_size.height; y++ )
-
 
96
        {
-
 
97
            CvScalar color = line_colors[y % line_max];
-
 
98
            if( cn == 1 )
-
 
99
                color = cvScalarAll(200);
-
 
100
            color.val[0] *= scale;
-
 
101
            color.val[1] *= scale;
-
 
102
            color.val[2] *= scale;
-
 
103
            color.val[3] *= scale;
-
 
104
 
-
 
105
            for( x = 0; x < pattern_size.width; x++, i++ )
-
 
106
            {
-
 
107
                CvPoint pt;
-
 
108
                pt.x = cvRound(corners[i].x*(1 << shift));
-
 
109
                pt.y = cvRound(corners[i].y*(1 << shift));
-
 
110
 
-
 
111
                if( i != 0 )
-
 
112
                    cvLine( image, prev_pt, pt, color, 1, line_type, shift );
-
 
113
 
-
 
114
                cvLine( image, cvPoint(pt.x - r, pt.y - r),
-
 
115
                        cvPoint(pt.x + r, pt.y + r), color, 1, line_type, shift );
-
 
116
                cvLine( image, cvPoint(pt.x - r, pt.y + r),
-
 
117
                        cvPoint(pt.x + r, pt.y - r), color, 1, line_type, shift );
-
 
118
                cvCircle( image, pt, r+(1<<shift), color, 1, line_type, shift );
-
 
119
                prev_pt = pt;
-
 
120
            }
-
 
121
        }
-
 
122
    }
-
 
123
}
-
 
124
 
11
// Convert a 3xN matrix to a vector of Point3fs.
125
// Convert a 3xN matrix to a vector of Point3fs.
12
void matToPoints3f(const cv::Mat &mat, std::vector<cv::Point3f> &points){
126
void matToPoints3f(const cv::Mat &mat, std::vector<cv::Point3f> &points){
13
 
127
 
14
    unsigned int nPoints = mat.cols;
128
    unsigned int nPoints = mat.cols;
15
    points.resize(nPoints);
129
    points.resize(nPoints);