Hi:
I’m a total newbie with Python. I was looking at the edge detecting example and noticed there is some random pixels. I’m trying to remove these by taking a snapshot (img), doing a high pass filter, taking another snapshot (img2), and applying a high pass filter. I’m looking at doing an and between these two images,which could reduce random pixels. The IDE doesn’t seem to recognize “image.and()”
My code:
# Edge Detection Example:
#
# This example demonstrates using the morph function on an image to do edge
# detection and then thresholding and filtering that image afterwards.
import sensor, image, time
from pyb import LED
blue_led = LED(3)
kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
kernel = [-1, -1, -1,\
-1, +8, -1,\
-1, -1, -1]
# This is a high pass filter kernel. see here for more kernels:
# http://www.fmwconcepts.com/imagemagick/digital_image_filtering.pdf
thresholds = [(100, 255)] # grayscale thresholds
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QVGA) # or sensor.QVGA (or others)
sensor.skip_frames(10) # Let new settings take affect.
clock = time.clock() # Tracks FPS.
# On the OV7725 sensor, edge detection can be enhanced
# significantly by setting the sharpness/edge registers.
# Note: This will be implemented as a function later.
if (sensor.get_id() == sensor.OV7725):
sensor.__write_reg(0xAC, 0xDF)
sensor.__write_reg(0x8F, 0xFF)
# clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
img.morph(kernel_size, kernel)
while(True):
img2 = sensor.snapshot() # Take another picture and return the image.
img2.morph(kernel_size, kernel)
img = img2.and(img)
print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
blue_led.toggle()
Any help appreciated