Fixed Blackmagic capture.
This commit is contained in:
parent
3670d3f793
commit
d9cd16b095
8 changed files with 33 additions and 15 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -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):
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
2
run.bat
2
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:
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue