기본 입출력
이미지
이미지 출력
img = cv2.imread("이미지 파일 경로")
cv2.imshow('이미지 창', img)
cv2.waitKey()
cv2.destroyAllWindows()
이미지 저장
img = cv2.imread("이미지 파일 경로")
cv2.show('이미지 창', img)
cv2.imwrite("저장경로", img)
cv2.waitKey()
cv2.destroyAllWindows()
동영상
동영상 출력
cap = cv2.VideoCapture("비디오 파일 경로")
if cap.isOpend():
while True:
ret, img = cap.read() # ret=초기화 여부(bool), img=프레임 이미지
if ret:
cv2.imshow("창 이름", img)
cv2.waitKey(25) #25ms 지연 (40fps로 가정)
else:
break
else:
print("can't open video")
cap.release()
cv2.destroyAllWindows()
웹캠 출력
cap = cv2.VideoCapture(0) # 0번 장치
if cap.isOpend():
while True:
ret, img = cap.read() # ret=초기화 여부(bool), img=프레임 이미지
if ret:
cv2.imshow("창 이름", img)
if cv2.waitKey(1) != -1:
break
else:
break
else:
print("no frame")
else:
print("can't open camera.")
cap.release()
cv2.destroyAllWindows()