forked from neozhaoliang/surround-view-system-introduction
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
866ca6b
commit bff0498
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from queue import Queue | ||
import cv2 | ||
from PyQt5.QtCore import (QThread, QTime, QMutex, pyqtSignal, QMutexLocker) | ||
|
||
from structures import ThreadStatisticsData | ||
|
||
|
||
class BaseThread(QThread): | ||
|
||
""" | ||
Base class for all types of threads (capture, processing, stitching, ..., | ||
etc). Mainly for collecting statistics of this thread. | ||
""" | ||
|
||
FPS_STAT_QUEUE_LENGTH = 32 | ||
|
||
update_statistics_gui = pyqtSignal(ThreadStatisticsData) | ||
|
||
def __init__(self, parent=None): | ||
super(BaseThread, self).__init__(parent) | ||
self.init_commons() | ||
|
||
def init_commons(self): | ||
self.stopped = False | ||
self.stop_mutex = QMutex() | ||
self.clock = QTime() | ||
self.fps = Queue() | ||
self.processing_time = 0 | ||
self.processing_mutex = QMutex() | ||
self.sample_count = 0 | ||
self.fps_sum = 0 | ||
self.stat_data = ThreadStatisticsData() | ||
|
||
def stop(self): | ||
with QMutexLocker(self.stop_mutex): | ||
self.stopped = True | ||
|
||
def update_fps(self, dt): | ||
# add instantaneous fps value to queue | ||
if dt > 0: | ||
self.fps.put(1000 / dt) | ||
self.sample_count += 1 | ||
|
||
# discard redundant items in the fps queue | ||
if self.fps.qsize() > self.FPS_STAT_QUEUE_LENGTH: | ||
self.fps.get() | ||
|
||
# update statistics | ||
if self.fps.qsize() == self.sample_count == self.FPS_STAT_QUEUE_LENGTH: | ||
while not self.fps.empty(): | ||
self.fps_sum += self.fps.get() | ||
|
||
self.stat_data.average_fps = round(self.fps_sum / self.FPS_STAT_QUEUE_LENGTH, 2) | ||
# reset sum and sample number | ||
self.fps_sum = 0 | ||
self.sample_count = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class ImageFrame(object): | ||
|
||
def __init__(self, timestamp, image): | ||
self.timestamp = timestamp | ||
self.image = image | ||
|
||
|
||
class ThreadStatisticsData(object): | ||
|
||
def __init__(self): | ||
self.average_fps = 0 | ||
self.frames_processed_count = 0 |