From 153564a6beafeb3c54d909dc0baf2be9eba6a7b3 Mon Sep 17 00:00:00 2001 From: rise0chen Date: Thu, 12 Sep 2024 11:23:37 +0800 Subject: [PATCH] feat: list camera --- camera/bin/src/camera.py | 20 ++++++++++++++++++++ camera/bin/src/utils/camera.py | 2 ++ camera/web/index.html | 16 +++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/camera/bin/src/camera.py b/camera/bin/src/camera.py index 95c7b09..f158e1f 100644 --- a/camera/bin/src/camera.py +++ b/camera/bin/src/camera.py @@ -4,6 +4,7 @@ import shutil import cv2 import time +import json import lebai_sdk import utils.camera as camera @@ -22,6 +23,24 @@ def get_cmd(): return "" +def search_camera(): + width = (lebai.get_item("plugin_camera_width"))['value'] + if not width: + width = "1280" + width = int(width) + height = (lebai.get_item("plugin_camera_height"))['value'] + if not height: + height = "720" + height = int(height) + + camera_list = [] + for i in range(-1,10): + cap = camera.Camera(i, width, height) + if cap.isOpened(): + camera_list.append(i) + cap.release() + lebai.set_item("plugin_camera_indexs", json.dumps(camera_list)) + def init_camera(): index = (lebai.get_item("plugin_camera_index"))['value'] if not index: @@ -40,6 +59,7 @@ def init_camera(): return cap def main(): + search_camera() cap = init_camera() if not cap.isOpened(): exit(1) diff --git a/camera/bin/src/utils/camera.py b/camera/bin/src/utils/camera.py index 26b1d80..7c0c16e 100644 --- a/camera/bin/src/utils/camera.py +++ b/camera/bin/src/utils/camera.py @@ -60,6 +60,8 @@ def getImage(self): return img_color def release(self): + if not self.isOpened(): + return if self.kind == "cv": self.camera.release() if self.kind == "rs": diff --git a/camera/web/index.html b/camera/web/index.html index 89bb56a..899e8b5 100644 --- a/camera/web/index.html +++ b/camera/web/index.html @@ -9,7 +9,7 @@
index(深度摄像头填 -1)
- +
width
@@ -58,6 +58,11 @@ } function get() { rpc_data.method = "get_item"; + rpc_data.id = 20; + rpc_data.params[0] = { + "key": "plugin_camera_indexs", + }; + ws.send(JSON.stringify(rpc_data)); rpc_data.id = 21; rpc_data.params[0] = { "key": "plugin_camera_index", @@ -92,6 +97,15 @@ if (value === undefined) { return; } + if (id == 20) { + let options = []; + let indexs = JSON.parse(value); + for (const i in indexs) { + let selected = indexs[i] == document.getElementById("index").value ? "selected" : ""; + options.push(``); + } + document.getElementById("index").innerHTML = options; + } if (id == 21) { document.getElementById("index").value = value || "-1"; }