修改了背景图
This commit is contained in:
parent
b273732450
commit
69aaaeac09
Binary file not shown.
@ -249,21 +249,20 @@ class FemtoBoltManager(BaseDevice):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 设置图形背景色和边距
|
# 设置图形背景色和边距
|
||||||
self.fig.patch.set_facecolor((50/255, 50/255, 50/255)) # 设置深灰色背景 rgb(50, 50, 50)
|
self.fig.patch.set_facecolor((38/255, 48/255, 64/255))
|
||||||
self.fig.tight_layout(pad=0) # 移除所有边距
|
self.fig.tight_layout(pad=0) # 移除所有边距
|
||||||
|
|
||||||
# 清除之前的绘图
|
# 清除之前的绘图
|
||||||
self.ax.clear()
|
self.ax.clear()
|
||||||
self.ax.set_facecolor((50/255, 50/255, 50/255)) # 设置坐标区域背景色为黑色
|
self.ax.set_facecolor((38/255, 48/255, 64/255))
|
||||||
|
|
||||||
# 深度数据过滤(与display_x.py完全一致)
|
# 深度数据过滤(与display_x.py完全一致)
|
||||||
depth[depth > self.depth_range_max] = 0
|
depth[depth > self.depth_range_max] = 0
|
||||||
depth[depth < self.depth_range_min] = 0
|
depth[depth < self.depth_range_min] = 0
|
||||||
|
|
||||||
# 背景图(深灰色背景)
|
# 背景图(#263040)
|
||||||
# 创建RGB格式的背景图,确保颜色准确性
|
background = np.zeros((*depth.shape, 3), dtype=np.uint8)
|
||||||
background_gray_value = 50 # RGB(50, 50, 50)
|
background[:] = (38, 48, 64)
|
||||||
background = np.full((*depth.shape, 3), background_gray_value, dtype=np.uint8)
|
|
||||||
|
|
||||||
# 使用 np.ma.masked_equal() 来屏蔽深度图中的零值
|
# 使用 np.ma.masked_equal() 来屏蔽深度图中的零值
|
||||||
depth = np.ma.masked_equal(depth, 0)
|
depth = np.ma.masked_equal(depth, 0)
|
||||||
|
|||||||
@ -570,18 +570,25 @@ class MockPressureDevice:
|
|||||||
|
|
||||||
def _generate_heatmap_image(self, raw_data: np.ndarray) -> str:
|
def _generate_heatmap_image(self, raw_data: np.ndarray) -> str:
|
||||||
try:
|
try:
|
||||||
|
# 底值阈值(小于等于该值的区域作为背景)
|
||||||
vmin = 10
|
vmin = 10
|
||||||
|
# 归一化到 [0,255],避免 dmax==dmin 时除零
|
||||||
dmin, dmax = np.min(raw_data), np.max(raw_data)
|
dmin, dmax = np.min(raw_data), np.max(raw_data)
|
||||||
norm = np.clip((raw_data - dmin) / max(dmax - dmin, 1) * 255, 0, 255).astype(np.uint8)
|
norm = np.clip((raw_data - dmin) / max(dmax - dmin, 1) * 255, 0, 255).astype(np.uint8)
|
||||||
|
# 应用伪彩色(JET)以增强对比
|
||||||
heatmap = cv2.applyColorMap(norm, cv2.COLORMAP_JET)
|
heatmap = cv2.applyColorMap(norm, cv2.COLORMAP_JET)
|
||||||
heatmap[raw_data <= vmin] = (0, 0, 0)
|
# 将低值区域设置为背景色 #263040;OpenCV 使用 BGR 通道顺序 -> (64, 48, 38)
|
||||||
|
heatmap[raw_data <= vmin] = (64, 48, 38)
|
||||||
|
# 放大显示,保持像素边界清晰
|
||||||
rows, cols = raw_data.shape
|
rows, cols = raw_data.shape
|
||||||
heatmap = cv2.resize(heatmap, (cols * 4, rows * 4), interpolation=cv2.INTER_NEAREST)
|
heatmap = cv2.resize(heatmap, (cols * 4, rows * 4), interpolation=cv2.INTER_NEAREST)
|
||||||
|
# 转换为 RGB 交给 PIL 编码
|
||||||
heatmap_rgb = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
|
heatmap_rgb = cv2.cvtColor(heatmap, cv2.COLOR_BGR2RGB)
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
Image.fromarray(heatmap_rgb).save(buffer, format="PNG")
|
Image.fromarray(heatmap_rgb).save(buffer, format="PNG")
|
||||||
buffer.seek(0)
|
buffer.seek(0)
|
||||||
|
# 输出 data URL 便于前端直接显示
|
||||||
image_base64 = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
image_base64 = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
||||||
return f"data:image/png;base64,{image_base64}"
|
return f"data:image/png;base64,{image_base64}"
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user