机械臂摄像头
This commit is contained in:
+8
-18
@@ -1130,26 +1130,16 @@ def api_camera_capture():
|
||||
|
||||
@app.route("/api/camera/arm_refresh")
|
||||
def api_arm_camera_refresh():
|
||||
"""从机械臂拉一张 JPEG(流式读第一个完整帧)"""
|
||||
"""从机械臂拉一张 JPEG(请求 snapshot 端点,简单 HTTP GET)"""
|
||||
import requests
|
||||
try:
|
||||
r = requests.get(ARM_CAMERA_CONFIG["url"], stream=True, timeout=8)
|
||||
if r.status_code != 200:
|
||||
return "", 404
|
||||
data = b""
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
data += chunk
|
||||
# 在累积数据中找 JPEG 完整帧
|
||||
s = data.find(b"\xff\xd8")
|
||||
e = data.find(b"\xff\xd9", s + 2) if s >= 0 else -1
|
||||
if s >= 0 and e > s:
|
||||
r.close()
|
||||
return Response(data[s:e+2], mimetype="image/jpeg")
|
||||
# 累积超过 5MB 还没找到完整帧,说明流异常,放弃
|
||||
if len(data) > 5 * 1024 * 1024:
|
||||
r.close()
|
||||
return "", 404
|
||||
r.close()
|
||||
r = requests.get(ARM_CAMERA_CONFIG.get("snapshot_url", ARM_CAMERA_CONFIG["url"]), timeout=8)
|
||||
if r.status_code == 200 and r.content:
|
||||
resp = Response(r.content, mimetype="image/jpeg")
|
||||
resp.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
|
||||
resp.headers["Pragma"] = "no-cache"
|
||||
resp.headers["Expires"] = "0"
|
||||
return resp
|
||||
return "", 404
|
||||
except Exception as ex:
|
||||
logger.error(f"arm_refresh 失败: {ex}")
|
||||
|
||||
@@ -40,6 +40,7 @@ CAMERA_CONFIG = {
|
||||
# ========== 机械臂摄像头流 ==========
|
||||
ARM_CAMERA_CONFIG = {
|
||||
"url": "http://192.168.110.164:5003/api/camera/preview",
|
||||
"snapshot_url": "http://192.168.110.164:5003/api/camera/snapshot",
|
||||
}
|
||||
|
||||
# ========== HTTP 上传 ==========
|
||||
|
||||
Reference in New Issue
Block a user