def get_images(self): z = np.zeros((10, 10)) if OPTIMIZE_FPS: return z, z, z # TODO : Maybe reduce image size for performance? responses = self.client.simGetImages([ fsds.ImageRequest("cam1", fsds.ImageType.Scene, False, False), fsds.ImageRequest("cam2", fsds.ImageType.Scene, False, False), #fsds.ImageRequest("cam3", fsds.ImageType.DepthPlanner, pixels_as_float=True, compress=False) ]) response = responses[0] # get np array img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8) # reshape array to 4 channel image array H X W X 4 imgL = img1d.reshape(response.height, response.width, 3) response = responses[1] # get np array img1d = np.fromstring(response.image_data_uint8, dtype=np.uint8) # reshape array to 4 channel image array H X W X 4 imgR = img1d.reshape(response.height, response.width, 3) """ response = responses[2] img1d = np.uint8(response.image_data_float) imgD = img1d.reshape(response.height, response.width, 1) """ imgD = z return imgL, imgR, imgD
def get_camera(): global ax1, im1, ax2, im2 #imgL = fsds.string_to_uint8_array(client.simGetImage("cam1", fsds.ImageType.Scene )) responses = client.simGetImages([ fsds.ImageRequest("cam1", fsds.ImageType.Scene, False, False), fsds.ImageRequest("cam2", fsds.ImageType.Scene, False, False), fsds.ImageRequest("cam3", fsds.ImageType.DepthPlanner, pixels_as_float = True, compress=False) ]) response = responses[0] # get numpy array img1d = numpy.fromstring(response.image_data_uint8, dtype=numpy.uint8) # reshape array to 4 channel image array H X W X 4 imgL = img1d.reshape(response.height, response.width, 3) imgL =cv2.resize(imgL, ( imgL.shape[1]//2, imgL.shape[0]//2 )) # original image is fliped vertically #imgL = numpy.flipud(img_rgb) response = responses[1] # get numpy array img1d = numpy.fromstring(response.image_data_uint8, dtype=numpy.uint8) # reshape array to 4 channel image array H X W X 4 imgR = img1d.reshape(response.height, response.width, 3) imgR =cv2.resize(imgR, ( imgR.shape[1]//2, imgR.shape[0]//2 )) # ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'camera_name', 'camera_orientation', 'camera_position', 'compress', 'from_msgpack', 'height', 'image_data_float': [0.0], 'image_data_uint8', 'image_type', 'message', 'pixels_as_float': False, 'time_stamp', 'to_msgpack', 'width'] response = responses[2] # get numpy array # print(response.image_data_float) #print(dir(response)) #img1d = numpy.fromstring(response.image_data_uint8, dtype=numpy.uint8) img1d = numpy.uint8(response.image_data_float) # img1d = numpy.array(response.image_data_float) # reshape array to 4 channel image array H X W X 4 imgD = img1d.reshape(response.height, response.width, 1) imgD = cv2.resize(imgD, ( imgD.shape[1]//2, imgD.shape[0]//2 )) imgLg = cv2.cvtColor(imgL, cv2.COLOR_BGR2GRAY) imgRg = cv2.cvtColor(imgR, cv2.COLOR_BGR2GRAY) stereo = cv2.StereoBM_create(numDisparities=128, blockSize=15) # imgD = stereo.compute(imgLg,imgRg) cv2.imshow("imgL", imgL) cv2.imshow("imgD", imgD) cv2.imshow("imgSBGM", stereo) cv2.waitKey(1) print(img1d.shape, imgL.shape) pass
def get_camera(): responses = client.simGetImages([ fsds.ImageRequest("cam1", fsds.ImageType.Scene, False, False), fsds.ImageRequest("cam2", fsds.ImageType.Scene, False, False), fsds.ImageRequest("cam1", fsds.ImageType.DisparityNormalized, False, False) ]) response = responses[0] # get numpy array img1d = numpy.fromstring(response.image_data_uint8, dtype=numpy.uint8) # reshape array to 4 channel image array H X W X 4 imgL = img1d.reshape(response.height, response.width, 3) # original image is fliped vertically #imgL = numpy.flipud(img_rgb) response = responses[1] # get numpy array img1d = numpy.fromstring(response.image_data_uint8, dtype=numpy.uint8) # reshape array to 4 channel image array H X W X 4 imgR = img1d.reshape(response.height, response.width, 3) response = responses[2] # get numpy array img1d = numpy.fromstring(response.image_data_uint8, dtype=numpy.uint8) # reshape array to 4 channel image array H X W X 4 imgD = img1d.reshape(response.height, response.width, 3) print(img1d.shape, imgL.shape) #cv2.imshow("imgL", imgL) #im1.set_data(imgL) #im2.set_data(imgR) #im3.set_data(imgD) #if (im2 == False): im2 = ax2.imshow(grab_frame(cap2)) #cv2.imshow("Left", imgL) #cv2.imshow("Right", ) #plt.show() pass
import sys import os ## adds the fsds package located the parent directory to the pyhthon path sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import time import fsds # connect to the simulator client = fsds.FSDSClient() # Check network connection, exit if not connected client.confirmConnection() # Get the image [image] = client.simGetImages([ fsds.ImageRequest(camera_name='examplecam', image_type=fsds.ImageType.Scene, pixels_as_float=False, compress=True) ], vehicle_name='FSCar') print("Image width: ", image.width) print("Image height: ", image.height) # write to png fsds.write_file(os.path.normpath('example.png'), image.image_data_uint8)