簡體   English   中英

使用 Allied Vision Camera 增加實時 stream 的每秒幀數 (FPS),該相機使用 Vimba SDK for Python

[英]Increase Frames Per Second (FPS) of live stream using Allied Vision Camera that uses Vimba SDK for Python

首先,我得到了 Allied Vision Camera,在 Vimba SDK Python 的幫助下,我正在播放。 流式傳輸的 FPS 約為 12-14,而 Manta G-201C 提供的最大 FPS 為 30。如何達到最大 FPS?

首先,在 Vimba Viewer App 的幫助下,我設置了必要的參數,如曝光時間、白平衡、增益等,並保存了 xml 文件。 現在,在 xml 文件的幫助下,我將必要的值作為基本設置提供給 Vimba-Python。 以下代碼片段如下所示:

import cv2
import time
from vimba import *
import os
from datetime import datetime

is_running = True
i = 1
count = 0
path = 'C:\\Vimba\\dataset\\'

def do_something(img):
    lst = []
    global count
    count += 1
    filename = 'IMG_' + str(count) + '.jpg'
    cv2.putText(img, str(datetime.now()), (20, 40), cv2.FONT_HERSHEY_PLAIN, 2, (255, 255, 255), 2, cv2.LINE_AA)
    cv2.imwrite(filename, img)
    lst.append(img)
    return len(lst)


with Vimba.get_instance() as vimba:
    with vimba.get_all_cameras()[0] as cam:
        os.chdir(path)
        cam.set_pixel_format(PixelFormat.BayerRG8)
        cam.ExposureTimeAbs.set(30000.000000)
        cam.BalanceWhiteAuto.set('Off')
        cam.Gain.set(0)
        cam.AcquisitionMode.set('Continuous')
        cam.GainAuto.set('Off')
        cam.Height.set(720)
        cam.Width.set(1280)
        while is_running:
            start = time.time()
            frame = cam.get_frame()
            frame = frame.as_numpy_ndarray()
            frame = cv2.cvtColor(frame, cv2.COLOR_BAYER_RG2RGB)
            cv2.imshow('Live feed', frame)
            result = do_something(frame)
            end = time.time()
            seconds = end - start
            fps = int(result/seconds)
            print('FPS:', fps)
            # print(cam.AcquisitionFrameRateAbs.get())
            key = cv2.waitKey(1)
            if key == ord('q'):
                break
        cv2.destroyAllWindows()

從上面的代碼中可以看出,我正在讀取相機設置的所有值(來自 xml 文件),然后創建一個 function 'do_something(img)' 將圖像保存在所需路徑並返回圖像總數的值存儲在列表中。 該值用於檢查 FPS。 運行整個代碼后我得到以下 FPS:

FPS: 8
FPS: 13
FPS: 13
FPS: 14
FPS: 13
FPS: 13
FPS: 13
FPS: 12
FPS: 13
FPS: 13
FPS: 12
FPS: 14
FPS: 14
FPS: 13
FPS: 14
FPS: 14
FPS: 14
FPS: 14
FPS: 14

而在 cam.AcquisitionFrameRateAbs.get() 的幫助下,它顯示 FPS 為 30.00030000300003。 我已經嘗試了 inte.net 中的一些東西,但對我沒有任何作用。 我想從 14 幀達到 30 幀,但不知道該怎么做。 任何幫助表示贊賞!

順便說一句,我使用的是華碩 F570Z 筆記本電腦,它有一個顯卡 NVIDIA GeForce GTX 1050 (4 GB),處理器 - AMD Ryzen 5 四核 2500U,RAM - 8 GB DDR4 和 Windows 10 64 位。

如注釋中所述,您需要異步獲取:如果要使用多線程和 numpy 數組的幀處理機制為幀的 opencv 格式,則可以修改 multithreading_opencv.py 中的第 62 行cv_frame = frame.as_opencv_image()並替換它與您的框架處理。 您當然也可以對其他 python 腳本執行相同操作,並禁用像素格式檢查。 例如,在 asynchronous_grab_opencv.py 中,將整個代碼塊 117-132 替換為僅設置像素格式。

您也可以先獲取幀,使用 Vimba 圖像變換更改為 BGR8 像素格式,然后用作 opencv 幀:

frame.convert_pixel_format(PixelFormat.Bgr8)

opencv_frame = frame.as_opencv_image()

兩種像素格式解決方案本質上都是一樣的。 我不確定哪個會更快,但僅使用異步采集就已經可以帶來更高的 FPS。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM