Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rise0chen committed Mar 20, 2024
1 parent f3546d9 commit 8207764
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 150 deletions.
22 changes: 6 additions & 16 deletions apriltag/bin/src/apriltag.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion apriltag/plugin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "apriltag",
"description": "视觉识别apriltag位姿",
"homepage": "lebai.ltd"
"homepage": "lebai.ltd",
"auto_restart": true
}
45 changes: 17 additions & 28 deletions camera/bin/src/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -32,34 +31,24 @@ 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)

images_dir = os.path.join(current_dir, "../../images")
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
Expand All @@ -68,8 +57,8 @@ 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 = init_camera()
exit(2)
# 释放摄像头
cap.release()
Expand Down
3 changes: 2 additions & 1 deletion camera/plugin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "camera",
"description": "采集摄像头图片并保存到文件系统",
"homepage": "lebai.ltd"
"homepage": "lebai.ltd",
"auto_restart": true
}
107 changes: 18 additions & 89 deletions camera/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,14 @@
height<br>
<input type="number" id="height">
<br>
fx<br>
<input type="number" id="fx" step="0.01">
<br>
fy<br>
<input type="number" id="fy" step="0.01">
<br>
cx<br>
<input type="number" id="cx" step="0.01">
<br>
cy<br>
<input type="number" id="cy" step="0.01">
<br>
interval(采集频率,单位ms)<br>
<input type="number" id="interval" step="100">
<br>
</form>
<button onclick="save()">save</button>
<button onclick="get()">get</button>
<button onclick="get()">refresh</button>
<br>
<img src="" id="pic">
<img src="../images/img.webp" id="pic">
</body>

<script>
var timer_pic = null;
var ws;
var rpc_data = {
"jsonrpc": "2.0",
Expand All @@ -67,28 +51,8 @@
};
ws.send(JSON.stringify(rpc_data));
rpc_data.params[0] = {
"key": "plugin_camera_fx",
"value": document.getElementById("fx").value
};
ws.send(JSON.stringify(rpc_data));
rpc_data.params[0] = {
"key": "plugin_camera_fy",
"value": document.getElementById("fy").value
};
ws.send(JSON.stringify(rpc_data));
rpc_data.params[0] = {
"key": "plugin_camera_cx",
"value": document.getElementById("cx").value
};
ws.send(JSON.stringify(rpc_data));
rpc_data.params[0] = {
"key": "plugin_camera_cy",
"value": document.getElementById("cy").value
};
ws.send(JSON.stringify(rpc_data));
rpc_data.params[0] = {
"key": "plugin_camera_interval",
"value": document.getElementById("interval").value
"key": "plugin_camera_cmd",
"value": "reinit"
};
ws.send(JSON.stringify(rpc_data));
}
Expand All @@ -109,31 +73,6 @@
"key": "plugin_camera_height",
};
ws.send(JSON.stringify(rpc_data));
rpc_data.id = 31;
rpc_data.params[0] = {
"key": "plugin_camera_fx",
};
ws.send(JSON.stringify(rpc_data));
rpc_data.id = 32;
rpc_data.params[0] = {
"key": "plugin_camera_fy",
};
ws.send(JSON.stringify(rpc_data));
rpc_data.id = 33;
rpc_data.params[0] = {
"key": "plugin_camera_cx",
};
ws.send(JSON.stringify(rpc_data));
rpc_data.id = 34;
rpc_data.params[0] = {
"key": "plugin_camera_cy",
};
ws.send(JSON.stringify(rpc_data));
rpc_data.id = 41;
rpc_data.params[0] = {
"key": "plugin_camera_interval",
};
ws.send(JSON.stringify(rpc_data));
}

function connect() {
Expand Down Expand Up @@ -162,35 +101,25 @@
if (id == 23) {
document.getElementById("height").value = value || "720";
}
if (id == 31) {
document.getElementById("fx").value = value || "900";
}
if (id == 32) {
document.getElementById("fy").value = value || "900";
}
if (id == 33) {
document.getElementById("cx").value = value || "640";
}
if (id == 34) {
document.getElementById("cy").value = value || "360";
}
if (id == 41) {
var interval = value || "0";
document.getElementById("interval").value = interval;
if (timer_pic) {
clearInterval(timer_pic);
}
if (interval != "0") {
timer_pic = setInterval(() => {
document.getElementById("pic").src = "../images/img.webp?" + Date.now()
}, Number(interval));
}
}
}
}
}
connect();

function shoot() {
rpc_data.id = 10;
rpc_data.method = "set_item";
rpc_data.params[0] = {
"key": "plugin_camera_cmd",
"value": "shoot"
};
ws.send(JSON.stringify(rpc_data));
document.getElementById("pic").src = "../images/img.webp?" + Date.now();
}
setInterval(() => {
shoot();
}, 1000);

setInterval(() => {
if (ws.readyState == ws.CLOSED) {
connect();
Expand Down
22 changes: 11 additions & 11 deletions camera_calibrater/bin/src/camera_calibrater.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ def clear_imgs():
def main():
while True:
time.sleep(1)
img = cv2.imread(os.path.join(images_dir, "img.webp"))
if img.size == 0:
continue
row, col, width = get_row_col_width()
ret, corners = cv2.findChessboardCorners(img, (row, col), None)
if ret:
if len(corners) == row * col:
cv2.drawChessboardCorners(img, (row,col), corners, ret)
cv2.imwrite(os.path.join(images_dir, "camera_calibrater.tmp.webp"), img, [cv2.IMWRITE_WEBP_QUALITY, 10])
shutil.move(os.path.join(images_dir, "camera_calibrater.tmp.webp"), os.path.join(images_dir, "camera_calibrater.webp"))

cmd = get_cmd()
if not cmd or cmd == "":
continue
if cmd == "preview":
img = cv2.imread(os.path.join(images_dir, "img.webp"))
if img.size == 0:
continue
row, col, width = get_row_col_width()
ret, corners = cv2.findChessboardCorners(img, (row, col), None)
if ret:
if len(corners) == row * col:
cv2.drawChessboardCorners(img, (row,col), corners, ret)
cv2.imwrite(os.path.join(images_dir, "camera_calibrater.tmp.webp"), img, [cv2.IMWRITE_WEBP_QUALITY, 10])
shutil.move(os.path.join(images_dir, "camera_calibrater.tmp.webp"), os.path.join(images_dir, "camera_calibrater.webp"))
if cmd == "record":
lebai_real = lebai_sdk.connect("127.0.0.1", False)
i = get_i()+1
Expand Down
3 changes: 2 additions & 1 deletion camera_calibrater/plugin.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "camera_calibrater",
"description": "相机标定",
"homepage": "lebai.ltd"
"homepage": "lebai.ltd",
"auto_restart": true
}
17 changes: 14 additions & 3 deletions camera_calibrater/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h2>标定完成后,请务必禁用插件,否则,插件会一直在后台
<br>
</form>
<button onclick="save()">save</button>
<button onclick="get()">get</button>
<button onclick="get()">refresh</button>
<br>
<hr>
<hr>
Expand Down Expand Up @@ -171,7 +171,7 @@ <h2>标定完成后,请务必禁用插件,否则,插件会一直在后台
clearInterval(timer);
refresh_img();
}
}, 2000);
}, 500);
}
function refresh_img() {
document.getElementById("pic1").src = "../../camera/images/camera_calibrater.1.webp?" + Date.now();
Expand Down Expand Up @@ -236,8 +236,19 @@ <h2>标定完成后,请务必禁用插件,否则,插件会一直在后台
connect();
}
}, 1000);
setInterval(() => {

function preview() {
rpc_data.id = 10;
rpc_data.method = "set_item";
rpc_data.params[0] = {
"key": "plugin_camera_calibrater_cmd",
"value": "preview"
};
ws.send(JSON.stringify(rpc_data));
document.getElementById("pic").src = "../../camera/images/camera_calibrater.webp?" + Date.now()
}
setInterval(() => {
preview();
}, 1000);
</script>

Expand Down

0 comments on commit 8207764

Please sign in to comment.