diff --git a/apriltag/bin/src/apriltag.py b/apriltag/bin/src/apriltag.py index f94514a..60bb9d0 100644 --- a/apriltag/bin/src/apriltag.py +++ b/apriltag/bin/src/apriltag.py @@ -21,22 +21,12 @@ lebai = lebai_sdk.connect("127.0.0.1", True) def main(): - fx = (lebai.get_item("plugin_camera_fx"))['value'] - if not fx: - fx = "900" - fx = float(fx) - fy = (lebai.get_item("plugin_camera_fy"))['value'] - if not fy: - fy = "900" - fy = float(fy) - cx = (lebai.get_item("plugin_camera_cx"))['value'] - if not cx: - cx = "640" - cx = float(cx) - cy = (lebai.get_item("plugin_camera_cy"))['value'] - if not cy: - cy = "360" - cy = float(cy) + camera_matrix = (lebai.get_item("plugin_camera_calibrater_camera_matrix"))['value'] + camera_matrix = json.loads(camera_matrix) + fx = camera_matrix[0][0] + fy = camera_matrix[1][1] + cx = camera_matrix[0][2] + cy = camera_matrix[1][2] tag_family = (lebai.get_item("plugin_apriltag_tag_family"))['value'] if not tag_family: tag_family = "tag36h11" diff --git a/apriltag/plugin.json b/apriltag/plugin.json index 749c58e..cb13436 100644 --- a/apriltag/plugin.json +++ b/apriltag/plugin.json @@ -1,5 +1,6 @@ { "name": "apriltag", "description": "视觉识别apriltag位姿", - "homepage": "lebai.ltd" + "homepage": "lebai.ltd", + "auto_restart": true } \ No newline at end of file diff --git a/apriltag/web/index.html b/apriltag/web/index.html index 5d72b24..879d159 100644 --- a/apriltag/web/index.html +++ b/apriltag/web/index.html @@ -7,6 +7,7 @@ +

使用camera_calibrater插件完成标定后,才能使用本插件

tag_family
diff --git a/camera/bin/src/camera.py b/camera/bin/src/camera.py index 74beb38..1df5b0a 100644 --- a/camera/bin/src/camera.py +++ b/camera/bin/src/camera.py @@ -12,14 +12,13 @@ lebai_sdk.init() lebai = lebai_sdk.connect("127.0.0.1", True) -def get_interval(): - interval = (lebai.get_item("plugin_camera_interval"))['value'] - if not interval: - interval = "0" - interval = float(interval) - return interval/1000 +def get_cmd(): + cmd = (lebai.get_item("plugin_camera_cmd"))['value'] + if not cmd: + cmd = "" + return cmd -def main(): +def init_camera(): index = (lebai.get_item("plugin_camera_index"))['value'] if not index: index = "-1" @@ -32,24 +31,12 @@ def main(): if not height: height = "720" height = int(height) - fx = (lebai.get_item("plugin_camera_fx"))['value'] - if not fx: - fx = "900" - fx = float(fx) - fy = (lebai.get_item("plugin_camera_fy"))['value'] - if not fy: - fy = "900" - fy = float(fy) - cx = (lebai.get_item("plugin_camera_cx"))['value'] - if not cx: - cx = "640" - cx = float(cx) - cy = (lebai.get_item("plugin_camera_cy"))['value'] - if not cy: - cy = "360" - cy = float(cy) cap = camera.Camera(index, width, height) + return cap + +def main(): + cap = init_camera() if not cap.isOpened(): exit(1) @@ -57,9 +44,11 @@ def main(): if not os.path.exists(images_dir): os.mkdir(images_dir) while True: - interval = get_interval() - if interval > 0: - time.sleep(interval) + time.sleep(0.1) + cmd = get_cmd() + if not cmd or cmd == "": + continue + if cmd == "shoot": frame = cap.getImage() if frame is None: break @@ -68,8 +57,10 @@ def main(): shutil.move(os.path.join(images_dir, "img.tmp.jpg"), os.path.join(images_dir, "img.jpg")) cv2.imwrite(os.path.join(images_dir, "img.tmp.webp"), frame, [cv2.IMWRITE_WEBP_QUALITY, 50]) shutil.move(os.path.join(images_dir, "img.tmp.webp"), os.path.join(images_dir, "img.webp")) - else: - time.sleep(5.0) + if cmd == "reinit": + cap.release() + cap = init_camera() + lebai.set_item("plugin_camera_cmd", "") exit(2) # 释放摄像头 cap.release() diff --git a/camera/plugin.json b/camera/plugin.json index dea9110..d0a2c4f 100644 --- a/camera/plugin.json +++ b/camera/plugin.json @@ -1,5 +1,6 @@ { "name": "camera", "description": "采集摄像头图片并保存到文件系统", - "homepage": "lebai.ltd" + "homepage": "lebai.ltd", + "auto_restart": true } \ No newline at end of file diff --git a/camera/web/index.html b/camera/web/index.html index fb20a86..5edea56 100644 --- a/camera/web/index.html +++ b/camera/web/index.html @@ -17,30 +17,14 @@ height

- fx
- -
- fy
- -
- cx
- -
- cy
- -
- interval(采集频率,单位ms)
- -
- +
- +