BodyBalanceEvaluation/backend/testcamera.py
2025-08-11 09:23:04 +08:00

109 lines
3.5 KiB
Python

# import cv2
# class CameraViewer:
# def __init__(self, device_index=0):
# self.device_index = device_index
# self.window_name = "Camera Viewer"
# def start_stream(self):
# cap = cv2.VideoCapture(self.device_index)
# if not cap.isOpened():
# print(f"无法打开摄像头设备 {self.device_index}")
# return
# cv2.namedWindow(self.window_name, cv2.WINDOW_NORMAL)
# while True:
# ret, frame = cap.read()
# if not ret:
# print("无法获取视频帧")
# break
# cv2.imshow(self.window_name, frame)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# break
# cap.release()
# cv2.destroyAllWindows()
# if __name__ == "__main__":
# # 修改这里的数字可以切换不同摄像头设备
# viewer = CameraViewer(device_index=1)
# viewer.start_stream()
# import os
# import pefile
# def list_dll_exports(dll_path):
# """解析 DLL 并返回导出的函数列表"""
# try:
# pe = pefile.PE(dll_path)
# exports = []
# if hasattr(pe, 'DIRECTORY_ENTRY_EXPORT'):
# for exp in pe.DIRECTORY_ENTRY_EXPORT.symbols:
# if exp.name:
# exports.append(exp.name.decode('utf-8'))
# else:
# exports.append(f"Ordinal_{exp.ordinal}")
# return exports
# except Exception as e:
# print(f"[错误] 无法解析 {dll_path}: {e}")
# return []
# def scan_directory_for_dll_functions(directory):
# """扫描目录下所有 DLL 文件并解析导出函数"""
# results = {}
# for root, _, files in os.walk(directory):
# for file in files:
# if file.lower().endswith(".dll"):
# dll_path = os.path.join(root, file)
# print(f"\n正在解析: {dll_path}")
# funcs = list_dll_exports(dll_path)
# results[dll_path] = funcs
# for func in funcs:
# print(f" {func}")
# return results
# if __name__ == "__main__":
# folder_path = r"D:\BodyBalanceEvaluation\backend\tests" # 这里改成你的 DLL 文件目录
# scan_directory_for_dll_functions(folder_path)
import ctypes
dll_path = r"D:\BodyBalanceEvaluation\backend\tests\SMiTSenseUsb-F3.0.dll"
mydll = ctypes.WinDLL(dll_path)
class FPMS_DEVICE_C(ctypes.Structure):
_fields_ = [
("mn", ctypes.c_uint8),
("sn", ctypes.c_char * 32),
("swVersion", ctypes.c_char * 32),
("rows", ctypes.c_uint16),
("cols", ctypes.c_uint16)
]
# 声明
mydll.fpms_usb_init.argtypes = [ctypes.c_int]
mydll.fpms_usb_init.restype = ctypes.c_int
mydll.fpms_usb_get_device_list.argtypes = [
ctypes.POINTER(FPMS_DEVICE_C),
ctypes.POINTER(ctypes.c_int)
]
mydll.fpms_usb_get_device_list.restype = ctypes.c_int
# 初始化
print("init:", mydll.fpms_usb_init(0))
# 获取设备列表
device_count = ctypes.c_int()
devices = (FPMS_DEVICE_C * 10)()
res = mydll.fpms_usb_get_device_list(devices, ctypes.byref(device_count))
print("get_device_list 返回值:", res, "设备数量:", device_count.value)
# 打印设备信息
for i in range(device_count.value):
dev = devices[i]
print(f"[设备 {i}] mn={dev.mn}, sn={dev.sn.decode(errors='ignore')}, "
f"swVersion={dev.swVersion.decode(errors='ignore')}, rows={dev.rows}, cols={dev.cols}")