Page 628 - MDP2020-1
P. 628
| 인천전자마이스터고등학교 ·············································································································
622
openCV 카메라 동작코드
import cv2
import shutil
import time
import threading
cap = cv2.VideoCapture(-1)
path = 'home/pi/MdpAppcheTest'
def thread_run():
i=-1
timer=threading.Timer(2,thread_run)
i=i*-1
return i
timer.start()
thread_run()
print('width :%d, height : %d' % (cap.get(3), cap.get(4)))
while(True):
ret, frame = cap.read()
# Read 결과WW와 frame
if(ret):
cv2.imshow('frame_color', frame)
#if cv2.waitKey(1) == ord('w'):
if thread_run() == 1:
cv2.imwrite('w.jpg',frame)
shutil.move('/home/pi/w.jpg','/home/pi/MdpAppcheTest/test.jpg')
print("!"+path)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()