/* 自定義代碼塊樣式 */

herrDeng網內搜尋

自訂搜尋

Ads

2026年9月30日 星期三

OpenCV 串流處理完整攻略:VideoCapture 屬性控制、Trackbar 滑桿與 HSV 實作


[py3 code請進]
import cv2
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) #寬度
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)  #高度
 
if not cap.isOpened():
    print("不行!")
    exit() #離開程式
 
wname = "Webcam Control"
cv2.namedWindow(wname)
# -------------------------------
# 主迴圈:讀取 -> 顯示
# -------------------------------
cnt=0
while True:
    ret, frame = cap.read()
    if not ret:
        break
    # 直接顯示原始畫面
    cv2.imshow(wname, frame)
    k=cv2.waitKey(1)
    if k>0: # 按鍵 寫圖檔
        cv2.imwrite(f"{cnt}.jpg", frame)
        print(f"{cnt}.jpg 寫進圖檔 ")
        cnt+=1
    if k==27:  # 按 ESC 離開
        break
cap.release() #釋放資源
cv2.destroyAllWindows()

沒有留言:

Related Posts Plugin for WordPress, Blogger...

熱門文章