[英]How to use optimize processors performance in OpenCV-Python?
我是 OpenCV-Python 多處理的初學者。 我使用的是 Raspberry Pi 2 B 型(四核 x 1GHz)。 我正在嘗試用一個非常簡單的例子來優化 FPS。
這是我的代碼:
網絡攝像頭.py
import cv2
from threading import Thread
from multiprocessing import Process, Queue
class Webcam:
def __init__(self):
self.video_capture = cv2.VideoCapture('/dev/video2')
self.current_frame = self.video_capture.read()[1]
self.current_frame = cv2.resize(self.current_frame,(1280,720), cv2.INTER_AREA)
def _update_frame(self):
self.current_frame = self.video_capture.read()[1]
def _resize(self):
self.current_frame = cv2.resize(self.current_frame,(1280,720), cv2.INTER_AREA)
def resizeThread(self):
p2 = Process(target=self._resize, args=())
p2.start()
def readThread(self):
p1 = Process(target=self._update_frame, args=())
p1.start()
def get_frame(self):
return self.current_frame
主文件
from webcam import Webcam
import cv2
import time
webcam = Webcam()
webcam.readThread()
webcam.resizeThread()
while True:
startF = time.time()
webcam._update_frame()
webcam._resize()
image = webcam.get_frame()
print (image.shape)
cv2.imshow("Frame", image)
endF = time.time()
print ("FPS: {:.2f}".format(1/(endF-startF)))
cv2.waitKey(1)
我只有大約 10 FPS 的 FPS。
FPS: 11.16
(720, 1280, 3)
FPS: 10.91
(720, 1280, 3)
FPS: 10.99
(720, 1280, 3)
FPS: 10.01
(720, 1280, 3)
FPS: 9.98
(720, 1280, 3)
FPS: 9.97
那么如何優化多處理以提高 FPS? 我是否正確使用了多處理?
非常感謝你幫助我
東安
不確定這對多處理方面是否有幫助,但您可以通過兩種方式優化 cv2.resize 調用:
*當然,循環的最后一步應該使用一個小於 2 的因子,以確保結果具有您想要的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.