标定运行
This commit is contained in:
66
saveimg.py
Normal file
66
saveimg.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import cv2
|
||||
import threading
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import os
|
||||
|
||||
# 全局变量
|
||||
frame = None
|
||||
running = True
|
||||
|
||||
def video_thread():
|
||||
global frame, running
|
||||
cap = cv2.VideoCapture(0, cv2.CAP_ANY)
|
||||
cap.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*"YUYV"))
|
||||
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
|
||||
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
|
||||
# cap.set(cv2.CAP_PROP_FPS, 30)
|
||||
|
||||
if not cap.isOpened():
|
||||
print("[ERROR] Cannot open camera", file=sys.stderr)
|
||||
running = Falseq
|
||||
return
|
||||
|
||||
while running:
|
||||
ret, f = cap.read()
|
||||
if not ret:
|
||||
break
|
||||
frame = f.copy()
|
||||
cv2.imshow('Live Feed (Local Display)', f)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
running = False
|
||||
break
|
||||
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
def input_thread():
|
||||
global running
|
||||
print("Commands: 's' = screenshot, 'q' = quit")
|
||||
while running:
|
||||
try:
|
||||
cmd = input().strip().lower()
|
||||
if cmd == 's':
|
||||
if frame is not None:
|
||||
filename = f"./save_img/shot_{datetime.now().strftime('%Y%m%d_%H%M%S')}.jpg"
|
||||
cv2.imwrite(filename, frame)
|
||||
print(f"[SSH] Saved: {os.path.abspath(filename)}")
|
||||
else:
|
||||
print("[SSH] No frame available yet.")
|
||||
elif cmd == 'q':
|
||||
running = False
|
||||
break
|
||||
else:
|
||||
print("[SSH] Unknown command. Use 's' or 'q'.")
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 启动视频线程
|
||||
vt = threading.Thread(target=video_thread, daemon=True)
|
||||
vt.start()
|
||||
|
||||
# 主线程监听 SSH 输入
|
||||
input_thread()
|
||||
|
||||
print("[INFO] Exiting...")
|
||||
Reference in New Issue
Block a user