46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""
|
|
Example 4: Multi-Sensor with Multiprocessing
|
|
|
|
Each sensor runs in its own process with independent CUDA context.
|
|
"""
|
|
|
|
import os
|
|
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
|
|
|
|
import cv2
|
|
import orisys
|
|
import multiprocessing as mp
|
|
|
|
|
|
def main():
|
|
configs = [
|
|
{'vid_src': './s1.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
|
{'vid_src': './s1_copy.mp4', 'isstitch': True, 'cuda': True, 'cal_path': './config/cal.npy'},
|
|
]
|
|
|
|
with orisys.MultiSensor(configs) as multi:
|
|
print("\nPress 'q' to quit")
|
|
|
|
for all_data in multi:
|
|
for data in [d for d in all_data if d]:
|
|
sid = data['sensor_id']
|
|
print(f"Sensor {sid}: FPS={data['fps']:5.1f}, Fn={data['fnormal']:8.2f}")
|
|
|
|
if data['img'] is not None and data['flow'] is not None:
|
|
arrows = orisys.util.draw_arrows(data['img'].copy(), data['flow'], threshold=5)
|
|
cv2.imshow(f"Sensor {sid}", arrows)
|
|
|
|
if data['depth'] is not None:
|
|
cv2.imshow(f"Sensor {sid} - Depth",
|
|
cv2.applyColorMap((data['depth'] * 255).astype('uint8'), cv2.COLORMAP_HOT))
|
|
|
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
|
break
|
|
|
|
cv2.destroyAllWindows()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
mp.freeze_support()
|
|
main()
|