微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

6 FLIR Lepton 相机并行视频录制

如何解决6 FLIR Lepton 相机并行视频录制

我想用 python 编写一个脚本来一次读取 6 个 FLIR Lepton 相机。我也使用了线程,但这不适用于超过 1 个相机。请帮我解决这个问题。此代码仅适用于 1 个摄像头。我可以执行顺序操作,但不能并行执行。

目标是一次读取6个摄像头,录制后拼接这些摄像头的视频。

from import_clr import *
from moviepy.editor import VideoFileClip,concatenate_videoclips

import threading

clr.AddReference("ManagedIR16Filters")
clr.AddReference("TIFFfile")
clr.AddReference("LeptonUVC")
from flirpy.camera.lepton import Lepton
import cv2
from Lepton import CCI
from IR16Filters import IR16Capture,NewIR16FrameEvent,NewBytesFrameEvent
from System.Drawing import ImageConverter
from System import Array,Byte
import matplotlib
from matplotlib import pyplot as plt
from matplotlib import cm
import numpy
import time
from PIL import Image
import matplotlib

class camThread(threading.Thread):
    def __init__(self,previewName,camID):
        threading.Thread.__init__(self)
        self.previewName = previewName
        self.camID = camID

    def run(self):
        print
        "Starting " + self.previewName
        camPreview(self.previewName,self.camID)


def camPreview(previewName,camID):
    cv2.namedWindow(previewName)
    cam = cv2.VideoCapture(camID)
    cam.set(3,160)
    cam.set(4,120)
    fourcc = cv2.VideoWriter_fourcc(*'XVID')
    out = cv2.VideoWriter('output_' + '_' + str(camID) + '.avi',fourcc,9.0,(int(160),int(120)))
    if cam.isOpened():  # try to get the first frame
        print('open')
        rval,frame = cam.read()
    else:
        rval = False

    while rval:
        out.write(frame)
        cv2.imshow(previewName,frame)
        rval,frame = cam.read()
        if cv2.waitKey(1) & 0xFF == ord('q'):  # exit on ESC
            break
    cv2.destroyWindow(previewName)


# Create two threads as follows
thread1 = camThread("Camera 1",1)
thread2 = camThread("Camera 2",2)
thread3 = camThread("Camera 3",3)
thread4 = camThread("Camera 4",4)
thread5 = camThread("Camera 5",5)
thread6 = camThread("Camera 6",6)
thread1.start()
time.sleep(3)
thread2.start()
time.sleep(3)
thread3.start()
thread4.start()
thread5.start()
thread6.start()



print()
print("Active threads",threading.activeCount())

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。