Skip to content

Commit

Permalink
feat: list camera
Browse files Browse the repository at this point in the history
  • Loading branch information
rise0chen committed Sep 12, 2024
1 parent 8fbcb38 commit 153564a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
20 changes: 20 additions & 0 deletions camera/bin/src/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
import cv2
import time
import json
import lebai_sdk
import utils.camera as camera

Expand All @@ -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:
Expand All @@ -40,6 +59,7 @@ def init_camera():
return cap

def main():
search_camera()
cap = init_camera()
if not cap.isOpened():
exit(1)
Expand Down
2 changes: 2 additions & 0 deletions camera/bin/src/utils/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
16 changes: 15 additions & 1 deletion camera/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<form>
index(深度摄像头填 -1)<br>
<input type="number" id="index">
<select id="index"></select>
<br>
width<br>
<input type="number" id="width">
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(`<option value="${indexs[i]}" ${selected}>${indexs[i]}</option>`);
}
document.getElementById("index").innerHTML = options;
}
if (id == 21) {
document.getElementById("index").value = value || "-1";
}
Expand Down

0 comments on commit 153564a

Please sign in to comment.