我正在使用视频编写器来保存FLIR相机的输出。到目前为止,我已经成功,视频文件保存得很好。但是,保存的文件顶部是实际的镜头,周围是黑色。这个屏幕截图将显示我的意思:
起初我以为我只是保存了错误大小的视频,但无论我设置的大小如何,这都会继续发生。我甚至尝试使用cv2.resize()
方法,但也失败了。
我似乎找不到其他有这个问题的人,我无法弄清楚我做错了什么。这是我的代码:
def main(flip_v = False, alpha = 128, device = "/dev/spidev0.0"):
# Create an array representing a 1280x720 image of
# a cross through the center of the display. The shape of
# the array must be of the form (height, width, color)
a = np.zeros((240, 320, 3), dtype=np.uint8)
lepton_buf = np.zeros((60, 80, 1), dtype=np.uint16)
with picamera.PiCamera() as camera:
# Add the overlay directly into layer 3 with transparency;
# we can omit the size parameter of add_overlay as the
# size is the same as the camera's resolution
o = camera.add_overlay(np.getbuffer(a), size=(320,240), layer=3, alpha=int(alpha), crop=(0,0,80,60), vflip=flip_v)
#Creating the VideoWriter object
filename = time.strftime("%Y.%m.%d %H.%M.%S", time.localtime()) + ".avi"
fourcc = cv2.cv.CV_FOURCC('I', '4', '2', '0')
out = cv2.VideoWriter(filename, fourcc, 8.0, (60, 80))
with Lepton(device) as l:
last_nr = 0
while True:
_,nr = l.capture(lepton_buf)
if nr == last_nr:
# no need to redo this frame
continue
last_nr = nr
cv2.normalize(lepton_buf, lepton_buf, 0, 65535, cv2.NORM_MINMAX)
np.right_shift(lepton_buf, 8, lepton_buf)
a[:lepton_buf.shape[0], :lepton_buf.shape[1], :] = lepton_buf
#resize the frame before writing it to a file
resized_frame = cv2.resize(a, (60, 80))
out.write(np.uint8(rezised_frame))
o.update(np.getbuffer(a))
# Once the program has run 2000 time break the loop
k += 1
if k == 2000:
out.release()
break