25 #include <bias_config.h>
26 #ifndef BIAS_HAVE_OPENCV
27 # error Please recompile BIAS with USE_OPENCV to use this code.
29 #include <Base/Common/W32Compat.hh>
30 #include <Base/Image/Image.hh>
31 #include <Base/Image/ImageConvert.hh>
32 #include <Base/Image/ImageIO.hh>
33 #include <Base/ImageUtils/ImageDraw.hh>
34 #include <Base/Math/Vector2.hh>
35 #include <Base/Math/Vector3.hh>
36 #include <FeatureDetector/LEDDetector.hh>
51 int main(
int argc,
char** argv)
54 cout <<
"Usage : ExampleLEDDetector <image> [-c <num>]" << endl
55 <<
" -c <num> : Work on channel <num> of color image" << endl;
62 cout <<
"Error : Failed to load image " << argv[1] <<
"!" << endl;
67 if (argc > 2 && strcmp(argv[2],
"-c") == 0) {
68 int channel = argc > 3 ? atoi(argv[3]) : 0;
70 if (channel < 0 || channel >= channels) {
71 cout <<
"Invalid channel " << channel <<
" given, ignoring option -c" << endl;
72 }
else if (channels > 1) {
73 cout <<
"Working on channel " << channel <<
" of color image" << endl;
74 BIAS::ImageConvert::GetChannel<unsigned char>(image, channel);
80 std::vector<BIAS::Vector3<double> > pos;
84 std::vector<double> r(pos.size());
86 std::vector<double> minx, maxx, maxval;
88 BIASASSERT(minx.size() == pos.size() && maxx.size() == pos.size());
89 for (
unsigned int i = 0; i < pos.size(); i++)
90 r[i] = 0.5 * (maxx[i] - minx[i]);
94 unsigned int i_center = 0;
95 double d_center = 1e8;
97 for (
unsigned int i = 0; i < pos.size(); i++) {
106 unsigned char col[3] = { 0, 0, 0 };
107 cout <<
"Detected " << pos.size() <<
" LED spots : " << endl;
108 for (
unsigned int i = 0; i < pos.size(); i++) {
109 cout << (i == i_center ?
"X " :
" ") << pos[i] << endl << flush;
110 if (i == i_center) col[0] = 255;
else col[0] = 0;
114 CircleCenter(image, (
int)(pos[i][0]+0.5), (
int)(pos[i][1]+0.5), (
int)(r[i]+0.5), col);
118 const std::string filename =
"ExampleLEDDetector.png";
120 cout <<
"Saved output image to " << filename << endl;
122 cout <<
"Error : Failed to write image to " << filename <<
"!" << endl;
int Compute(const BIAS::Image< unsigned char > &image, std::vector< BIAS::Vector3< double > > &results)
Detect LED spots in image.
void GetAttributes(std::vector< double > &minX, std::vector< double > &maxX, std::vector< double > &maxValues)
Return attributes of detected LED spots.
static int CircleCenterFilled(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[])
draws a filled circle using Value
unsigned int GetWidth() const
This class contains methods to detect (IR)-LED-Spots, with template matching (new search) or in "recy...
static int CircleCenter(Image< StorageType > &im, unsigned int CenterX, unsigned int CenterY, unsigned int Radius, const StorageType Value[]=NULL)
draws a circular line, either using Value or a good contrast value
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...