简体   繁体   English

无法使用 python 中的 opencv 和 xvid 编解码器和轻子相机保存视频

[英]unable to save video using opencv in python with xvid codec and lepton camera

I am trying to save video using XVID as codec and.avi format but every time I get a file of only 6KB and I am not able to play it.我正在尝试使用 XVID 将视频保存为编解码器和 .avi 格式,但每次我得到一个只有 6KB 的文件并且我无法播放它。 I am using lepton 3.5 cameras.我正在使用轻子 3.5 相机。 How can I resolve this?我该如何解决这个问题?

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

Please find the code below in which I am using it -请在下面找到我正在使用它的代码 -

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

I solved the issue by adding out.write(frame)我通过添加 out.write(frame) 解决了这个问题

as below:如下:

  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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM