Commit c35b6fe4 by Yuhaibo

1

parent b3b8ed72
......@@ -1042,9 +1042,9 @@ class MissionPanelHandler:
self.mission_panel.setCellTextColor(row_idx, col_idx, '#00AA00')
print(f" ✅ [设置绿色] 行{row_idx} 列{col_idx} {channel_name}")
else:
# 其他情况:恢复默认黑色
self.mission_panel.setCellTextColor(row_idx, col_idx, '#000000')
print(f" ⚫ [设置黑色] 行{row_idx} 列{col_idx} {channel_name} (检测={is_detecting}, 当前={is_current_mission})")
# 其他情况:保持灰色(不修改颜色)
# 通道列默认就是灰色,不需要重新设置
print(f" ⚪ [保持灰色] 行{row_idx} 列{col_idx} {channel_name} (检测={is_detecting}, 当前={is_current_mission})")
print(f"{'='*60}")
print(f"✅ [调试] 通道列颜色更新完成")
......
......@@ -1009,6 +1009,7 @@ class AnnotationWidget(QtWidgets.QWidget):
# 区域名称和高度配置(支持双击编辑)
self.area_names = [] # 存储区域名称列表
self.area_heights = [] # 存储区域高度列表(默认20mm)
self.area_states = [] # 存储区域状态列表(默认、空、满)
self.channel_name = "" # 通道名称
self._initUI()
......@@ -1075,13 +1076,32 @@ class AnnotationWidget(QtWidgets.QWidget):
return f"区域{area_index+1}"
def _ensureAreaConfig(self, area_index):
"""确保区域配置存在(名称和高度)"""
"""确保区域配置存在(名称、状态和高度)"""
# 扩展列表到需要的长度
while len(self.area_names) <= area_index:
self.area_names.append(self._generateAreaName(len(self.area_names)))
while len(self.area_heights) <= area_index:
self.area_heights.append("20mm")
while len(self.area_states) <= area_index:
self.area_states.append("默认")
def _toggleAreaState(self, area_index):
"""切换区域状态:默认 → 空 → 满 → 默认"""
if area_index < 0 or area_index >= len(self.area_states):
return
current_state = self.area_states[area_index]
if current_state == "默认":
self.area_states[area_index] = "空"
elif current_state == "空":
self.area_states[area_index] = "满"
elif current_state == "满":
self.area_states[area_index] = "默认"
print(f"区域 {area_index+1} 状态已切换为: {self.area_states[area_index]}")
self._updateDisplay()
def loadFrame(self, frame):
"""加载图像帧(发送信号给handler处理)"""
......@@ -1242,6 +1262,11 @@ class AnnotationWidget(QtWidgets.QWidget):
# 高度位置:名称后面(留15像素间隔)
height_pos = (left + 5 + name_width + 15, text_y)
draw.text(height_pos, area_height, fill=(255, 255, 0), font=font_height)
# 状态标签:在框中间位置
area_state = self.area_states[i]
state_pos = (cx - len(area_state) * 10, cy) # 居中显示,估算字符宽度
draw.text(state_pos, area_state, fill=(255, 255, 255), font=font_name)
# 转换回OpenCV图像
img[:] = cv2.cvtColor(np.array(img_pil), cv2.COLOR_RGB2BGR)
......@@ -1285,6 +1310,12 @@ class AnnotationWidget(QtWidgets.QWidget):
height_pos = (left + 5 + name_width + 15, text_y)
cv2.putText(img, area_height, height_pos,
cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 0), 2)
# 状态标签:在框中间位置
area_state = self.area_states[i]
state_pos = (cx - len(area_state) * 7, cy)
cv2.putText(img, area_state, state_pos,
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2)
def _drawInstructionText(self, img):
"""在图像右上角绘制说明文字(支持中文) - 增强版"""
......@@ -1363,7 +1394,7 @@ class AnnotationWidget(QtWidgets.QWidget):
"2. 在框内底部区域点击设置容器底部点",
"3. 在框内顶部区域点击设置容器顶部点",
"4. 双击文本编辑名称/高度,Enter确认",
"5. 双击框体删除单个区域(新增!)",
"5. 双击状态标签切换状态(默认→空→满)",
"6. 双击空白区域完成标注",
"",
"快捷键操作(增强版)",
......@@ -1575,6 +1606,26 @@ class AnnotationWidget(QtWidgets.QWidget):
# 转换坐标
image_x, image_y = self._labelToImageCoords(event.x(), event.y())
# 检查是否双击了某个区域的状态标签位置
for i, (cx, cy, size) in enumerate(self.annotation_engine.boxes):
self._ensureAreaConfig(i)
half = size // 2
area_state = self.area_states[i]
# 状态标签区域:在框中间,大小约为状态文本的大小
state_width = len(area_state) * 20 # 估算状态文本宽度
state_height = 30 # 估算状态文本高度
state_left = cx - state_width // 2
state_right = cx + state_width // 2
state_top = cy - state_height // 2
state_bottom = cy + state_height // 2
if state_left <= image_x <= state_right and state_top <= image_y <= state_bottom:
# 双击了状态标签,切换状态
self._toggleAreaState(i)
return
# 检查是否双击了某个区域的名称或高度文本位置
for i, (cx, cy, size) in enumerate(self.annotation_engine.boxes):
self._ensureAreaConfig(i)
......@@ -1604,25 +1655,6 @@ class AnnotationWidget(QtWidgets.QWidget):
# 双击了高度区域
self._editAreaHeight(i)
return
# 🔥 新增:检查是否双击了某个检测框区域(用于删除单个框)
for i, (cx, cy, size) in enumerate(self.annotation_engine.boxes):
half = size // 2
left = cx - half
right = cx + half
top = cy - half
bottom = cy + half
# 检查是否双击了框的边框区域(不包括文本区域)
if (left <= image_x <= right and top <= image_y <= bottom):
# 检查是否不在文本区域内(避免与编辑功能冲突)
text_rect_top = top + 5
text_rect_bottom = top + 40
if not (text_rect_top <= image_y <= text_rect_bottom):
# 双击了框的非文本区域,显示删除确认对话框
self._confirmDeleteArea(i)
return
# 如果双击的位置不在任何文本区域内,则触发完成标注(等同于按C键)
self._onComplete()
......@@ -1824,6 +1856,8 @@ class AnnotationWidget(QtWidgets.QWidget):
self.area_names.pop()
if len(self.area_heights) > 0:
self.area_heights.pop()
if len(self.area_states) > 0:
self.area_states.pop()
self._updateDisplay()
else:
......@@ -1840,6 +1874,8 @@ class AnnotationWidget(QtWidgets.QWidget):
self.area_names.pop()
if len(self.area_heights) > 0:
self.area_heights.pop()
if len(self.area_states) > 0:
self.area_states.pop()
# 回到画框模式
self.annotation_engine.step = 0
......@@ -1978,6 +2014,11 @@ class AnnotationWidget(QtWidgets.QWidget):
removed_height = self.area_heights.pop(area_index)
print(f"已删除区域高度 {area_index+1}: {removed_height}")
# 删除对应的区域状态
if area_index < len(self.area_states):
removed_state = self.area_states.pop(area_index)
print(f"已删除区域状态 {area_index+1}: {removed_state}")
# 更新显示
self._updateDisplay()
......
......@@ -710,10 +710,14 @@ class MissionPanel(QtWidgets.QWidget):
if col_index == 0 and user_data is not None:
item.setData(Qt.UserRole, user_data)
# 🔥 如果是未配置状态,设置灰色前景色
if is_unconfigured:
# 🔥 通道列始终设置为灰色字体
if self.CHANNEL_START_COLUMN <= col_index < self.CHANNEL_START_COLUMN + self.CHANNEL_COUNT:
item.setForeground(QtGui.QColor(128, 128, 128)) # 设置灰色文字
print(f"[调试] 设置灰色QTableWidgetItem: 行={row_index}, 列={col_index}, 值='{value}'")
print(f"[调试] 设置通道列灰色字体: 行={row_index}, 列={col_index}, 值='{value}'")
# 🔥 如果是未配置状态且不是通道列,设置灰色前景色
elif is_unconfigured:
item.setForeground(QtGui.QColor(128, 128, 128)) # 设置灰色文字
print(f"[调试] 设置未配置状态灰色QTableWidgetItem: 行={row_index}, 列={col_index}, 值='{value}'")
else:
print(f"[调试] 设置普通QTableWidgetItem: 行={row_index}, 列={col_index}, 值='{value}'")
......@@ -1182,7 +1186,7 @@ class MissionPanel(QtWidgets.QWidget):
item = self.table.item(selected_row, col)
if item:
# 双击行:只设置文字颜色为黑色,不改变背景
# 双击行:所有列(包括通道列)都设置为黑色文字
item.setForeground(QtGui.QColor(0, 0, 0)) # 黑色文字
# 不设置背景色,保持原有背景
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment