更新截图数据保存方法
This commit is contained in:
parent
1deb2425b8
commit
f9b9f94c81
@ -15,7 +15,7 @@ backup_interval = 24
|
||||
max_backups = 7
|
||||
|
||||
[CAMERA]
|
||||
device_index = 0
|
||||
device_index = 1
|
||||
width = 1280
|
||||
height = 720
|
||||
fps = 30
|
||||
@ -29,7 +29,7 @@ depth_range_max = 1500
|
||||
|
||||
[DEVICES]
|
||||
imu_device_type = real
|
||||
imu_port = COM3
|
||||
imu_port = COM8
|
||||
imu_baudrate = 9600
|
||||
pressure_device_type = real
|
||||
pressure_use_mock = False
|
||||
|
Binary file not shown.
Binary file not shown.
@ -503,20 +503,20 @@ class RecordingManager:
|
||||
|
||||
|
||||
|
||||
def collect_detection_data(self, session_id: str, patient_id: str) -> Dict[str, Any]:
|
||||
def collect_detection_data(self, session_id: str, patient_id: str, detection_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""
|
||||
采集所有设备数据并保存到指定目录结构
|
||||
保存前端传入的检测数据和图片
|
||||
|
||||
Args:
|
||||
session_id: 检测会话ID
|
||||
patient_id: 患者ID
|
||||
detection_data: 前端传入的检测数据,包含base64格式的图片数据
|
||||
|
||||
Returns:
|
||||
Dict: 包含所有采集数据的字典,符合detection_data表结构
|
||||
"""
|
||||
# 生成采集时间戳
|
||||
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S_%f')[:-3] # 精确到毫秒
|
||||
data_base_dir= Path(f'data/patients/{patient_id}/{session_id}/{timestamp}')
|
||||
if getattr(sys, 'frozen', False):
|
||||
# 打包后的exe文件路径
|
||||
exe_dir = os.path.dirname(sys.executable)
|
||||
@ -537,73 +537,56 @@ class RecordingManager:
|
||||
# 初始化数据字典
|
||||
data = {
|
||||
'session_id': session_id,
|
||||
'head_pose': None,
|
||||
'head_pose': detection_data.get('head_pose'),
|
||||
'body_pose': None,
|
||||
'body_image': None,
|
||||
'foot_data': None,
|
||||
'foot_image': None,
|
||||
'foot_data': detection_data.get('foot_data'),
|
||||
'foot_data_image': None,
|
||||
'foot_image': None,
|
||||
'screen_image': None,
|
||||
|
||||
'timestamp': timestamp
|
||||
}
|
||||
|
||||
try:
|
||||
# 1. 采集头部姿态数据(从IMU设备获取)
|
||||
# 注意:这里需要从外部传入IMU设备或者在初始化时添加IMU管理器
|
||||
# if self.imu_manager and self.imu_manager.is_connected:
|
||||
# head_pose_data = self._collect_head_pose_data()
|
||||
# if head_pose_data:
|
||||
# data['head_pose'] = json.dumps(head_pose_data)
|
||||
# self.logger.debug(f'头部姿态数据采集成功: {session_id}')
|
||||
# 保存图片数据
|
||||
image_fields = [
|
||||
('body_image', 'body'),
|
||||
('foot_image', 'foot'),
|
||||
('foot_data_image', 'foot_data'),
|
||||
('screen_image', 'screen')
|
||||
]
|
||||
|
||||
# 2. 采集身体姿态数据(从FemtoBolt深度相机获取)
|
||||
if self.femtobolt_manager and self.femtobolt_manager.is_connected:
|
||||
body_pose_data = self._collect_body_pose_data()
|
||||
if body_pose_data:
|
||||
data['body_pose'] = json.dumps(body_pose_data)
|
||||
self.logger.debug(f'身体姿态数据采集成功: {session_id}')
|
||||
|
||||
# 3. 采集身体视频截图(从FemtoBolt深度相机获取)
|
||||
if self.femtobolt_manager and self.femtobolt_manager.is_connected:
|
||||
for field, prefix in image_fields:
|
||||
base64_data = detection_data.get(field)
|
||||
if base64_data:
|
||||
try:
|
||||
body_image_path = self._capture_body_image(data_dir)
|
||||
if body_image_path:
|
||||
data['body_image'] = str(os.path.join(data_base_dir,body_image_path))
|
||||
self.logger.debug(f'身体截图保存成功: {body_image_path}')
|
||||
except Exception as e:
|
||||
self.logger.error(f'采集身体截图异常: {e}')
|
||||
# 移除base64头部信息
|
||||
if ';base64,' in base64_data:
|
||||
base64_data = base64_data.split(';base64,')[1]
|
||||
|
||||
# 4. 采集足部压力数据(从压力传感器获取)
|
||||
if self.pressure_manager and hasattr(self.pressure_manager, 'is_connected') and self.pressure_manager.is_connected:
|
||||
foot_data = self._collect_foot_pressure_data()
|
||||
if foot_data:
|
||||
data['foot_data'] = json.dumps(foot_data)
|
||||
self.logger.debug(f'足部压力数据采集成功: {session_id}')
|
||||
# 解码base64数据
|
||||
image_data = base64.b64decode(base64_data)
|
||||
|
||||
# 5. 采集足部监测视频截图(从摄像头获取)
|
||||
if self.camera_manager and self.camera_manager.is_connected:
|
||||
foot_image_path = self._capture_foot_image(data_dir)
|
||||
if foot_image_path:
|
||||
data['foot_image'] = str(os.path.join(data_base_dir,foot_image_path))
|
||||
self.logger.debug(f'足部截图保存成功: {foot_image_path}')
|
||||
# 生成图片文件名
|
||||
filename = f'{prefix}_{timestamp}.jpg'
|
||||
file_path = data_dir / filename
|
||||
|
||||
# # 6. 生成足底压力数据图(从压力传感器数据生成)
|
||||
# if self.pressure_manager and hasattr(self.pressure_manager, 'is_connected') and self.pressure_manager.is_connected:
|
||||
# foot_data_image_path = self._generate_foot_pressure_image(data_dir)
|
||||
# if foot_data_image_path:
|
||||
# data['foot_data_image'] = str(foot_data_image_path)
|
||||
# self.logger.debug(f'足底压力数据图生成成功: {foot_data_image_path}')
|
||||
# 保存图片
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(image_data)
|
||||
|
||||
# 7. 采集屏幕截图
|
||||
screen_image_path = self._capture_screen_image(data_dir)
|
||||
if screen_image_path:
|
||||
data['screen_image'] = str(os.path.join(data_base_dir,screen_image_path))
|
||||
self.logger.debug(f'屏幕截图保存成功: {screen_image_path}')
|
||||
|
||||
self.logger.debug(f'数据采集完成: {session_id}, 时间戳: {timestamp}')
|
||||
# 更新数据字典中的图片路径
|
||||
data[field] = str(os.path.join('data', 'patients', patient_id, session_id, timestamp, filename))
|
||||
self.logger.debug(f'{field}保存成功: {filename}')
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f'数据采集失败: {e}')
|
||||
self.logger.error(f'保存{field}失败: {e}')
|
||||
|
||||
self.logger.debug(f'数据保存完成: {session_id}, 时间戳: {timestamp}')
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f'数据保存失败: {e}')
|
||||
|
||||
return data
|
||||
|
||||
|
@ -15,7 +15,7 @@ backup_interval = 24
|
||||
max_backups = 7
|
||||
|
||||
[CAMERA]
|
||||
device_index = 3
|
||||
device_index = 1
|
||||
width = 1280
|
||||
height = 720
|
||||
fps = 30
|
||||
@ -29,7 +29,7 @@ depth_range_max = 1700
|
||||
|
||||
[DEVICES]
|
||||
imu_device_type = real
|
||||
imu_port = COM3
|
||||
imu_port = COM8
|
||||
imu_baudrate = 9600
|
||||
pressure_device_type = real
|
||||
pressure_use_mock = False
|
||||
|
@ -1163,7 +1163,6 @@ class AppServer:
|
||||
# 获取请求数据
|
||||
data = flask_request.get_json() or {}
|
||||
patient_id = data.get('patient_id')
|
||||
screen_image_base64 = data.get('imageData')
|
||||
|
||||
# 如果没有提供patient_id,从会话信息中获取
|
||||
if not patient_id:
|
||||
@ -1184,7 +1183,8 @@ class AppServer:
|
||||
# 调用录制管理器采集数据
|
||||
collected_data = self.recording_manager.collect_detection_data(
|
||||
session_id=session_id,
|
||||
patient_id=patient_id
|
||||
patient_id=patient_id,
|
||||
detection_data=data
|
||||
)
|
||||
|
||||
# 将采集的数据保存到数据库
|
||||
|
@ -13,7 +13,7 @@ api.interceptors.request.use(
|
||||
if (window.electronAPI) {
|
||||
config.baseURL = window.electronAPI.getBackendUrl()
|
||||
} else {
|
||||
config.baseURL = 'http://192.168.1.173:5000'
|
||||
config.baseURL = 'http://192.168.1.58:5000'
|
||||
}
|
||||
|
||||
// 只为需要发送数据的请求设置Content-Type
|
||||
@ -631,7 +631,7 @@ export const getBackendUrl = () => {
|
||||
if (window.electronAPI) {
|
||||
return window.electronAPI.getBackendUrl()
|
||||
} else {
|
||||
return 'http://192.168.1.173:5000'
|
||||
return 'http://192.168.1.58:5000'
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user