Page 1 of 1

Extract a vector from a table

Posted: 15 Nov 2017, 12:22
by DavideIng
Hello,
I am getting the rgb image of an ePuck vision sensor.
The following satement has been used:

Code: Select all

ImageTable_rgb=simGetVisionSensorImage(handleVision,0,0,0)
Now, ImageTable is a table containing rgb values and I need to extract a vector (3rd dimension of the table) refeared to a random couple of the first and second dimension (the image is composed by a unique color).
I need to get this vector for the following statement:

Code: Select all

if (ExtractedVector=={1,0,0}) then
velLeft=-maxVel*0.25
velRight=maxVel*0.25
end
Any suggestions?

Many thanks
Davide

Re: Extract a vector from a table

Posted: 15 Nov 2017, 15:36
by coppelia
Sorry, I don't get your question. What dimension? What random couple?

Btw, simGetVisionSensorCharImage is faster than simGetVisionSensorImage. It however returns a string buffer instead of a table.

Cheers

Re: Extract a vector from a table

Posted: 16 Nov 2017, 13:00
by DavideIng
Fix it, I needed to be able to use the three component of the rgb vector retrieved by simGetVisionSensorImage to set an if statement like the following:

Code: Select all

ImageTable_rgb=simGetVisionSensorImage(handleVision,0,0,0)
         if (ImageTable_rgb [1]>0.5) and (ImageTable_rgb [2] < 0.2) and (ImageTable_rgb [3] < 0.2)then
        simSetJointTargetVelocity(leftMotor,-math.pi*0.5)
        simSetJointTargetVelocity(rightMotor,-math.pi*0.25)
        simWait(4)
        end
To change the target velocity, therefore direction, of an ePuck when the color of the plane is set close then light red.

About couple I meant for each pixel coordinates ( the first two dimensions of the array retrieved X and Y) of a plane, but I did not need to select that because the image is uniformly painted with the same color so each pixel has the same rgb component.