automatic Pick & Place robot arm with MV

Hello guys,

i have build a pick & place robot arm with 4 servos and a suction cup. The heart is a arduino board.
The automatic pick and place work good if the picking things are every time on the same place.

Now i want that the robot pick the things if he identify it with the camera.

I connect the arduino and the MV M7 with the uart port and it works good.

As main code to identify the things i use the “rectangle” code and thats perfect for me.

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()

    for r in img.find_rects(threshold = 10000):
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        print(r)

    print("FPS %f" % clock.fps())

My question is:
Who can help me to expand the “rectangle” code that the robot pick the first detected “rectangle” which was detected by the cam ?

Hi, just assign the return of find_rects() to a list.

rects = img.find_rects(…)

And then do:

if rects:
rects[0]

To get the first rect object.

is this so ok ? Where is must set the list ? Do you have an example for me ?

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    rects = img.find_rects()
    for r in img.find_rects(threshold = 10000):
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        print(r)

    print("FPS %f" % clock.fps())
    
if rects:
    rects[0]

Hi, I answer a lot of forums topics on my phone and don’t get on my PC until around 9pm to 12am PST.

Anyway, I recommend when you think you have a general purpose python question to just Google the answer:

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    rects = img.find_rects(threshold = 10000):
    for r in rects:
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        print(r)
    if rects: # Make sure list is not empty
        first_rect = rects[0] # Get first rect

    print("FPS %f" % clock.fps())

If you make the background a certain colour different from anything it has to look for then you can threshold out the back ground and what ever is left will be what your looking for. Not sure if OpenMV cam allows find blobs on the binary image left but if it does then it will find everything that is left. There is even a blob.rotation() that will give you the rotation of the blobs.

Thanks for your help

Here is a syntaxError and i dont know why

rects = img.find_rects(threshold = 10000):

The one thing the arm should pick is in a box with much other things.

Remove the semicolon at the end of the line.