Skip to content

Commit

Permalink
Fixed converting image to grayscale when image is not RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelVRossi committed Jan 4, 2023
1 parent 3947e4e commit 4d8aae4
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion remotecv/detectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ def get_features(self, image):

def get_grayscale_equalized_features(self, image):
img = self.get_np_img(image)
img_equalized = cv2.equalizeHist(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY))

if image.mode.upper() not in ["L", "1"]:
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

img_equalized = cv2.equalizeHist(img)

return self.get_faces(img_equalized, image.size)

Expand Down
Binary file added tests/fixtures/one_face-bw-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/one_face-bw-la.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/one_face-bw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/fixtures/one_face-p.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions tests/test_face_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,24 @@ def test_should_run_on_images_with_alpha(self):
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
expect(detection_result[0][3]).to_be_numeric()

def test_should_run_on_images_with_mode_l(self):
detection_result = FaceDetector().detect(create_image("one_face-bw.png"))
expect(detection_result[0][0]).to_be_numeric()
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
expect(detection_result[0][3]).to_be_numeric()

def test_should_run_on_images_with_mode_1(self):
detection_result = FaceDetector().detect(create_image("one_face-bw-1.png"))
expect(detection_result[0][0]).to_be_numeric()
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
expect(detection_result[0][3]).to_be_numeric()

def test_should_run_on_images_with_mode_la(self):
detection_result = FaceDetector().detect(create_image("one_face-bw-la.png"))
expect(detection_result[0][0]).to_be_numeric()
expect(detection_result[0][1]).to_be_numeric()
expect(detection_result[0][2]).to_be_numeric()
expect(detection_result[0][3]).to_be_numeric()

0 comments on commit 4d8aae4

Please sign in to comment.