def __call__(self, image, greyscale=False, image_diagonal=None, group_prefix='dlib', n_upscales=0): r""" Perform a detection using the cached dlib detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. greyscale : `bool`, optional Convert the image to greyscale or not. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. n_upscales : `int`, optional Number of times to upscale the image when performing the detection, may increase the chances of detecting smaller objects. Returns ------ bounding_boxes : `list` of `menpo.shape.PointDirectedGraph` The detected objects. """ detect_partial = partial(self._detector, n_upscales=n_upscales) return detect(detect_partial, image, greyscale=greyscale, image_diagonal=image_diagonal, group_prefix=group_prefix)
def __call__(self, image, greyscale=True, image_diagonal=None, group_prefix='object', n_upscales=0): r""" Perform a detection using the cached dlib detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : menpo.image.Image A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. greyscale : bool, optional Convert the image to greyscale or not. image_diagonal : int, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : str, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. n_upscales : int, optional Number of times to upscale the image when performing the detection, may increase the chances of detecting smaller objects. Returns ------ bounding_boxes : menpo.shape.PointDirectedGraph The detected objects. """ detect_partial = partial(self._detector, n_upscales=n_upscales) return detect(detect_partial, image, greyscale=greyscale, image_diagonal=image_diagonal, group_prefix=group_prefix)
def __call__(self, image, greyscale=True, image_diagonal=None, group_prefix='ffld2', padding=6, interval=5, threshold=0.5, overlap=0.3): r""" Perform a detection using the cached ffdl2 detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. greyscale : `bool`, optional Whether to convert the image to greyscale or not. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. padding : `int`, optional Amount of zero padding in HOG cells interval : `int`, optional Number of levels per octave in the HOG pyramid threshold : `double`, optional Minimum detection threshold. Detections with a score less than this value are not returned. Values can be negative. overlap : `double`, optional Minimum overlap in in latent positive search and non-maxima suppression. As discussed in the Face Detection Without Bells and Whistles paper, a sensible value for overlap is 0.3 Returns ------ bounding_boxes : `menpo.shape.PointDirectedGraph` The detected objects. """ detect_partial = partial(self._detector, padding=padding, interval=interval, threshold=threshold, overlap=overlap) return detect(detect_partial, image, greyscale=greyscale, image_diagonal=image_diagonal, group_prefix=group_prefix)
def test_rescaling_image(): takeo_copy = takeo.copy() ratio = 200.0 / takeo_copy.diagonal() pcs = detect(fake_detector, takeo_copy, image_diagonal=200) assert len(pcs) == 1 assert takeo_copy.n_channels == 3 assert takeo_copy.landmarks['object_0'][None].n_points == 4 assert_allclose(takeo_copy.landmarks['object_0'][None].points, fake_box * (1.0 / ratio), atol=10e-2)
def test_rescaling_image(): takeo_copy = takeo.copy() ratio = 200.0 / takeo_copy.diagonal() pcs = detect(fake_detector, takeo_copy, image_diagonal=200) assert len(pcs) == 1 assert takeo_copy.n_channels == 3 assert takeo_copy.landmarks['object_0'].n_points == 4 assert_allclose(takeo_copy.landmarks['object_0'].points, fake_box * (1.0 / ratio), atol=10e-2)
def __call__(self, image, image_diagonal=None, group_prefix='opencv', scale_factor=1.1, min_neighbours=5, min_size=(30, 30), flags=cv2.cv.CV_HAAR_SCALE_IMAGE): r""" Perform a detection using the cached opencv detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. scale_factor : `float`, optional The amount to increase the sliding windows by over the second pass. min_neighbours : `int`, optional The minimum number of neighbours (close detections) before Non-Maximum suppression to be considered a detection. Use 0 to return all detections. min_size : `tuple` of 2 ints The minimum object size in pixels that the detector will consider. flags : `int`, optional The flags to be passed through to the detector. Returns ------ bounding_boxes : `menpo.shape.PointDirectedGraph` The detected objects. """ detect_partial = partial(self._detector, scale_factor=scale_factor, min_neighbours=min_neighbours, min_size=min_size, flags=flags) return detect(detect_partial, image, greyscale=True, image_diagonal=image_diagonal, group_prefix=group_prefix)
def __call__( self, image, image_diagonal=None, group_prefix="opencv", scale_factor=1.1, min_neighbours=5, min_size=(30, 30), flags=None, ): r""" Perform a detection using the cached opencv detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. scale_factor : `float`, optional The amount to increase the sliding windows by over the second pass. min_neighbours : `int`, optional The minimum number of neighbours (close detections) before Non-Maximum suppression to be considered a detection. Use 0 to return all detections. min_size : `tuple` of 2 ints The minimum object size in pixels that the detector will consider. flags : `int`, optional The flags to be passed through to the detector. Returns ------ bounding_boxes : `list` of `menpo.shape.PointDirectedGraph` The detected objects. """ if flags is None: flags = _get_default_flags() detect_partial = partial( self._detector, scale_factor=scale_factor, min_neighbours=min_neighbours, min_size=min_size, flags=flags ) return detect(detect_partial, image, greyscale=True, image_diagonal=image_diagonal, group_prefix=group_prefix)
def __call__(self, image, greyscale=False, image_diagonal=None, group_prefix='bob', threshold=20, minimum_overlap=0.2): r""" Perform a detection using the cached bob detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. greyscale : `bool`, optional Convert the image to greyscale or not. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. threshold : `float`, optional The threshold of the quality of detected faces. Detections with a quality lower than this value will not be considered. Higher thresholds will not detect all faces, while lower thresholds will generate false detections. ``minimum_overlap`` : `float` ``[0, 1]`` Computes the best detection using the given minimum overlap. Returns ------ bounding_boxes : `list` of `menpo.shape.PointDirectedGraph` The detected objects. """ detect_partial = partial(self._detector, threshold=threshold, minimum_overlap=minimum_overlap) return detect(detect_partial, image, greyscale=greyscale, image_diagonal=image_diagonal, group_prefix=group_prefix, channels_at_back=False)
def __call__(self, image, greyscale=True, image_diagonal=None, group_prefix='ffld2', padding=6, interval=5, threshold=0.5, overlap=0.3): r""" Perform a detection using the cached ffdl2 detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. greyscale : `bool`, optional Whether to convert the image to greyscale or not. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. padding : `int`, optional Amount of zero padding in HOG cells interval : `int`, optional Number of levels per octave in the HOG pyramid threshold : `double`, optional Minimum detection threshold. Detections with a score less than this value are not returned. Values can be negative. overlap : `double`, optional Minimum overlap in in latent positive search and non-maxima suppression. As discussed in the Face Detection Without Bells and Whistles paper, a sensible value for overlap is 0.3 Returns ------ bounding_boxes : `list` of `menpo.shape.PointDirectedGraph` The detected objects. """ detect_partial = partial(self._detector, padding=padding, interval=interval, threshold=threshold, overlap=overlap) return detect(detect_partial, image, greyscale=greyscale, image_diagonal=image_diagonal, group_prefix=group_prefix)
def test_passing_uint8_rgb_image_greyscale_no_convert(): fake_image = MagicMock() fake_image.n_channels = 3 pcs = detect(fake_detector, fake_image, greyscale=True) assert len(pcs) == 1 fake_image.as_greyscale.assert_called_once_with(mode='luminosity')
def test_passing_uint8_image(): takeo_copy = takeo_uint8.copy() pcs = detect(fake_detector, takeo_copy, greyscale=False) assert len(pcs) == 1 assert takeo_copy.n_channels == 3 assert takeo_copy.landmarks['object_0'][None].n_points == 4
def __call__(self, image, image_diagonal=None, group_prefix='object', max_detections=100, orientations=0.0, scale_factor=1.2, stride_factor=0.1, min_size=100, confidence_cutoff=3.0): r""" Perform a detection using the cached pico detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : menpo.image.Image A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. image_diagonal : int, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : str, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. max_detections : `int`, optional The maximum number of detections to return. orientations : list of `float`s or `float`, optional The orientations of the cascades to use. ``0.0`` will perform an axis aligned detection. Values greater than ``0.0`` will perform detections of the cascade rotated counterclockwise around a unit circle. If a list is passed, each item should be an orientation in radians around the unit circle, with ``0.0`` being axis aligned. scale_factor : `float`, optional The ratio to increase the cascade window at every iteration. Must be greater than 1.0 stride_factor : `float`, optional The ratio to decrease the window step by at every iteration. Must be less than 1.0, optional min_size : `float`, optional The minimum size in pixels (diameter of the detection circle) that a face can be. This is the starting cascade window size. confidence_cutoff : `float`, optional The confidence value to trim the detections with. Any detections with confidence less than the cutoff will be discarded. Returns ------ bounding_boxes : menpo.shape.PointDirectedGraph The detected objects. """ detect_partial = partial(self._detector, max_detections=max_detections, orientations=orientations, scale_factor=scale_factor, stride_factor=stride_factor, min_size=min_size, confidence_cutoff=confidence_cutoff) return detect(detect_partial, image, greyscale=True, image_diagonal=image_diagonal, group_prefix=group_prefix)
def test_passing_uint8_image_greyscale_raises(): takeo_copy = takeo_uint8.copy() pcs = detect(fake_detector, takeo_copy, greyscale=True)
def __call__(self, image, image_diagonal=None, group_prefix='pico', max_detections=100, orientations=0.0, degrees=True, scale_factor=1.2, stride_factor=0.1, min_size=100, confidence_cutoff=3.0, axis_aligned_bb=True): r""" Perform a detection using the cached pico detector. The detections will also be attached to the image as landmarks. Parameters ---------- image : `menpo.image.Image` A Menpo image to detect. The bounding boxes of the detected objects will be attached to this image. image_diagonal : `int`, optional The total size of the diagonal of the image that should be used for detection. This is useful for scaling images up and down for detection. group_prefix : `str`, optional The prefix string to be appended to each each landmark group that is stored on the image. Each detection will be stored as group_prefix_# where # is a count starting from 0. max_detections : `int`, optional The maximum number of detections to return. orientations : list of `float`s or `float`, optional The orientations of the cascades to use. ``0.0`` will perform an axis aligned detection. Values greater than ``0.0`` will perform detections of the cascade rotated counterclockwise around a unit circle. If a list is passed, each item should be an orientation in either radians or degrees around the unit circle, with ``0.0`` being axis aligned. degrees : `bool`, optional If ``True``, the ``orientations`` parameter is treated as rotations counterclockwise in degrees rather than radians. scale_factor : `float`, optional The ratio to increase the cascade window at every iteration. Must be greater than 1.0 stride_factor : `float`, optional The ratio to decrease the window step by at every iteration. Must be less than 1.0, optional min_size : `float`, optional The minimum size in pixels (diameter of the detection circle) that a face can be. This is the starting cascade window size. confidence_cutoff : `float`, optional The confidence value to trim the detections with. Any detections with confidence less than the cutoff will be discarded. axis_aligned_bb : `bool`, optional If ``True``, the returned detections will be axis aligned, regardless of which orientation they were detected at. If ``False``, the returned bounding box will be rotated by the orientation detected. Returns ------ bounding_boxes : `list` of `menpo.shape.PointDirectedGraph` The detected objects. """ if degrees: # Cypico expects Radians orientations = np.deg2rad(orientations) detect_partial = partial(self._detector, max_detections=max_detections, orientations=orientations, scale_factor=scale_factor, stride_factor=stride_factor, min_size=min_size, confidence_cutoff=confidence_cutoff, axis_aligned_bb=axis_aligned_bb) return detect(detect_partial, image, greyscale=True, image_diagonal=image_diagonal, group_prefix=group_prefix)
def test_passing_uint8_image(): takeo_copy = takeo_uint8.copy() pcs = detect(fake_detector, takeo_copy, greyscale=False) assert len(pcs) == 1 assert takeo_copy.n_channels == 3 assert takeo_copy.landmarks['object_0'].n_points == 4
def test_passing_uint8_image_greyscale(): takeo_copy = takeo_uint8.copy() pcs = detect(fake_detector, takeo_copy, greyscale=True) assert len(pcs) == 1
def test_passing_uint8_greyscale_image_greyscale_pass_through(): fake_image = MagicMock() fake_image.n_channels = 1 pcs = detect(fake_detector, fake_image, greyscale=True) assert len(pcs) == 1 fake_image.as_greyscale.assert_not_called()