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