Extract a vector from a table

Typically: "How do I... ", "How can I... " questions
Post Reply
DavideIng
Posts: 34
Joined: 21 Sep 2017, 17:27

Extract a vector from a table

Post by DavideIng » 15 Nov 2017, 12:22

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

coppelia
Site Admin
Posts: 6218
Joined: 14 Dec 2012, 00:25

Re: Extract a vector from a table

Post by coppelia » 15 Nov 2017, 15:36

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

DavideIng
Posts: 34
Joined: 21 Sep 2017, 17:27

Re: Extract a vector from a table

Post by DavideIng » 16 Nov 2017, 13:00

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.

Post Reply