我有一系列灰度影像。使用opencv的python代碼,我用這些灰度影像制作了一個視頻。
import cv2
import numpy as np
A = readimages(img_path) # A is a list of uint8 images of size similar to framesize
framesize = (480,640)
out = cv2.VideoWriter('output_video.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 30.0, framesize, isColor = False)
for img in A:
out.write(cv2.flip(img,0))
out.release()
如下圖所示的結果視頻(左側部分)僅顯示輸入影像的一小部分以及多行。請任何幫助。

uj5u.com熱心網友回復:
在這種情況下,在寫入視頻檔案之前,影像 dtype 必須為 uint8。新代碼運行良好。
import cv2
import numpy as np
A = readimages(img_path) # A is a list of uint8 images of size similar to framesize
framesize = (480,640)
out = cv2.VideoWriter('output_video.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 30.0, framesize, isColor = False)
for img in A:
out.write(img.astype('uint8'))
out.release()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/338188.html
上一篇:如何在openCV上獲得與leptonica的pixReduceRankBinary2和pixCloseBrick相同的結果?
