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 (将#修改为@)