[英]unable to save video using opencv in python with xvid codec and lepton camera
我正在嘗試使用 XVID 將視頻保存為編解碼器和 .avi 格式,但每次我得到一個只有 6KB 的文件並且我無法播放它。 我正在使用輕子 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
我通過添加 out.write(frame) 解決了這個問題
如下:
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.