-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmrgingham_pywrap_cplusplus_bridge.cc
134 lines (116 loc) · 6.04 KB
/
mrgingham_pywrap_cplusplus_bridge.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "find_chessboard_corners.hh"
#include "find_blobs.hh"
#include "mrgingham.hh"
#include "mrgingham_pywrap_cplusplus_bridge.h"
#include "mrgingham-internal.h"
// These are wrappers. And the reason this file exists at all is because
// mrgingham has a c++ api, while the python wrappers are in C. AND there's
// another complicating factor: on CentOS7.2 if I build a C++ thing that talks
// to numpy it barfs:
//
// g++ -Wall -Wextra -std=gnu99 -Wno-cast-function-type -I/usr/include/opencv -fvisibility=hidden -Wno-unused-function -Wno-missing-field-initializers -Wno-unused-parameter -Wno-strict-aliasing -Wno-int-to-pointer-cast -Wno-unused-variable -MMD -MP -g -fno-omit-frame-pointer -DVERSION='"1.1"' -pthread -fno-strict-aliasing -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/include/python2.7 -O3 -c -o/dev/null mrgingham_pywrap_cplusplus_bridge.cc |& head -n 50
// cc1plus: warning: command line option '-std=gnu99' is valid for C/ObjC but not for C++ [enabled by default]
// In file included from /usr/include/numpy/ndarraytypes.h:7:0,
// from /usr/include/numpy/ndarrayobject.h:17,
// from /usr/include/numpy/arrayobject.h:15,
// from mrgingham_pywrap_cplusplus_bridge.cc:5:
// /usr/include/numpy/npy_common.h:188:2: error: #error Must use Python with unicode enabled.
// #error Must use Python with unicode enabled.
// ^
//
// As a result, this file doesn't touch Python, and does stuff with callbacks.
// Yuck. Callbacks will make stuff slower. With a newer distro, the python
// unicode thing maybe isn't a problem. You can revert the commit on 2019/3/25
// if you want to try it again
extern "C"
bool find_chessboard_corners_from_image_array_C( // in
int Nrows, int Ncols,
int stride,
char* imagebuffer, // this is const
// set to 0 to just use the image. Set
// to <0 to try automatically find a
// good scaling level. Try this first
int image_pyramid_level,
bool doblobs,
bool debug,
bool (*add_points)(int* xy, int N, double scale) )
{
cv::Mat cvimage(Nrows, Ncols, CV_8UC1,
imagebuffer, stride);
std::vector<mrgingham::PointInt> out_points;
bool result;
if(doblobs)
{
if(image_pyramid_level != 0)
return false;
result = find_blobs_from_image_array( &out_points, cvimage );
}
else
{
result = find_chessboard_corners_from_image_array( &out_points, cvimage, image_pyramid_level,
debug );
}
if( !result ) return false;
static_assert( sizeof(mrgingham::PointInt) == 2*sizeof(int),
"add_points() assumes PointInt is simply 2 ints");
return
(*add_points)( &out_points[0].x, (int)out_points.size(),
1. / (double)FIND_GRID_SCALE);
}
extern "C"
bool find_chessboard_from_image_array_C( // in
int Nrows, int Ncols,
int stride,
char* imagebuffer, // this is const
const int gridn,
// set to 0 to just use the image. Set
// to <0 to try automatically find a
// good scaling level. Try this first
int image_pyramid_level,
bool doblobs,
bool debug,
int debug_sequence_x,
int debug_sequence_y,
bool (*add_points)(double* xy, int N) )
{
cv::Mat cvimage(Nrows, Ncols, CV_8UC1,
imagebuffer, stride);
std::vector<mrgingham::PointDouble> out_points;
mrgingham::debug_sequence_t debug_sequence = {};
if(debug_sequence_x >= 0 &&
debug_sequence_y >= 0)
{
debug_sequence.dodebug = true;
debug_sequence.pt.x = debug_sequence_x;
debug_sequence.pt.y = debug_sequence_y;
}
bool result;
if(doblobs)
{
if(image_pyramid_level != 0)
return false;
result = find_circle_grid_from_image_array(out_points,
cvimage, gridn,
debug,
debug_sequence);
}
else
{
signed char* refinement_level = NULL;
result =
(find_chessboard_from_image_array( out_points,
&refinement_level,
gridn,
cvimage,
image_pyramid_level,
debug,
debug_sequence,
NULL ) >= 0);
free(refinement_level);
}
if( !result ) return false;
static_assert( sizeof(mrgingham::PointDouble) == 2*sizeof(double),
"add_points() assumes PointDouble is simply 2 doubles");
return
(*add_points)( &out_points[0].x, (int)out_points.size() );
}