MCPcopy Create free account
hub / github.com/davisking/dlib / main

Function main

examples/fhog_ex.cpp:29–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27// ----------------------------------------------------------------------------
28
29int main(int argc, char** argv)
30{
31 try
32 {
33 // Make sure the user entered an argument to this program. It should be the
34 // filename for an image.
35 if (argc != 2)
36 {
37 cout << "error, you have to enter a BMP file as an argument to this program" << endl;
38 return 1;
39 }
40
41 // Here we declare an image object that can store color rgb_pixels.
42 array2d<rgb_pixel> img;
43
44 // Now load the image file into our image. If something is wrong then
45 // load_image() will throw an exception. Also, if you linked with libpng
46 // and libjpeg then load_image() can load PNG and JPEG files in addition
47 // to BMP files.
48 load_image(img, argv[1]);
49
50
51 // Now convert the image into a FHOG feature image. The output, hog, is a 2D array
52 // of 31 dimensional vectors.
53 array2d<matrix<float,31,1> > hog;
54 extract_fhog_features(img, hog);
55
56 cout << "hog image has " << hog.nr() << " rows and " << hog.nc() << " columns." << endl;
57
58 // Let's see what the image and FHOG features look like.
59 image_window win(img);
60 image_window winhog(draw_fhog(hog));
61
62 // Another thing you might want to do is map between the pixels in img and the
63 // cells in the hog image. dlib provides the image_to_fhog() and fhog_to_image()
64 // routines for this. Their use is demonstrated in the following loop which
65 // responds to the user clicking on pixels in the image img.
66 point p; // A 2D point, used to represent pixel locations.
67 while (win.get_next_double_click(p))
68 {
69 point hp = image_to_fhog(p);
70 cout << "The point " << p << " in the input image corresponds to " << hp << " in hog space." << endl;
71 cout << "FHOG features at this point: " << trans(hog[hp.y()][hp.x()]) << endl;
72 }
73
74 // Finally, sometimes you want to get a planar representation of the HOG features
75 // rather than the explicit vector (i.e. interlaced) representation used above.
76 dlib::array<array2d<float> > planar_hog;
77 extract_fhog_features(img, planar_hog);
78 // Now we have an array of 31 float valued image planes, each representing one of
79 // the dimensions of the HOG feature vector.
80 }
81 catch (exception& e)
82 {
83 cout << "exception thrown: " << e.what() << endl;
84 }
85}
86

Callers

nothing calls this directly

Calls 9

extract_fhog_featuresFunction · 0.85
image_to_fhogFunction · 0.85
get_next_double_clickMethod · 0.80
load_imageFunction · 0.50
draw_fhogFunction · 0.50
transFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected