|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
#include <dlib/dnn.h> |
|
#include <dlib/image_io.h> |
|
#include <dlib/gui_widgets.h> |
|
#include <dlib/image_processing.h> |
|
|
|
using namespace std; |
|
using namespace dlib; |
|
|
|
|
|
|
|
|
|
template <long num_filters, typename SUBNET> using con5d = con<num_filters,5,5,2,2,SUBNET>; |
|
template <long num_filters, typename SUBNET> using con5 = con<num_filters,5,5,1,1,SUBNET>; |
|
template <typename SUBNET> using downsampler = relu<affine<con5d<32, relu<affine<con5d<32, relu<affine<con5d<16,SUBNET>>>>>>>>>; |
|
template <typename SUBNET> using rcon5 = relu<affine<con5<55,SUBNET>>>; |
|
using net_type = loss_mmod<con<1,9,9,1,1,rcon5<rcon5<rcon5<downsampler<input_rgb_image_pyramid<pyramid_down<6>>>>>>>>; |
|
|
|
|
|
|
|
int main() try |
|
{ |
|
net_type net; |
|
shape_predictor sp; |
|
|
|
|
|
|
|
|
|
deserialize("mmod_front_and_rear_end_vehicle_detector.dat") >> net >> sp; |
|
|
|
matrix<rgb_pixel> img; |
|
load_image(img, "../mmod_cars_test_image2.jpg"); |
|
|
|
image_window win; |
|
win.set_image(img); |
|
|
|
|
|
for (auto&& d : net(img)) |
|
{ |
|
|
|
|
|
|
|
|
|
auto fd = sp(img,d); |
|
rectangle rect; |
|
for (unsigned long j = 0; j < fd.num_parts(); ++j) |
|
rect += fd.part(j); |
|
|
|
if (d.label == "rear") |
|
win.add_overlay(rect, rgb_pixel(255,0,0), d.label); |
|
else |
|
win.add_overlay(rect, rgb_pixel(255,255,0), d.label); |
|
} |
|
|
|
|
|
|
|
|
|
cout << "Hit enter to end program" << endl; |
|
cin.get(); |
|
} |
|
catch(image_load_error& e) |
|
{ |
|
cout << e.what() << endl; |
|
cout << "The test image is located in the examples folder. So you should run this program from a sub folder so that the relative path is correct." << endl; |
|
} |
|
catch(serialization_error& e) |
|
{ |
|
cout << e.what() << endl; |
|
cout << "The correct model file can be obtained from: http://dlib.net/files/mmod_front_and_rear_end_vehicle_detector.dat.bz2" << endl; |
|
} |
|
catch(std::exception& e) |
|
{ |
|
cout << e.what() << endl; |
|
} |
|
|
|
|
|
|
|
|
|
|