I keep getting this error, but I don’t know what is the problem… I was also getting the
NameError: name ‘blob’ not defined. but then I changed the code and this error came up… Does anyone know what is the problem?
I’ll attach the code below.
import sensor, image, time #sensor
#import sensor → Import the module for sensor related functions
#import image → Import module containing machine vision algorithms
#import time → Import module for tracking elapsed time
sensor.reset() # Resets the sensor
sensor.set_pixformat(sensor.RGB565) # Sets the sensor to grayscale
sensor.set_framesize(sensor.QVGA) # Sets the resolution to 320x240 pixels
sensor.skip_frames(time = 2000) # Skip some frame to let the image stabilize
#variables:
clock = time.clock()
thresholds = (100,255)
while(True):
clock.tick()
img = sensor.snapshot().lens_corr(1.8) # Takes a snapshot and saves it to the memory
circles = img.find_circles(threshold = 3000, x_margin = 20, y_margin =20, r_margin = 20,
r_min = 2, r_max = 100, r_step = 2)
blobs = img.find_blob( [thresholds], area_threshold = 225 , merge = False)
# threshold = (100,255) defines the min/max gray scale values i'm looking for
# area_threshold = 225 : to find blobs with a minimal area of 15x15=220 pixels
# merge = False : Overlapping blobs will not be merged
for c in circles:
img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0))
print(c)
for b in blobs:
img.draw_rectangle(blob.rect(),color = 255) # Draw a rectangle where the blob was found
img.draw_cross(blob.cx(), blob.cy(), color = 255) # Draw a cross in the middle of the blob
print("FPS %f" % clock.fps())
Thanks for everything in advance!!
Miguel