1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| def camera():
global i, initialisation,fps,compt
STS = getFDCvalue()
if initialisation and (STS == 2):
print('init')
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
camera1 = 0
camera2 = 0
cap.set(4,720)
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
cap2 = cv2.VideoCapture(2)
cap2.set(3, 1280)
cap2.set(4,720)
ligne_position = getLigne()
ligne_position = 0
video_name_cam_1 = 'decoupage/'+time.strftime("%d-%m-%Y")+'_'+time.strftime("%H-%M-%S")+'_1_'+str(ligne_position)+'.avi'
video_name_cam_2 = 'decoupage/'+time.strftime("%d-%m-%Y")+'_'+time.strftime("%H-%M-%S")+'_2_'+str(ligne_position)+'.avi'
out = cv2.VideoWriter(video_name_cam_1,cv2.VideoWriter_fourcc('M','J','P','G'), fps, (frame_width,frame_height))
out2 = cv2.VideoWriter(video_name_cam_2,cv2.VideoWriter_fourcc('M','J','P','G'), fps, (frame_width,frame_height))
initialisation = 0
while (initialisation == 0) and (STS > 1):
while STS == 2:
ret, frame = cap.read() # si lecture video = ok
ret2, frame2 = cap2.read()
if ret or ret2:
i = i + 1
if ret:
out.write(frame) # On ecrit dans la video
camera1 = 1
if ret2:
out2.write(frame2)
camera2 = 1
STS = getFDCvalue()
print('Fonctionnement : camera1 : ',camera1, 'camera 2 : ',camera2, i ,'frame')
else:
if i > 1:
cap.release()
out.release()
cap2.release()
out2.release()
i = 0
initialisation = 1
LAST_STS = STS
else:
STS = getFDCvalue()
print('STS value : ',STS)
while True:
camera()
time.sleep(0.1) |