Closed Phibedy closed 7 years ago
//#include <dlib/svm_threaded.h>
#include <dlib/string.h>
#include <dlib/image_processing.h>
#include <dlib/data_io.h>
#include <dlib/cmd_line_parser.h>
#include <iostream>
#include <fstream>
using namespace std;
using namespace dlib;
int main(int argc, char** argv)
{
try
{
command_line_parser parser;
parser.add_option("h","Display this help message.");
parser.add_option("u", "Upsample each input image <arg> times. Each upsampling quadruples the number of pixels in the image (default: 0).", 1);
parser.parse(argc, argv);
// Now we do a little command line validation. Each of the following functions
// checks something and throws an exception if the test fails.
const char* one_time_opts[] = {"h", "u"};
const string signs[] = {"30", "ped"};
int numSigns = sizeof(signs) / sizeof(signs[0]);
parser.check_one_time_options(one_time_opts); // Can't give an option more than once
// Make sure the arguments to these options are within valid ranges if they are supplied by the user.
parser.check_option_arg_range("u", 0, 8);
if (parser.option("h"))
{
cout << "Usage: train_object_detector [options] <image dataset file|image file>\n";
parser.print_options();
return EXIT_SUCCESS;
}
typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type;
// Get the upsample option from the user but use 0 if it wasn't given.
const unsigned long upsample_amount = get_option(parser, "u", 0);
if (parser.number_of_arguments() == 0)
{
cout << "You must give an image." << endl;
cout << "\nTry the -h option for more information." << endl;
return EXIT_FAILURE;
}
dlib::array<object_detector<image_scanner_type>> detectors;
detectors.resize(numSigns);
// load a previously trained object detector and try it out on some data
for(int i = 0; i < numSigns; i++){
ifstream fin(signs[i] + ".svm", ios::binary);
if (!fin)
{
cout << "Can't find a trained object detector file " + signs[i] + ".svm. " << endl;
return EXIT_FAILURE;
}
object_detector<image_scanner_type> det;
deserialize(det, fin);
detectors[i] = det;
}
dlib::array<array2d<unsigned char> > images;
images.resize(parser.number_of_arguments());
for (unsigned long i = 0; i < images.size(); ++i)
load_image(images[i], parser[i]);
// Upsample images if the user asked us to do that.
for (unsigned long i = 0; i < upsample_amount; ++i)
{
for (unsigned long j = 0; j < images.size(); ++j)
pyramid_up(images[j]);
}
// Test the detector on the images we loaded and display the results
// in a window.
for (unsigned long i = 0; i < images.size(); ++i)
{
// Run the detector on images[i]
for(int j = 0; j < numSigns; j++){
const std::vector<rectangle> rects = detectors[j](images[i]);
cout << "Number of " + signs[j] + " detections: "<< rects.size() << endl;
for(int k = 0; k < rects.size(); k++){
cout << rects[k] << endl;
}
}
// Put the image and detections into the window.
cout << "Hit enter to see the next image.";
cin.get();
}
}
catch (exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
cout << "\nTry the -h option for more information." << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
// ----------------------------------------------------------------------------------------
Hatte ich wohl schon mal programmiert: https://github.com/tum-phoenix/config_sign_detection
momentan ultra langsam
Mit cmake release compilieren und dann ist es "schnell genug" für die Präsentation
Das nachmachen mit den Schildern, die wir rumliegen haben: https://gist.github.com/iandees/f773749c47d088705199