50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""
|
|
Example 5: Async/Pipelined Processing
|
|
|
|
Overlaps image capture with deformation computation for higher throughput.
|
|
Pipeline: [Capture Thread] -> [Queue] -> [Compute Thread] -> [Queue] -> [Main]
|
|
"""
|
|
|
|
import os
|
|
os.environ["OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS"] = "0"
|
|
|
|
import cv2
|
|
import orisys
|
|
|
|
|
|
def main():
|
|
sensor = orisys.Sensor("./s1.mp4", isstitch=True, cuda=True, verbose=True)
|
|
sensor.enable_async(queue_size=2)
|
|
|
|
print("\nPress 'q' to quit, 'r' to reset")
|
|
|
|
try:
|
|
while True:
|
|
data = sensor.get_async(timeout=0.05)
|
|
if data is None:
|
|
continue
|
|
|
|
print(f"FPS: {data['fps']:5.1f}, Fn: {data['fnormal']:8.2f}, "
|
|
f"Fx: {data['fshearx']:8.2f}, Fy: {data['fsheary']: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("Deformation", arrows)
|
|
|
|
if data['depth'] is not None:
|
|
depth_img = cv2.applyColorMap((data['depth'] * 255).astype('uint8'), cv2.COLORMAP_HOT)
|
|
cv2.imshow("Depth", depth_img)
|
|
|
|
key = cv2.waitKey(1) & 0xFF
|
|
if key == ord('q'):
|
|
break
|
|
elif key == ord('r'):
|
|
sensor.reset()
|
|
finally:
|
|
sensor.disconnect()
|
|
cv2.destroyAllWindows()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|