Skip to content

Instantly share code, notes, and snippets.

@Tony363
Created September 12, 2020 06:33
Show Gist options
  • Save Tony363/e2c3b37823b4a9e7e84c86bf610539cd to your computer and use it in GitHub Desktop.
Save Tony363/e2c3b37823b4a9e7e84c86bf610539cd to your computer and use it in GitHub Desktop.
# NB : cv2.UMat array is faster than np array
pano = cv2.UMat(np.asarray([]))
leftimage_gpu = cv2.cuda_GpuMat()
rightimage_gpu = cv2.cuda_GpuMat()
readFrame = 0
while self.running:
try:
# Initialize left and right frames
# CSI cameras frames works on 30 or 60 FPS but the sticher works under 3FPS (slower)
# Therefore it needs to store a frame for a longer period of time to be able to stitch
# if (self.left_camera.frame is not None and self.right_camera.frame is not None) or self.GPU:
if (self.left_camera.frame is not None and self.right_camera.frame is not None):
_, left_image = self.left_camera.read()
_, right_image = self.right_camera.read()
stitch_start_time = time.time()
leftimage_gpu.upload(left_image)
rightimage_gpu.upload(right_image)
if self.stitched_frames == 0 or self.to_estimate is True:
status = self.stitcher.estimateTransform([left_image,right_image])
if status_check(status):
print(CODES.INFO, "Transform successfully estimated")
self.to_estimate = False
status,pano = self.stitcher.composePanorama([left_image,right_image],pano)
# self.pano.upload(pano)
if not status_check(status):
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment