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

Function main

examples/image_ex.cpp:26–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24// ----------------------------------------------------------------------------
25
26int main(int argc, char** argv)
27{
28 try
29 {
30 // make sure the user entered an argument to this program
31 if (argc != 2)
32 {
33 cout << "error, you have to enter a BMP file as an argument to this program" << endl;
34 return 1;
35 }
36
37 // Here we declare an image object that can store rgb_pixels. Note that in
38 // dlib there is no explicit image object, just a 2D array and
39 // various pixel types.
40 array2d<rgb_pixel> img;
41
42 // Now load the image file into our image. If something is wrong then
43 // load_image() will throw an exception. Also, if you linked with libpng
44 // and libjpeg then load_image() can load PNG and JPEG files in addition
45 // to BMP files.
46 load_image(img, argv[1]);
47
48
49 // Now let's use some image functions. First let's blur the image a little.
50 array2d<unsigned char> blurred_img;
51 gaussian_blur(img, blurred_img);
52
53 // Now find the horizontal and vertical gradient images.
54 array2d<short> horz_gradient, vert_gradient;
55 array2d<unsigned char> edge_image;
56 sobel_edge_detector(blurred_img, horz_gradient, vert_gradient);
57
58 // now we do the non-maximum edge suppression step so that our edges are nice and thin
59 suppress_non_maximum_edges(horz_gradient, vert_gradient, edge_image);
60
61 // Now we would like to see what our images look like. So let's use a
62 // window to display them on the screen. (Note that you can zoom into
63 // the window by holding CTRL and scrolling the mouse wheel)
64 image_window my_window(edge_image, "Normal Edge Image");
65
66 // We can also easily display the edge_image as a heatmap or using the jet color
67 // scheme like so.
68 image_window win_hot(heatmap(edge_image));
69 image_window win_jet(jet(edge_image));
70
71 // also make a window to display the original image
72 image_window my_window2(img, "Original Image");
73
74 // Sometimes you want to get input from the user about which pixels are important
75 // for some task. You can do this easily by trapping user clicks as shown below.
76 // This loop executes every time the user double clicks on some image pixel and it
77 // will terminate once the user closes the window.
78 point p;
79 while (my_window.get_next_double_click(p))
80 {
81 cout << "User double clicked on pixel: " << p << endl;
82 cout << "edge pixel value at this location is: " << (int)edge_image[p.y()][p.x()] << endl;
83 }

Callers

nothing calls this directly

Calls 10

gaussian_blurFunction · 0.85
sobel_edge_detectorFunction · 0.85
heatmapFunction · 0.85
jetFunction · 0.85
get_next_double_clickMethod · 0.80
load_imageFunction · 0.50
nrMethod · 0.45
ncMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected