Skip to content

detect-video crashes because FaceDetector.get_face() only accepts file paths #17

Description

@timlac

Summary
Running openface detect-video results in an OpenCV error:

Error: OpenCV(4.11.0) :-1: error: (-5:Bad argument) in function 'imread'
> Expected 'filename' to be a str or path-like object

This happens because process_video() passes a numpy frame to FaceDetector.get_face(), but get_face() and detect_faces() assume the input is a file path, which leads to cv2.imread() being called on a numpy array.

How to Reproduce

openface detect-video path/to/video.mp4 --device cpu

Proposed Fix

Modify preprocess_image() in face_detection.py to allow either a file path or a numpy frame:

def preprocess_image(self, image_path, resize: float = 1.0):
    if isinstance(image_path, str):
        img_raw = cv2.imread(image_path, cv2.IMREAD_COLOR)
    else:
        # assume numpy BGR array from cv2.VideoCapture
        img_raw = image_path

    img = np.float32(img_raw)
    if resize != 1:
        img = cv2.resize(img, None, fx=resize, fy=resize, interpolation=cv2.INTER_LINEAR)
    img -= (104, 117, 123)
    img = img.transpose(2, 0, 1)
    img = torch.from_numpy(img).unsqueeze(0).to(self.device)
    return img, img_raw

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions