File "C:\python\coppeliasim1\UR5VisionSensor.py", line 33, in <module>
print(buffer)
NameError: name 'buffer' is not defined
This error occurred in my code when I was using the Python remote API to get a visual sensor. The visual sensor properties are shown in pictures.
Code: Select all
import sim
import sys
import numpy as np
import math
import matplotlib.pyplot as mpl
import time
import pygame
import cv2
##### Python connect to the V-REP client
print('Program started')
# Close potential connections
sim.simxFinish(-1)
clientID = sim.simxStart('127.0.0.1', 19997, True, True, 5000, 5)
print("Connection success")
# Start simulation
sim.simxStartSimulation(clientID, sim.simx_opmode_blocking)
print("Simulation start")
##### Obtain the handle
errorCode,visionSensorHandle = sim.simxGetObjectHandle(clientID,'Cam',sim.simx_opmode_oneshot_wait)
##### Get the image of vision sensor
errorCode,resolution,image = sim.simxGetVisionSensorImage(clientID,visionSensorHandle,0,sim.simx_opmode_streaming)
time.sleep(0.1)
errorCode,resolution,image = sim.simxGetVisionSensorImage(clientID,visionSensorHandle,0,sim.simx_opmode_buffer)
print(buffer)
#Process the image to the format (64,64,3)
sensorImage = []
sensorImage = np.array(image,dtype = np.uint8)
sensorImage.resize([resolution[0],resolution[1],3])
#Use matplotlib.imshow to show the image
mpl.imshow(sensorImage,origin='lower')