Vision sensor img

Report crashes, strange behaviour, or apparent bugs
Post Reply
lyl
Posts: 8
Joined: 15 Sep 2021, 07:40

Vision sensor img

Post by lyl »

Traceback (most recent call last):
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.

Image

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')

fferri
Posts: 1187
Joined: 09 Sep 2013, 19:28

Re: Vision sensor img

Post by fferri »

The error message is pretty clear: there is no such variable named "buffer".

What is print(buffer) doing there?

Post Reply