0

一度に 6 台の FLIR Lepton カメラを読み取るスクリプトを Python で作成したいと考えています。スレッドも使用しましたが、それは複数のカメラでは機能しません。これに関して私を助けてください。このコードは 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())
4

0 に答える 0