Count the white pixels on image

Hi,
Theres any exemple of using greyscale YUV color space converted to monochrome and return the number of white points on image?

With the best Regards,
João

Call the find_blobs(), pass color thresholds which look for white, then sum the pixels() value for each blob up. See the grayscale color tracking example to get started.

Hi kwagyeman,

Thank you for the answer. Currenctly my code is:

import sensor, image, time, math
thresholds = (245, 255)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 3000) #Just to understand if the sensor needs time before start
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()
while(True):
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds], pixels_threshold=10, area_threshold=10, merge=True):
        x = blob.pixels()

        img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=90, color=127)
    sensor.flush()
    print(clock.fps(), x)

But some times i recive the error saying the ‘x’ isn’t defined.
Could you please help me and understand if this is the better code for the solution?

With the best regards,
Joao

import sensor, image, time, math
thresholds = (245, 255)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 3000) #Just to understand if the sensor needs time before start
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()
while(True):
    clock.tick()
    img = sensor.snapshot()
    blobs = img.find_blobs([thresholds], pixels_threshold=10, area_threshold=10, merge=True)
    for blob in blobs:
        img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=90, color=127)
    white_pixels = sum(blob.pixels() for blob in blobs)
    print(clock.fps(), white_pixels)

You should read up on python lists and how to work with them. This is what makes python so powerful on the OpenMV Cam.

Thank you everyone.

Could you please explain how to define a color to find? if i want to search for black or red for exemple.

With the best regards,
Joao

Please see the color tracking examples. Color tracking is done in the LAB color space. Tracking is done by thresholding the image with min/maxes for the 3 LAB color channels. This means you need to pass a 6-tuple value to methods to track colors.

The color tracking examples explain this.