我在使用 cv2 VideoCapture 时遇到问题。 MP4 文件在每个文件中仅打印出 1 帧, 我该如何解决?没有错误,文件也没有损坏。
while(cam.isOpened()):
fname_vid='AlucardMovelogVid_'+str(date.today())+'.mp4'
out=cv2.VideoWriter(fname_vid,fourcc, 20.0, (640,480))
now=datetime.now()
dt_string=now.strftime('%d/%m/%Y, %H:%M:%S : ')
ret,frame1=cam.read()
ret,frame2=cam.read()
diff=cv2.absdiff(frame1,frame2)
appended_diff=dt_string+str(diff)
gray=cv2.cvtColor(diff,cv2.COLOR_RGB2GRAY)
blur=cv2.GaussianBlur(gray,(5,5),0)
frame=cv2.flip(blur,0)
movelog.append(appended_diff)
fname='Alucard_Movelog_'+str(date.today())+'.txt'
with open(fname, 'w') as file:
for item in movelog:
file.write("%s\n" % item)
out.write(frame)
if(cv2.waitKey(10)==ord('*')):
break
cv2.imshow('Alucard',blur)
out.release()