checked 5 sensors run in parralle, cpu max out
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
"""
|
||||
Example 7: Five Sensors with Async Pipeline
|
||||
|
||||
Demonstrates scaling to 5 sensors running in parallel with async mode.
|
||||
Each sensor runs in its own process with 3-stage async pipeline.
|
||||
"""
|
||||
|
||||
import os
|
||||
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
|
||||
|
||||
import cv2
|
||||
import orisys
|
||||
import multiprocessing as mp
|
||||
import numpy as np
|
||||
|
||||
|
||||
def main():
|
||||
# Configure 5 sensors (using same video for demo - replace with actual sources)
|
||||
configs = [
|
||||
{'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
||||
{'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
||||
{'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
||||
{'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
||||
{'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
||||
]
|
||||
|
||||
with orisys.MultiSensor.async_context(configs) as multi:
|
||||
print(f"\n{len(configs)} sensors started. Press 'q' to quit")
|
||||
|
||||
for all_data in multi:
|
||||
valid_data = [d for d in all_data if d and d['img'] is not None]
|
||||
|
||||
# Print stats for all sensors
|
||||
for data in valid_data:
|
||||
print(f"S{data['sensor_id']}: FPS={data['fps']:4.1f} Fn={data['fnormal']:7.1f}", end=" | ")
|
||||
if valid_data:
|
||||
print()
|
||||
|
||||
# Create grid display (2 rows: 3 + 2)
|
||||
imgs = []
|
||||
for data in valid_data:
|
||||
if data['flow'] is not None:
|
||||
img = orisys.util.draw_arrows(data['img'].copy(), data['flow'], threshold=5)
|
||||
else:
|
||||
img = data['img']
|
||||
# Add sensor ID label
|
||||
cv2.putText(img, f"S{data['sensor_id']}", (10, 30),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0), 2)
|
||||
imgs.append(img)
|
||||
|
||||
if len(imgs) >= 5:
|
||||
# Create 2x3 grid (pad with black if needed)
|
||||
h, w = imgs[0].shape[:2]
|
||||
black = np.zeros((h, w, 3), dtype=np.uint8) if len(imgs[0].shape) == 3 else np.zeros((h, w), dtype=np.uint8)
|
||||
|
||||
row1 = np.hstack([imgs[0], imgs[1], imgs[2]])
|
||||
row2 = np.hstack([imgs[3], imgs[4], black])
|
||||
grid = np.vstack([row1, row2])
|
||||
|
||||
# Resize for display
|
||||
grid = cv2.resize(grid, (1200, 800))
|
||||
cv2.imshow("5 Sensors Grid", grid)
|
||||
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
break
|
||||
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mp.freeze_support()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user