Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
michaellee1019 opened this issue Jan 29, 2024 · 1 comment
Open

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

michaellee1019 opened this issue Jan 29, 2024 · 1 comment
Labels
state:triage We're still figuring out how severe this issue is

Comments

@michaellee1019
Copy link

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.

@michaellee1019 michaellee1019 added the state:triage We're still figuring out how severe this issue is label Jan 29, 2024
@rokm
Copy link
Member

rokm commented Jan 29, 2024

Strictly speaking, it is deepface that is trying to load the cascade file, not OpenCV itself:
https://github.com/serengil/deepface/blob/35025cdf6e4e2fc0642b890dc7dd589b7cb37205/deepface/detectors/OpenCv.py#L128-L156

And since the .xml files in cv2/data total 9MB, I don't think it is good idea to have them collected by default. If anything, this should be a job for deepface.detector.OpenCv hook (and even that should collect only the two files that it actually uses).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:triage We're still figuring out how severe this issue is
Projects
None yet
Development

No branches or pull requests

2 participants