Cannot present continuous image through cv2.imshow() while receiving camera data from Carla

651 Views Asked by At

I'm learning the program from https://pythonprogramming.net/control-camera-sensor-self-driving-autonomous-cars-carla-python/ , but i can only get static image through cv2.imshow(), while receiving carame data from Carla,and the code related to image processing is as follows:

def process_img(image):
    i = np.array(image.raw_data)
    i2 = i.reshape((IM_HEIGHT, IM_WIDTH, 4))
    i3 = i2[:, :, :3]
    cv2.imshow("", i3)
    cv2.waitKey(1)
    return i3/255.0

while cv2.waitKey(1), i can only get a blank image, so i choose larger number like cv2.waitKey(30),then i can only get the first frame of the camera, and the image doesn't update, the version of related software or packages are as follows: ubuntu 18.04, python 3.6, Carla 0.9.9, opencv-python 4.2.0.34, cuda10.0, cudnn 7.6.5 for cuda 10.0, tensorflow 1.14

example carla image

I'm really confused and hoping for help, any answers are appreciated

1

There are 1 best solutions below

0
On
  1. You create a place to store images from CARLA simulator - queue
  2. Listen to the camera and queue images
  3. In an infinite loop, get an image from the queue and display it (it is better to move the loop to a separate thread if you use gui)

Use this code

import queue
self.image_queue = queue.Queue()
camera.listen(self.image_queue.put)
while true:
    image_carla = self.image_queue.get()
    self.process_img(image_carla)