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

Method detect

tools/python/src/cnn_face_detector.cpp:29–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 }
28
29 std::vector<mmod_rect> detect (
30 py::array pyimage,
31 const int upsample_num_times
32 )
33 {
34 pyramid_down<2> pyr;
35 std::vector<mmod_rect> rects;
36
37 // Copy the data into dlib based objects
38 matrix<rgb_pixel> image;
39 if (is_image<unsigned char>(pyimage))
40 assign_image(image, numpy_image<unsigned char>(pyimage));
41 else if (is_image<rgb_pixel>(pyimage))
42 assign_image(image, numpy_image<rgb_pixel>(pyimage));
43 else
44 throw dlib::error("Unsupported image type, must be 8bit gray or RGB image.");
45
46 // Upsampling the image will allow us to detect smaller faces but will cause the
47 // program to use more RAM and run longer.
48 unsigned int levels = upsample_num_times;
49 while (levels > 0)
50 {
51 levels--;
52 pyramid_up(image, pyr);
53 }
54
55 std::lock_guard<std::mutex> lock(net_mutex);
56 auto dets = net(image);
57
58 // Scale the detection locations back to the original image size
59 // if the image was upscaled.
60 for (auto&& d : dets) {
61 d.rect = pyr.rect_down(d.rect, upsample_num_times);
62 rects.push_back(d);
63 }
64
65 return rects;
66 }
67
68 std::vector<std::vector<mmod_rect>> detect_mult (
69 py::list imgs,

Callers

nothing calls this directly

Calls 5

errorClass · 0.85
pyramid_upFunction · 0.85
assign_imageFunction · 0.50
rect_downMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected