我正在一个项目中,一个移动机器人在4壁配置的地面中漫游。每面墙都有一个独特的形状(正方形,三角形)。机器人会检测形状并计算机器人到墙壁之间的距离并导出它。
所需的结果
Timestamp A B C D
xxxxx 0 12 0 0
yyyyy 21 0 0 0
当前代码将距离A或B或C或D的下一列导出到时间戳。但是如果它检测到C,我希望将0作为A,B和D的值。
Timestamp A B C D
xxxxx 41 0 0 0
yyyyy 21 0 0 0
有人可以帮我吗?
if area > 200:
cv2.drawContours(frame, [approx], 0, (0, 0, 0), 5)
if len(approx) == 3:
timestamped_camera_readings = np.append(timestamped_camera_readings, (((154*58)/(perimeter/4))*0.2645 ))
elif len(approx) == 4:
timestamped_camera_readings = np.append(timestamped_camera_readings, (((154*58)/(perimeter/4))*0.2645 ))
elif len(approx) == 5:
timestamped_camera_readings = np.append(timestamped_camera_readings, (((154*58)/(g/5))*0.2645 ))
write_fmt = " ".join("%4.2f" for _ in timestamped_camera_readings)
# append time
timestamped_camera_readings = np.append(float(timestamp),timestamped_camera_readings)
write_fmt += " %.0f"
with open("camera_diatanceee.txt", "ab") as ff:
np.savetxt(ff, np.expand_dims(timestamped_camera_readings, axis=0),fmt='%f')