automatic Pick & Place robot arm with MV

OpenMV related project discussion.
shelly_beck
Posts: 4
Joined: Thu Jun 21, 2018 4:28 am

automatic Pick & Place robot arm with MV

Postby shelly_beck » Thu Jun 21, 2018 4:41 am

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.

Code: Select all

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 ?
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: automatic Pick & Place robot arm with MV

Postby kwagyeman » Thu Jun 21, 2018 1:08 pm

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.
Nyamekye,
shelly_beck
Posts: 4
Joined: Thu Jun 21, 2018 4:28 am

Re: automatic Pick & Place robot arm with MV

Postby shelly_beck » Fri Jun 22, 2018 2:13 am

kwagyeman wrote:
Thu Jun 21, 2018 1:08 pm
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 ?

Code: Select all

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]
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: automatic Pick & Place robot arm with MV

Postby kwagyeman » Fri Jun 22, 2018 2:39 am

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:

Code: Select all

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())
Nyamekye,
OutoftheBOTS
Posts: 87
Joined: Tue May 29, 2018 4:15 am

Re: automatic Pick & Place robot arm with MV

Postby OutoftheBOTS » Fri Jun 22, 2018 2:42 am

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.
shelly_beck
Posts: 4
Joined: Thu Jun 21, 2018 4:28 am

Re: automatic Pick & Place robot arm with MV

Postby shelly_beck » Fri Jun 22, 2018 3:09 am

kwagyeman wrote:
Fri Jun 22, 2018 2:39 am
Hi, I answer a lot of forums topics on my phone and don't get on my PC until around 9pm to 12am PST.
Thanks for your help

Here is a syntaxError and i dont know why

Code: Select all

rects = img.find_rects(threshold = 10000):
shelly_beck
Posts: 4
Joined: Thu Jun 21, 2018 4:28 am

Re: automatic Pick & Place robot arm with MV

Postby shelly_beck » Fri Jun 22, 2018 3:14 am

OutoftheBOTS wrote:
Fri Jun 22, 2018 2:42 am
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.
The one thing the arm should pick is in a box with much other things.
User avatar
kwagyeman
Posts: 2202
Joined: Sun May 24, 2015 2:10 pm

Re: automatic Pick & Place robot arm with MV

Postby kwagyeman » Fri Jun 22, 2018 3:29 am

Remove the semicolon at the end of the line.
Nyamekye,

Return to “Project Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest