73 lines
2.0 KiB
Python
73 lines
2.0 KiB
Python
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(1, 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 = False
|
|
return
|
|
|
|
while running:
|
|
ret, f = cap.read()
|
|
if not ret:
|
|
break
|
|
frame = f.copy()
|
|
# print(frame.shape)
|
|
# frame = cv2.resize(frame, (1280, 720))
|
|
# print(frame.shape)
|
|
cv2.namedWindow('AHD Video', cv2.WND_PROP_FULLSCREEN)
|
|
cv2.setWindowProperty('AHD Video', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
|
|
cv2.imshow('AHD Video', f)
|
|
# cv2.showFullscreen('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...")
|