diff --git a/Unity/Plugins/libminibmcapture32.dll b/Unity/Plugins/libminibmcapture32.dll index dc409da..d1bfeb5 100644 Binary files a/Unity/Plugins/libminibmcapture32.dll and b/Unity/Plugins/libminibmcapture32.dll differ diff --git a/Unity/Plugins/libminibmcapture64.dll b/Unity/Plugins/libminibmcapture64.dll index 6583947..9bf333d 100644 Binary files a/Unity/Plugins/libminibmcapture64.dll and b/Unity/Plugins/libminibmcapture64.dll differ diff --git a/dshowcapture.py b/dshowcapture.py index e1c5293..34d1d44 100644 --- a/dshowcapture.py +++ b/dshowcapture.py @@ -13,6 +13,11 @@ def resolve(name): lib = None bm_lib = None +bm_options = None + +def set_options(str): + global bm_options + bm_options = str def create_frame_buffer(width, height, factor): buffer = bytearray(width * height * 4 * factor) @@ -23,6 +28,7 @@ class DShowCapture(): def __init__(self): global lib global bm_lib + global bm_options if lib is None or bm_lib is None: if platform.architecture()[0] == '32bit': dll_path = resolve(os.path.join("dshowcapture", "dshowcapture_x86.dll")) @@ -62,6 +68,9 @@ class DShowCapture(): bm_lib.stop_capture_single.argtypes = [] bm_lib.get_json_length.argtypes = [] bm_lib.get_json.argtypes = [c_char_p, c_int] + if not bm_options is None: + bm_lib.set_options.argtypes = [c_char_p] + bm_lib.set_options(bm_options.encode()) self.lib = lib self.bm_lib = bm_lib self.cap = lib.create_capture() @@ -97,6 +106,7 @@ class DShowCapture(): self.info = json.loads(json_text) for cam in self.info: cam["type"] = "DirectShow" + cam["index"] = cam["id"] # Blackmagic json_length = self.bm_lib.get_json_length(); @@ -107,7 +117,7 @@ class DShowCapture(): dshow_len = len(self.info) for cam in bm_info: cam["type"] = "Blackmagic" - cam["id"] += dshow_len + cam["index"] = cam["id"] + dshow_len self.info.extend(bm_info) return self.info @@ -141,7 +151,7 @@ class DShowCapture(): if self.info[cam]['type'] == "DirectShow": ret = self.lib.capture_device_by_dcap(self.cap, cam, dcap, width, height, fps) == 1 elif self.info[cam]['type'] == "Blackmagic": - ret = self.bm_lib.start_capture_single(self.info[cam]['bmId'], self.info[cam]['caps'][dcap]['bmModecode'], None) != 0 + ret = self.bm_lib.start_capture_single(self.info[cam]['id'], self.info[cam]['caps'][dcap]['bmModecode'], None) == 1 if ret: self.type = self.info[cam]['type'] if self.type == "DirectShow": @@ -157,7 +167,7 @@ class DShowCapture(): self.width = self.info[cam]['caps'][dcap]['minCX'] self.height = self.info[cam]['caps'][dcap]['minCY'] self.fps = int(10000000 / self.info[cam]['caps'][dcap]['minInterval']) - self.flipped = False + self.flipped = True self.colorspace = 101 self.colorspace_internal = self.colorspace self.size = self.width * self.height * 4 @@ -209,6 +219,8 @@ class DShowCapture(): return self.lib.get_colorspace_internal(self.cap) def capturing(self): + if self.type == "Blackmagic": + return 1 return self.lib.capturing(self.cap) == 1 def get_frame(self, timeout): diff --git a/dshowcapture/libminibmcapture32.dll b/dshowcapture/libminibmcapture32.dll index dc409da..d1bfeb5 100644 Binary files a/dshowcapture/libminibmcapture32.dll and b/dshowcapture/libminibmcapture32.dll differ diff --git a/dshowcapture/libminibmcapture64.dll b/dshowcapture/libminibmcapture64.dll index 6583947..9bf333d 100644 Binary files a/dshowcapture/libminibmcapture64.dll and b/dshowcapture/libminibmcapture64.dll differ diff --git a/facetracker.py b/facetracker.py index 6ee0636..805f292 100644 --- a/facetracker.py +++ b/facetracker.py @@ -46,6 +46,7 @@ parser.add_argument("--dump-points", type=str, help="When set to a filename, the parser.add_argument("--benchmark", type=int, help="When set to 1, the different tracking models are benchmarked, starting with the best and ending with the fastest and with gaze tracking disabled for models with negative IDs", default=0) if os.name == 'nt': parser.add_argument("--use-dshowcapture", type=int, help="When set to 1, libdshowcapture will be used for video input instead of OpenCV", default=1) + parser.add_argument("--blackmagic-options", type=str, help="When set, this additional option string is passed to the blackmagic capture library", default=None) args = parser.parse_args() os.environ["OMP_NUM_THREADS"] = str(args.max_threads) @@ -69,20 +70,24 @@ if args.log_output != "": sys.stdout = OutputLog(output_logfile, sys.stdout) sys.stderr = OutputLog(output_logfile, sys.stderr) -if os.name == 'nt' and (args.list_cameras > 0 or not args.list_dcaps is None): +if os.name == 'nt': import dshowcapture + if not args.blackmagic_options is None: + dshowcapture.set_options(args.blackmagic_options) + +if os.name == 'nt' and (args.list_cameras > 0 or not args.list_dcaps is None): cap = dshowcapture.DShowCapture() + info = cap.get_info() + unit = 10000000.; if not args.list_dcaps is None: - info = cap.get_info() - unit = 10000000.; formats = {0: "Any", 1: "Unknown", 100: "ARGB", 101: "XRGB", 200: "I420", 201: "NV12", 202: "YV12", 203: "Y800", 300: "YVYU", 301: "YUY2", 302: "UYVY", 303: "HDYC (Unsupported)", 400: "MJPEG", 401: "H264" } for cam in info: if args.list_dcaps == -1: type = "" if cam['type'] == "Blackmagic": type = "Blackmagic: " - print(f"{cam['id']}: {type}{cam['name']}") - if args.list_dcaps != -1 and args.list_dcaps != cam['id']: + print(f"{cam['index']}: {type}{cam['name']}") + if args.list_dcaps != -1 and args.list_dcaps != cam['index']: continue for caps in cam['caps']: format = caps['format'] @@ -93,15 +98,16 @@ if os.name == 'nt' and (args.list_cameras > 0 or not args.list_dcaps is None): else: print(f" {caps['id']}: Resolution: {caps['minCX']}x{caps['minCY']}-{caps['maxCX']}x{caps['maxCY']} FPS: {unit/caps['maxInterval']:.3f}-{unit/caps['minInterval']:.3f} Format: {format}") else: - camera_count = cap.get_devices() if args.list_cameras == 1: print("Available cameras:") - for i in range(camera_count): - camera_name = cap.get_device(i) + for cam in info: + type = "" + if cam['type'] == "Blackmagic": + type = "Blackmagic: " if args.list_cameras == 1: - print(f"{i}: {camera_name}") + print(f"{cam['index']}: {type}{cam['name']}") else: - print(camera_name) + print(f"{type}{cam['name']}") cap.destroy_capture() sys.exit(0) diff --git a/run.bat b/run.bat index d0aced9..674c0c9 100644 --- a/run.bat +++ b/run.bat @@ -4,7 +4,7 @@ facetracker -l 1 set /p cameraNum=Select your camera from the list above and enter the corresponding number: -facetracker -a 1 +facetracker -a %cameraNum% set /p dcaps=Select your camera mode or -1 for default settings: set /p width=Select the width: diff --git a/tracker.py b/tracker.py index edbe8a4..a188ee2 100644 --- a/tracker.py +++ b/tracker.py @@ -1189,7 +1189,7 @@ class Tracker(): duration = (time.perf_counter() - start) * 1000 if not self.silent: - print(f"Took {duration:.2f}ms (detect: {duration_fd:.2f}ms, crop: {duration_pp:.2f}, track: {duration_model:.2f}ms, 3D points: {duration_pnp:.2f}ms)") + print(f"Took {duration:.2f}ms (detect: {duration_fd:.2f}ms, crop: {duration_pp:.2f}ms, track: {duration_model:.2f}ms, 3D points: {duration_pnp:.2f}ms)") results = sorted(results, key=lambda x: x.id)