无法在带有xvid编解码器和lepton相机的python中使用opencv保存视频



我试图使用XVID作为编解码器和.avi格式保存视频,但每次我得到的文件只有6KB,无法播放。我使用的是lepton 3.5相机。我该如何解决此问题?

fourcc = cv2.VideoWriter_fourcc(*"XVID")
out = cv2.VideoWriter('output_' + str(i) + '.avi', fourcc, 9.0, (160, 120), True)

请找到下面的代码,我在其中使用它-

found_device = None
for device in CCI.GetDevices():
if device.Name.startswith("PureThermal"):
found_device = device
print(" found lepton device")
break
if not found_device:
print("Couldn't find lepton device")
else:
lep = found_device.Open()
ID = lep.sys.GetFlirSerialNumber()
print(ID)
for i in range(1):
cv2_cap = cv2.VideoCapture(1)
cv2_cap.set(3, 160)
cv2_cap.set(4, 120)
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G')
out = cv2.VideoWriter('output.avi', fourcc, 9.0, (160, 120), True)
cv2.namedWindow("lepton", cv2.WINDOW_NORMAL)
print("Running, ESC or Ctrl-c to exit...")
while True:
ret, img = cv2_cap.read()
if ret == False:
print("Error reading image")
break
cv2.imshow("lepton", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

我通过添加出写(帧(

如下所示:

cv2_cap = cv2.VideoCapture(1)
cv2_cap.set(3, 160)
cv2_cap.set(4, 120)
fourcc = cv2.VideoWriter_fourcc(*'DIVX')
out = cv2.VideoWriter("output.avi", fourcc, 9.0, (160, 120), True)

cv2.namedWindow("lepton", cv2.WINDOW_NORMAL)
print("Running, ESC or Ctrl-c to exit...")
while True:
ret, img = cv2_cap.read()
if ret == False:
print("Error reading image")
break
out.write(img)
cv2.imshow("lepton", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

最新更新