Zmq remote Api vision sensor visualisation slow
Posted: 01 Oct 2021, 16:10
Hello,
I want to display the image of a vision sensor using python ZMQ remote API, the following code seems to works, but it makes Coppelia simulation run for about 1 second and then freeze for 2 seconds and then run for 1 second, etc...
Am I missing something to make it run more smoothly?
And is there a better way to show the image without using all the transformations I applied to the image?
Thank you in advance
I want to display the image of a vision sensor using python ZMQ remote API, the following code seems to works, but it makes Coppelia simulation run for about 1 second and then freeze for 2 seconds and then run for 1 second, etc...
Am I missing something to make it run more smoothly?
And is there a better way to show the image without using all the transformations I applied to the image?
Code: Select all
from time import sleep
import time
import zmqRemoteApi
from zmqRemoteApi import RemoteAPIClient
import numpy as np
from PIL import Image as I
import cv2
# create a client to connect to zmqRemoteApi server:
# (creation arguments can specify different host/port,
# defaults are host='localhost', port=23000)
client = RemoteAPIClient('localhost',23000)
# get a remote object:
sim = client.getObject('sim')
sensor1Handle=sim.getObjectHandle('VisionSensor')
sim.startSimulation()
resolution = sim.getVisionSensorResolution(sensor1Handle)
sleep(1)
while True:
image=sim.getVisionSensorImage(sensor1Handle)
img = np.array(image)*255
img = img.astype(np.uint8)
img.resize([resolution[0],resolution[1],3])
img = cv2.flip(img[...,::-1],0)
cv2.imshow('image',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
sim.stopSimulation()