Skip to content

Commit

Permalink
camera error
Browse files Browse the repository at this point in the history
  • Loading branch information
rise0chen committed Dec 2, 2024
1 parent 4ad7937 commit 535168f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
31 changes: 28 additions & 3 deletions camera_calibrater/bin/src/camera_calibrater.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ def main():
clear_imgs()
lebai.set_item("plugin_camera_calibrater_i", str(0))
if cmd == "calibrate":
if get_i() < 9:
print("image not enough")
lebai.set_item("plugin_camera_calibrater_cmd_calibrate", "")
continue
# 标定
cp_int = np.zeros((row * col, 3), np.float32)
cp_int[:, :2] = np.mgrid[0:row, 0:col].T.reshape(-1, 2)
Expand All @@ -149,11 +153,32 @@ def main():
obj_points.append(cp_world)
image_points.append(corners)
# 进行相机标定
image_points_len = len(image_points)
if image_points_len < 3:
print("image not enough")
ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(obj_points, image_points, img.shape[::-1], None, None)
if not ret:
print("failed to calibrateCamera")
lebai.set_item("plugin_camera_calibrater_cmd_calibrate", "")
continue
# 计算投影误差
mean_error = 0
error_points = [] # 坐标误差
for i in range(len(obj_points)):
imgpoints2, _ = cv2.projectPoints(obj_points[i], rvecs[i], tvecs[i], camera_matrix, dist_coeffs)
error = cv2.norm(image_points[i], imgpoints2, cv2.NORM_L2) / len(imgpoints2)
error_points.append(error)
mean_error += error
mean_error = mean_error / len(obj_points)

bad_points = [] #异常坐标
for i in range(len(obj_points)):
if error_points[i] > max(mean_error, 0.1) * 1.5:
print("remove bad images:", error_points[i])
bad_points.append(i)
for i in bad_points[::-1]:
R_end2base.pop(i)
T_end2base.pop(i)
obj_points.pop(i)
image_points.pop(i)

ret, camera_matrix, dist_coeffs, rvecs, tvecs = cv2.calibrateCamera(obj_points, image_points, img.shape[::-1], None, None)
if not ret:
print("failed to calibrateCamera")
Expand Down
2 changes: 1 addition & 1 deletion camera_calibrater/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<hr>
<img src="" id="pic">
<br>
采集至少9张不同位置的图片后再点击“标定”
采集15~30张不同位置的图片后再点击“标定”
<br>
注意:标定板具有方向标定过程需保证方向一致,倾斜角度超过45度容易翻转方向。
<br>
Expand Down
4 changes: 2 additions & 2 deletions modbus_rtu_slave/list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ cd bin/
# x86_64
cargo build --release --target x86_64-unknown-linux-gnu
mkdir -p x86_64
mv target/x86_64-unknown-linux-gnu/release/modbus_rtu_slave x86_64
mv -f target/x86_64-unknown-linux-gnu/release/modbus_rtu_slave x86_64 || true
# aarch64
cargo build --release --target aarch64-unknown-linux-gnu
mkdir -p aarch64
mv target/aarch64-unknown-linux-gnu/release/modbus_rtu_slave aarch64
mv -f target/aarch64-unknown-linux-gnu/release/modbus_rtu_slave aarch64 || true

echo $PLUGIN_CI_LIST

0 comments on commit 535168f

Please sign in to comment.