use of blob.cx()

General discussion about topics related to OpenMV.
sri
Posts: 9
Joined: Tue May 08, 2018 2:16 am
Location: thirunallar,karaikal

use of blob.cx()

Postby sri » Thu Jun 07, 2018 3:15 am

hi,
iam using openmv cam m4 and in this lilnk( http://docs.openmv.io/library/omv.image.html ) you have given that blob.cx() will Return the centroid x position of the blob.My doubt is that suppose if i track red colour object and i vary the distance from red coloured object to openmv cam upto what extent the cam will give accurate blob.cx() value.
thank you,
User avatar
kwagyeman
Posts: 2121
Joined: Sun May 24, 2015 2:10 pm

Re: use of blob.cx()

Postby kwagyeman » Thu Jun 07, 2018 12:09 pm

Hi, the camera has a field of view. So, unless the object is exactly in the center of the field of view the object's cx() value will move around.

That said, if you were to place the object exactly in the center of the camera's view the cx() value will not change as the distance changes then.
Nyamekye,
sri
Posts: 9
Joined: Tue May 08, 2018 2:16 am
Location: thirunallar,karaikal

Re: use of blob.cx()

Postby sri » Fri Jun 08, 2018 1:11 am

ohh, thank you sir but in my project i have to find the position of different white coloured and red coloured objects at one shot how can i do that by using openmv kindly help me to overcome this problem.
thank you,
Attachments
IMG20180529095555(1)(1).jpg
IMG20180529095555(1)(1).jpg (2.12 MiB) Viewed 278 times
User avatar
kwagyeman
Posts: 2121
Joined: Sun May 24, 2015 2:10 pm

Re: use of blob.cx()

Postby kwagyeman » Fri Jun 08, 2018 12:07 pm

Hi, you showed me this before. Please see go to examples -> Color Tracking -> Single RGB565 color tracking and then edit the color thresholds in that script using Tools -> Machine Vision -> Threshold Editor.

The script will show you all the positions of everything in the field of view as long as you set the thresholds correctly.
Nyamekye,
sri
Posts: 9
Joined: Tue May 08, 2018 2:16 am
Location: thirunallar,karaikal

Re: use of blob.cx()

Postby sri » Sat Jun 09, 2018 12:41 am

thank you very much sir
sri
Posts: 9
Joined: Tue May 08, 2018 2:16 am
Location: thirunallar,karaikal

Re: use of blob.cx()

Postby sri » Sat Jun 09, 2018 5:22 am

thank you very much sir,So in order to calculate the distance of various blobs we need not to calculate angle of field of view, Field of view and all .openmv cam itself will give the correct position of different blobs.
User avatar
kwagyeman
Posts: 2121
Joined: Sun May 24, 2015 2:10 pm

Re: use of blob.cx()

Postby kwagyeman » Sat Jun 09, 2018 11:49 am

Hi, it's not really possible to get the distance to and object using just one camera and vision reliablely. The size of the object on screen is related to the distance in a 1/d^2 way. E.g. as the object gets farther away the number of pixels in the object changes minimally related to the distance. That said, if the object is really close the relationship is linearish then and you can use a lookup table to map pixels to distance (or a piece wise linear function).

Whatever the case, you have to hand calculate the piece wise lookup table by measuring the object at each distance and recording the number of pixels. Then, you build interpolate any new pixel value to a distance between whatever measurements you made previously. In code this looks like a bunch of if statements.
Nyamekye,
sri
Posts: 9
Joined: Tue May 08, 2018 2:16 am
Location: thirunallar,karaikal

Re: use of blob.cx()

Postby sri » Tue Jun 12, 2018 4:56 am

hi,somehow blob.cx() gives the approximate value its enough for me.In my project i have to take the snapshot and than i have to send the different blob.cx() value to the raspberry pi how can i do this.
User avatar
iabdalkader
Posts: 503
Joined: Sun May 24, 2015 3:53 pm

Re: use of blob.cx()

Postby iabdalkader » Sun Jun 24, 2018 6:33 pm

sri wrote:
Tue Jun 12, 2018 4:56 am
hi,somehow blob.cx() gives the approximate value its enough for me.In my project i have to take the snapshot and than i have to send the different blob.cx() value to the raspberry pi how can i do this.
Hi, please search the forums for serial you'll find many examples for doing that.
User avatar
kwagyeman
Posts: 2121
Joined: Sun May 24, 2015 2:10 pm

Re: use of blob.cx()

Postby kwagyeman » Tue Jun 26, 2018 1:40 am

Here's an example:

Code: Select all

# Single Color RGB565 Blob Tracking Example
#
# This example shows off single color RGB565 tracking using the OpenMV Cam.

import sensor, image, time

threshold_index = 0 # 0 for red, 1 for green, 2 for blue

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)
# The below thresholds track in general red/green/blue things. You may wish to tune them...
thresholds = [(30, 100, 15, 127, 15, 127), # generic_red_thresholds
              (30, 100, -64, -8, -32, 32), # generic_green_thresholds
              (0, 30, 0, 64, -128, 0)] # generic_blue_thresholds

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. "merge=True" merges all overlapping blobs in the image.

from pyb import UART

# Always pass UART 3 for the UART number for your OpenMV Cam.
# The second argument is the UART baud rate. For a more advanced UART control
# example see the BLE-Shield driver.
uart = UART(3, 19200, timeout_char = 1000)

while(True):
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds[threshold_index]], pixels_threshold=200, area_threshold=200, merge=True):
        img.draw_rectangle(blob.rect())
        img.draw_cross(blob.cx(), blob.cy())
        uart.write(str(blob.cx()) + '\n')
    print(clock.fps())
Nyamekye,

Return to “General Topics”

Who is online

Users browsing this forum: No registered users and 2 guests