Hello. Good day, Sir.
I tried to do the guide you gave me Sir…
Right now, I’m not sure of the values I got in serial terminal, it ranges from 14161.0 to 14932.0.
Also, is it possible to draw a line (between) from one point detected to another point, like the image I attached? The first photo is the original picture, the second one is edited (i put lines to connect the center of detect point, for illustration)
So far, this is the code, sir:
import sensor, image, time, math
#Thresholds (L Min, L Max, A Min, A Max, B Min, B Max).
thresholds = [(38, 47, -20, -9, -28, -12),
(15, 27, -19, 6, -23, 6),
(38, 61, -27, -8, -28, -1),
(18, 31, -20, 6, -31, 1),
(16, 32, -16, 7, -23, 0),
(24, 34, -13, 7, -26, -7),
(9, 50, -12, 14, -26, -1),
(17, 37, -18, 10, -26, -3),
(37, 62, -14, 16, -59, -30),
(35, 48, -2, 26, -64, -41),
(29, 52, -12, 24, -62, -28)] # threshold_value_of_points
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()
def polygon_area(corners):
n=len(corners)
area=0.0
for i in range(n):
j=(i+1)%n
area+=corners[i][0]*corners[j][1]
area-=corners[j][0]*corners[i][1]
area = abs(area)/2.0
return area
while(True):
clock.tick()
img = sensor.snapshot()
for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200):
if blob.elongation() > 0.5:
img.draw_edges(blob.min_corners(), color=(255,0,0))
img.draw_line(blob.major_axis_line(), color=(0,255,0))
img.draw_line(blob.minor_axis_line(), color=(0,0,255))
img.draw_rectangle(blob.rect(),thickness=5)
img.draw_cross(blob.cx(), blob.cy())
corners = [(blob.cx(), blob.cy())for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200)]
print(polygon_area(corners))