Skip to content

OpenCV missing data files in /cv2/data directory #695

Description

@michaellee1019

Describe the bug
It seems that the data files placed into /cv2/data directory are not being included by PyInstaller. The files are defined in https://github.com/opencv/opencv/tree/master/data/haarcascades and currently an --add-data argument is required in order for the executable to run.

I am technically using Deepface on top of OpenCV but feel like its an issue with the cv2 hook given that the files are included at the Open CV level.

Seems like the existing hook could just include cv2/data/ directory https://github.com/pyinstaller/pyinstaller-hooks-contrib/blob/master/src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-cv2.py#L51 ?

  • Which hook/library isn't working? cv2
  • Does the error get raised while building or when running? running

To Reproduce

A minimal example file:

from deepface import DeepFace
results = DeepFace.extract_faces(img_path=numpy.array(image.convert('RGB')),enforce_detection=False, detector_backend='ssd')
print(results)

PyInstaller command:
Using this command resolves the issue

python3 -m PyInstaller --add-data /root/project/.venv/lib/python3.11/site-packages/cv2/data:cv2/data src/main.py

Error:

ValueError - ('Confirm that opencv is installed on your environment! Expected path ', '/tmp/_MEIIkBAm6/cv2/data/haarcascade_frontalface_default.xml', ' violated.') - file_name='deepface/detectors/OpenCv.py' func_name='__build_cascade' line_num=145

Expected behavior
Would like hooks to handle this instead of needing a --add-data argument

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: linux-arm64, linux-amd64, darwin-arm64
  • Python Version: python 3.11
  • Version of pyinstaller-hooks-contrib: 2024.0
  • Version of PyInstaller: 6.3.0

Additional context
I can provide a repository with a full working example if required.

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:triageWe're still figuring out how severe this issue is

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions