I am currently trying to make a program that recognizes three colors and then can detect the shape of the color. However, I have hit a problem with recognizing the colors. The third color in the threshold array is never detected. I have moved the variables around in different positions in the array, but it always doesn’t recognize the third. Can anyone tell me what my problem is? And then how I could manage to recognize the shape of the object that is being detected? I will only need to recognize a sphere, cube, and cylinder. theoretically, I could just look for rectangle and circle for the cube and sphere, then if neither of those are recognized, it would be a cylinder. I just do not know how to check within the area around the colored shape.
Here is what I have so far:
import sensor, image, time, math, pyb from pyb import Pin #Red == 1 #Blue == 2 #Yellow == 3 thresholds = [(41, 70, 46, 81, 29, 63),(75, 95, -19, 8, 53, 96),(53, 76, -21, -3, -56, -19)] sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) clock = time.clock() while(True): clock.tick() img = sensor.snapshot() for blob in img.find_blobs(thresholds, pixels_threshold=100, area_threshold=100, merge=True): if blob.code() == 1: print("Red Found") if blob.code() == 2: print("Yellow Found") if blob.code() == 3: print("Blue Found")