Example for LED spot detector in images.
#include <bias_config.h>
#ifndef BIAS_HAVE_OPENCV
# error Please recompile BIAS with USE_OPENCV to use this code.
#endif
#include <Base/Common/W32Compat.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/ImageUtils/ImageDraw.hh>
#include <Base/Math/Vector2.hh>
#include <Base/Math/Vector3.hh>
#include <FeatureDetector/LEDDetector.hh>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace BIAS;
int main(int argc, char** argv)
{
if (argc < 2) {
cout << "Usage : ExampleLEDDetector <image> [-c <num>]" << endl
<< " -c <num> : Work on channel <num> of color image" << endl;
return 0;
}
cout << "Error : Failed to load image " << argv[1] << "!" << endl;
return -1;
}
if (argc > 2 && strcmp(argv[2], "-c") == 0) {
int channel = argc > 3 ? atoi(argv[3]) : 0;
if (channel < 0 || channel >= channels) {
cout << "Invalid channel " << channel << " given, ignoring option -c" << endl;
} else if (channels > 1) {
cout << "Working on channel " << channel << " of color image" << endl;
BIAS::ImageConvert::GetChannel<unsigned char>(image, channel);
}
}
std::vector<BIAS::Vector3<double> > pos;
std::vector<double> r(pos.size());
{
std::vector<double> minx, maxx, maxval;
BIASASSERT(minx.size() == pos.size() && maxx.size() == pos.size());
for (unsigned int i = 0; i < pos.size(); i++)
r[i] = 0.5 * (maxx[i] - minx[i]);
}
unsigned int i_center = 0;
double d_center = 1e8;
for (unsigned int i = 0; i < pos.size(); i++) {
if (d < d_center) {
i_center = i;
d_center = d;
}
}
unsigned char col[3] = { 0, 0, 0 };
cout << "Detected " << pos.size() << " LED spots : " << endl;
for (unsigned int i = 0; i < pos.size(); i++) {
cout << (i == i_center ? "X " : " ") << pos[i] << endl << flush;
if (i == i_center) col[0] = 255; else col[0] = 0;
CircleCenter(image, (
int)(pos[i][0]+0.5), (
int)(pos[i][1]+0.5), (
int)(r[i]+0.5), col);
}
const std::string filename = "ExampleLEDDetector.png";
cout << "Saved output image to " << filename << endl;
} else {
cout << "Error : Failed to write image to " << filename << "!" << endl;
return -1;
}
return 0;
}