## Vision Sensor

Typically: "How do I... ", "How can I... " questions
Dheenu
Posts: 7
Joined: 15 Apr 2017, 01:29

### Vision Sensor

Hi guys
How can i detect the color of many objects in the scene using vision sensor and to select one desired colored object? I am using remote api from MATLAB.
Thank you

coppelia
Posts: 7838
Joined: 14 Dec 2012, 00:25

### Re: Vision Sensor

Hello,

you question is very vaste and vague. You will have to go step-by-step. First try to retrieve an image from V-REP via simxGetVisionSensorImage2. Then process/inspect that image (e.g. extract color blobs, etc.). You might also have to read the vision sensor's depth map if later on you want to assign a 3D coordinate to each blob.

Cheers

Dheenu
Posts: 7
Joined: 15 Apr 2017, 01:29

### Re: Vision Sensor

coppelia wrote:Hello,

you question is very vaste and vague. You will have to go step-by-step. First try to retrieve an image from V-REP via simxGetVisionSensorImage2. Then process/inspect that image (e.g. extract color blobs, etc.). You might also have to read the vision sensor's depth map if later on you want to assign a 3D coordinate to each blob.

Cheers
hey
I need to get the live feed from vrep and view that in MATLAB. I am using this code but I am getting only single Image in Matlab. Should I need to add anything in LUA code (Main script in Vrep for Vision_sensor)(Non threaded child script)?

Code: Select all

%handle
[returnCode,Vision_sensor]=vrep.simxGetObjectHandle(clientID,'Vision_sensor',vrep.simx_opmode_blocking);
%image from vrep
[returnCode,resolution,Image]=vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_streaming);
while 1
[returnCode,resolution,Image]=vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_buffer );
imshow(Image)
end


coppelia
Posts: 7838
Joined: 14 Dec 2012, 00:25

### Re: Vision Sensor

Your code probably works, but is not correct: when trying to read streamed data, you should always check if the data is there. Make sure you carefully read this section.

Cheers

Dheenu
Posts: 7
Joined: 15 Apr 2017, 01:29

### Re: Vision Sensor

coppelia wrote:Your code probably works, but is not correct: when trying to read streamed data, you should always check if the data is there. Make sure you carefully read this section.

Cheers
I tried to change the code but it resulted in error(display condition in if else loop). can you please help what i am missing?

Code: Select all

%handle
[returnCode,Vision_sensor]=vrep.simxGetObjectHandle(clientID,'Vision_sensor',vrep.simx_opmode_blocking);
%image from vrep
[returnCode,resolution,Image]=vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_streaming);
while (clientID~=-1)
if (returnCode==vrep.simx_return_ok)
{
vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_buffer)
imshow(Image)
}
else
display('error')
end
end

coppelia
Posts: 7838
Joined: 14 Dec 2012, 00:25

### Re: Vision Sensor

Try with following:

Code: Select all

[returnCode,Vision_sensor]=vrep.simxGetObjectHandle(clientID,'Vision_sensor',vrep.simx_opmode_blocking);
vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_streaming);
while (clientID~=-1)
[returnCode,resolution,Image]=vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_buffer);
if (returnCode==vrep.simx_return_ok)
imshow(Image)
end
end
Cheers

Dheenu
Posts: 7
Joined: 15 Apr 2017, 01:29

### Re: Vision Sensor

coppelia wrote:Try with following:

Code: Select all

[returnCode,Vision_sensor]=vrep.simxGetObjectHandle(clientID,'Vision_sensor',vrep.simx_opmode_blocking);
vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_streaming);
while (clientID~=-1)
[returnCode,resolution,Image]=vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,1,vrep.simx_opmode_buffer);
if (returnCode==vrep.simx_return_ok)
imshow(Image)
end
end
Cheers
thanks it works. but even though i set bit 1 in number option ([number returnCode,array resolution,libpointer image]=simxGetVisionSensorImage(number clientID,number sensorHandle,number options,number operationMode)) i am getting only greyscale image

coppelia
Posts: 7838
Joined: 14 Dec 2012, 00:25

### Re: Vision Sensor

Bit one set gives you greyscale images. This is normal. Set bit one to 0 for RGB values (your picture will be 3 times larger).

Cheers

Dheenu
Posts: 7
Joined: 15 Apr 2017, 01:29

### Re: Vision Sensor

coppelia wrote:Bit one set gives you greyscale images. This is normal. Set bit one to 0 for RGB values (your picture will be 3 times larger).

Cheers
How to store that image in a variable in MATLAB. When i use "imread(Image)" function it is showing "image" not find.
Thank you

Code: Select all

while loop < 3%(clientID~=-1)
[returnCode,resolution,Image]=vrep.simxGetVisionSensorImage2(clientID,Vision_sensor,0,vrep.simx_opmode_buffer);
if (returnCode==vrep.simx_return_ok)
end
loop=loop+1;
imshow(a); %error
end