Hi,
I’m trying to apply some dithering algo to an image with that code, but the set_pixel function doesn’t seem to have any effect.
# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
import sensor, image, time, lcd
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # Set frame size to QVGA (320x240)
sensor.skip_frames(10) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
lcd.init()
kernel_2x2 = [[0, 2], [3, 1]]
def coef(kernel, i, j):
return 255 * (1 + kernel[i][j]) / (1 + len(kernel) * len(kernel[0]))
def ordered_dithering(img, kernel):
height_img, width_img =(img.height(), img.width())
height_kernel, width_kernel = (len(kernel), len(kernel[0]))
for x in range(width_img, width_kernel):
for y in range(height_img, height_kernel):
for i in range(width_kernel):
for j in range(height_kernel):
pixel = 255 if img.get_pixel(x + i, y + j) < coef(kernel, i, j) else 0
img.set_pixel(x + i, y + j, pixel)
img.draw_string(0, 0, "h: %d, w: %d" % (height_img, width_img))
img.draw_string(0, 10, "h: %d, w: %d" % (height_kernel, width_kernel))
return img
while(True):
clock.tick() # Update the FPS clock.
img = sensor.snapshot() # Take a picture and return the image.
bw = ordered_dithering(img, kernel_2x2)
lcd.display(bw)
print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected
# to the IDE. The FPS should increase once disconnected.
On the lcd, I can see the text, but pixel values are not changing. Do I miss something ?
Thanks