Bonjour,
Je suis actuellement sur un projet développer avec un raspberry pi 3B+ qui comporte 2 caméras USB qui fonctionne en même temps.
Nous avons fait une migration vers une raspberry pi 4, or, les 2 caméras USB de fonctionnent pas en même temps.
Une fonctionne et enregistre bien une vidéo.
L’autre retourne l’erreur « VIDIOC_DQBUF: Ressource temporaly unavailable », ou « VIDIOC_DQBUF: Invalid Argument ».
Auriez-vous des pistes permettant de faire fonctionner deux caméras USB en même temps, sur la raspberry pi 4?
Voici mon code:
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)
Merci, Charles.

