Vision Sensor

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

Vision Sensor

Postby Dheenu » 25 Apr 2017, 22:45

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
Site Admin
Posts: 5824
Joined: 14 Dec 2012, 00:25

Re: Vision Sensor

Postby coppelia » 27 Apr 2017, 07:31

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: 6
Joined: 15 Apr 2017, 01:29

Re: Vision Sensor

Postby Dheenu » 01 May 2017, 01:04

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
Site Admin
Posts: 5824
Joined: 14 Dec 2012, 00:25

Re: Vision Sensor

Postby coppelia » 02 May 2017, 08:15

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: 6
Joined: 15 Apr 2017, 01:29

Re: Vision Sensor

Postby Dheenu » 03 May 2017, 05:59

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
Site Admin
Posts: 5824
Joined: 14 Dec 2012, 00:25

Re: Vision Sensor

Postby coppelia » 03 May 2017, 16:00

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: 6
Joined: 15 Apr 2017, 01:29

Re: Vision Sensor

Postby Dheenu » 05 May 2017, 22:48

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
Site Admin
Posts: 5824
Joined: 14 Dec 2012, 00:25

Re: Vision Sensor

Postby coppelia » 08 May 2017, 05:55

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: 6
Joined: 15 Apr 2017, 01:29

Re: Vision Sensor

Postby Dheenu » 14 May 2017, 18:52

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)
       a= imread('Image'); %showing error here
    end
    loop=loop+1;
    imshow(a); %error
end


Return to “General questions”

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 22 guests