Skip to content

Instantly share code, notes, and snippets.

@chilin0525
Created March 1, 2022 14:20
Show Gist options
  • Save chilin0525/c0d8cba9f21bd89367e9ec00185faff0 to your computer and use it in GitHub Desktop.
Save chilin0525/c0d8cba9f21bd89367e9ec00185faff0 to your computer and use it in GitHub Desktop.
test
import cv2
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot open camera")
exit()
#cv2.namedWindow("live", cv2.WINDOW_AUTOSIZE); # 命名一個視窗,可不寫
while(True):
# 擷取影像
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
# 彩色轉灰階
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# 顯示圖片
cv2.imshow('live', frame)
#cv2.imshow('live', gray)
# 按下 q 鍵離開迴圈
if cv2.waitKey(1) == ord('q'):
break
# 釋放該攝影機裝置
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment