Better use of absolute paths for portability
This commit is contained in:
parent
b3a0e4035b
commit
b3b407a99e
6 changed files with 26 additions and 16 deletions
5
.vscode/launch.json
vendored
5
.vscode/launch.json
vendored
|
@ -17,8 +17,9 @@
|
|||
"request": "launch",
|
||||
"program": "mirror.py",
|
||||
"args": [
|
||||
"--fullscreen",
|
||||
"--camera", "4",
|
||||
// "--windowed",
|
||||
"--output", "/tmp/face_saves",
|
||||
"--camera", "0",
|
||||
],
|
||||
"console": "integratedTerminal"
|
||||
}
|
||||
|
|
|
@ -33,4 +33,6 @@ The installation in Windows can be done, though it is quite elaborate:
|
|||
* `cargo build --lib --release`
|
||||
+ Download dll from https://git.rubenvandeven.com/r/visualhaar/releases
|
||||
+ Make the installer:
|
||||
* `build_exe.bat`
|
||||
* `& 'C:\Users\DP Medialab\AppData\Roaming\Python\Python38\Scripts\pyinstaller.exe' .\mirror.py --add-binary '.\visualhaar\target\release\visual_haarcascades_lib.dll;.' --add-data '.\haarcascade_frontalface_alt2.xml;.' --add-data '.\SourceSansPro-Regular.ttf;.' --add-data 'dnn;dnn'`
|
||||
* `mv '.\dist\mirror\mpl-data' '.\dist\mirror\matplotlib\'`
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
& 'C:\Users\DP Medialab\AppData\Roaming\Python\Python38\Scripts\pyinstaller.exe' .\mirror.py --add-binary '.\visualhaar\target\release\visual_haarcascades_lib.dll;.' --add-data '.\haarcascade_forntalface_alt2.xml;.' --add-data '.\SourceSansPro-Regular.ttf;.' --add-data 'dnn;dnn'
|
||||
mv '.\dist\mirror\mpl-data' '.\dist\mirror\matplotlib\'
|
|
@ -22,7 +22,10 @@ titles = {
|
|||
'dnn' : "Neural network",
|
||||
}
|
||||
|
||||
fontfile = "SourceSansPro-Regular.ttf"
|
||||
|
||||
project_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),'..')
|
||||
|
||||
fontfile = os.path.join(project_dir, "SourceSansPro-Regular.ttf")
|
||||
|
||||
font = ImageFont.truetype(fontfile, 30)
|
||||
font_s = ImageFont.truetype(fontfile, 20)
|
||||
|
@ -368,13 +371,13 @@ def process3_haar(in_q, out_q, cascade_file, library_filename = None):
|
|||
if library_filename is not None:
|
||||
C = ffi.dlopen(library_filename)
|
||||
else:
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
lib_path = os.path.join(dir_path, "..", "visualhaar", "target", "release")
|
||||
|
||||
lib_path = os.path.join(project_dir, "visualhaar", "target", "release")
|
||||
possible_paths = [
|
||||
os.path.join(lib_path, "libvisual_haarcascades_lib.so"),
|
||||
os.path.join(lib_path, "visual_haarcascades_lib.dll"),
|
||||
os.path.join(dir_path, "..", "visual_haarcascades_lib.dll"),
|
||||
os.path.join(project_dir, "visual_haarcascades_lib.dll"),
|
||||
]
|
||||
|
||||
existing_paths = [p for p in possible_paths if os.path.exists(p)]
|
||||
|
|
19
mirror.py
19
mirror.py
|
@ -2,22 +2,23 @@ import argparse
|
|||
import face_recognition.comparison
|
||||
import cv2
|
||||
from multiprocessing import freeze_support
|
||||
import os
|
||||
|
||||
if __name__ == '__main__':
|
||||
freeze_support() # support pyinstaller on Windows
|
||||
|
||||
parser = argparse.ArgumentParser(description='Visualise face recognition algorithms.')
|
||||
|
||||
parser = argparse.ArgumentParser(description='Visualise face recognition algorithms.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument('--camera', '-c', type=int, default=0,
|
||||
help='Numeric id of the camera')
|
||||
parser.add_argument('--fullscreen', '-f', action='store_true',
|
||||
help='Display output full screen')
|
||||
parser.add_argument('--windowed', '-w', action='store_true',
|
||||
help='Display output windowed instead of fullscreen')
|
||||
parser.add_argument('--clockwise', action='store_true',
|
||||
help='Rotate clockwise')
|
||||
parser.add_argument('--counter-clockwise', action='store_true',
|
||||
help='Rotate counter clockwise')
|
||||
parser.add_argument('--cascade', default='haarcascade_frontalface_alt2.xml',
|
||||
parser.add_argument('--cascade', default=os.path.join(os.path.dirname(os.path.realpath(__file__)),'haarcascade_frontalface_alt2.xml'),
|
||||
help='Cascade XML file to use (opencv format)')
|
||||
parser.add_argument('--output', metavar="DIRECTORY", default='saves',
|
||||
parser.add_argument('--output', metavar="DIRECTORY", default=os.path.expanduser("~/Desktop/faces"),
|
||||
help='Directory to store images (after pressing spacebar)')
|
||||
parser.add_argument('--visualhaar-lib', metavar="LIBRARY", default=None,
|
||||
help='path/filename for visualhaar library (.so on linux, .dll on windows)\nSee: https://git.rubenvandeven.com/r/visualhaar/releases')
|
||||
|
@ -30,4 +31,8 @@ if __name__ == '__main__':
|
|||
if args.counter_clockwise:
|
||||
rotate = cv2.ROTATE_90_COUNTERCLOCKWISE
|
||||
|
||||
face_recognition.comparison.main(args.camera, rotate, args.fullscreen, args.cascade, args.output, args.visualhaar_lib)
|
||||
if not os.path.exists(args.output):
|
||||
print("Making directory:", args.output)
|
||||
os.mkdir(args.output)
|
||||
|
||||
face_recognition.comparison.main(args.camera, rotate, not args.windowed, args.cascade, args.output, args.visualhaar_lib)
|
||||
|
|
|
@ -5,3 +5,4 @@ Pillow
|
|||
opencv-python
|
||||
cffi
|
||||
scikit-image
|
||||
pyinstaller
|
Loading…
Reference in a new issue