修改了深度相机的接口代码

This commit is contained in:
root 2025-08-04 10:18:50 +08:00
parent 480750cfcc
commit f437ff4dba
6 changed files with 149281 additions and 76094 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -918,12 +918,12 @@ if __name__ == '__main__':
# 简单的测试事件处理器
@socketio.on('connect')
def handle_connect():
print('CLIENT CONNECTED!!!', flush=True)
# print('CLIENT CONNECTED!!!', flush=True) # 控制台打印测试已关闭
logger.info('客户端已连接')
@socketio.on('disconnect')
def handle_disconnect():
print('CLIENT DISCONNECTED!!!', flush=True)
# print('CLIENT DISCONNECTED!!!', flush=True) # 控制台打印测试已关闭
logger.info('客户端已断开连接')
# @socketio.on('start_video')

Binary file not shown.

View File

@ -30,7 +30,7 @@ from database import DatabaseManager
try:
import pykinect_azure as pykinect
# 重新启用FemtoBolt功能使用正确的Orbbec SDK K4A Wrapper路径
FEMTOBOLT_AVAILABLE = True
FEMTOBOLT_AVAILABLE = False
print("信息: pykinect_azure库已安装FemtoBolt深度相机功能已启用")
print("使用Orbbec SDK K4A Wrapper以确保与FemtoBolt设备的兼容性")
except ImportError:
@ -659,11 +659,30 @@ class DeviceManager:
return False
try:
# 检查是否已经在推流
if self.femtobolt_streaming:
logger.warning('FemtoBolt深度相机推流已在运行')
return True
# 重置停止事件
self.streaming_stop_event.clear()
# 设置推流标志
self.femtobolt_streaming = True
# 启动推流线程
self.femtobolt_streaming_thread = threading.Thread(
target=self._femtobolt_streaming_thread,
daemon=True,
name='FemtoBoltStreamingThread'
)
self.femtobolt_streaming_thread.start()
logger.info('FemtoBolt深度相机推流已开始')
return True
except Exception as e:
logger.error(f'FemtoBolt深度相机推流启动失败: {e}')
self.femtobolt_streaming = False
return False
def stop_femtobolt_stream(self):
@ -815,7 +834,7 @@ class DeviceManager:
logger.error(f'摄像头帧推送失败: {e}')
# 控制帧率
time.sleep(1/30) # 30 FPS
# time.sleep(1/30) # 30 FPS
except Exception as e:
logger.error(f'摄像头推流线程异常: {e}')
@ -833,32 +852,37 @@ class DeviceManager:
# 获取FemtoBolt帧
capture = self.femtobolt_camera.update()
# 检查capture是否有效以及color图像是否存在
if capture is not None and capture.color is not None:
# 转换颜色格式
color_image = capture.color
color_image = cv2.cvtColor(color_image, cv2.COLOR_BGRA2BGR)
# 调整帧大小
height, width = color_image.shape[:2]
if width > 960:
scale = 960 / width
new_width = 960
new_height = int(height * scale)
color_image = cv2.resize(color_image, (new_width, new_height))
# JPEG编码
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 80]
success, buffer = cv2.imencode('.jpg', color_image, encode_param)
if success and self.socketio:
jpg_as_text = base64.b64encode(buffer).decode('utf-8')
self.socketio.emit('depth_camera_frame', {
'image': jpg_as_text,
'frame_id': frame_count,
'timestamp': time.time()
})
frame_count += 1
# 检查capture是否有效并获取彩色深度图像
if capture is not None:
ret, color_image = capture.get_transformed_colored_depth_image()
if ret and color_image is not None:
# 转换颜色格式(如果需要)
if len(color_image.shape) == 3 and color_image.shape[2] == 4:
color_image = cv2.cvtColor(color_image, cv2.COLOR_BGRA2BGR)
elif len(color_image.shape) == 3 and color_image.shape[2] == 3:
# 已经是BGR格式无需转换
pass
# 调整帧大小
height, width = color_image.shape[:2]
if width > 960:
scale = 960 / width
new_width = 960
new_height = int(height * scale)
color_image = cv2.resize(color_image, (new_width, new_height))
# JPEG编码
encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 80]
success, buffer = cv2.imencode('.jpg', color_image, encode_param)
if success and self.socketio:
jpg_as_text = base64.b64encode(buffer).decode('utf-8')
self.socketio.emit('depth_camera_frame', {
'image': jpg_as_text,
'frame_id': frame_count,
'timestamp': time.time()
})
frame_count += 1
else:
# 如果没有获取到有效帧,短暂等待后继续
time.sleep(0.01)

View File

@ -43,7 +43,7 @@ class AzureKinectImageCapture:
def __init__(self):
self.device = None
self.current_mode = 1 # 1:彩色, 2:深度, 3:红外, 4:彩色深度
self.current_mode = 4 # 1:彩色, 2:深度, 3:红外, 4:彩色深度
self.save_counter = 0
# 创建保存图像的目录