# For color tracking to work really well you should ideally be in a very, very, # very, controlled enviroment where the lighting is constant. Additionally, if # you want to track more than 2 colors you need to set the boundaries for them # very narrowly. If you try to track... generally red, green, and blue then # you will end up just tracking everything which you don't want. red_threshold = ( 40, 60, 60, 90, 50, 70) blue_threshold = ( 0, 20, -10, 30, -60, 10) # You may need to tweak the above settings for tracking red and blue things... # Select an area in the Framebuffer to copy the color settings. sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed. sensor.skip_frames(10) # Let new settings take affect. sensor.set_whitebal(False) # turn this off. clock = time.clock() # Tracks FPS. while(True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image. blobs = img.find_blobs([red_threshold, blue_threshold]) merged_blobs = img.find_markers(blobs) if merged_blobs: for b in merged_blobs: # Draw a rect around the blob. img.draw_rectangle(b[0:4]) # rect img.draw_cross(b[5], b[6]) # cx, cy # Draw the color label. b[8] is the color label. img.draw_string(b[0]+2, b[1]+2, "%d" % b[8])
uart.init(128000, 8, None, 1, timeout=10) # config led led_uart = pyb.LED(2) # green led to show uart led_uart.off() led_track = pyb.LED(1) # blue led to show find target led_track.off() led_failed = pyb.LED(3) # red led to show warning led_failed.off() # cam sensor config sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # use RGB565. sensor.set_framesize(sensor.QVGA) # use QQVGA for speed. sensor.skip_frames(20) # Let new settings take affect. sensor.set_whitebal(False) # turn this off. clock = time.clock() # Tracks FPS. # set orig blob, can also call get_init_blob in Vision_contr orig_blob = (160, 82, 500) # pid init pid = initPID() while (True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image. #print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while # connected to your computer. The FPS should increase once disconnected. orient = find_speed(img, orig_blob, pid) if (orient):
# Untitled - By: akshatha_kamath - Thu Jan 17 2019 import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) #To use RGB #sensor.set_pixformat(sensor.GRAYSCALE) #to use grayscale sensor.set_framesize(sensor.QVGA) sensor.set_whitebal(False) sensor.skip_frames(time=2000) clock = time.clock() while (True): clock.tick() img = sensor.snapshot() print(clock.fps())
# recorder object RGB565 frames or Grayscale frames. Use photo editing software # like GIMP to compress and optimize the Gif before uploading it to the web. # # This example demonstrates using frame differencing with your OpenMV Cam to do # motion detection. After motion is detected your OpenMV Cam will take video. import sensor, image, time, gif, pyb, os RED_LED_PIN = 1 BLUE_LED_PIN = 3 sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others) sensor.skip_frames(10) # Let new settings take affect. sensor.set_whitebal(False) # Turn off white balance. if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory while (True): pyb.LED(RED_LED_PIN).on() print("About to save background image...") sensor.skip_frames(60) # Give the user time to get ready. pyb.LED(RED_LED_PIN).off() sensor.snapshot().save("temp/bg.bmp") print("Saved background image - Now detecting motion!") pyb.LED(BLUE_LED_PIN).on() diff = 10 # We'll say we detected motion after 10 frames of motion.
# recording a Mjpeg file you can use VLC to play it. If you are on Ubuntu then # the built-in video player will work too. # # This example demonstrates using frame differencing with your OpenMV Cam to do # motion detection. After motion is detected your OpenMV Cam will take video. import sensor, image, time, mjpeg, pyb, os RED_LED_PIN = 1 BLUE_LED_PIN = 3 sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE sensor.set_framesize(sensor.QVGA) # or sensor.QQVGA (or others) sensor.skip_frames(10) # Let new settings take affect. sensor.set_whitebal(False) # Turn off white balance. if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory while(True): pyb.LED(RED_LED_PIN).on() print("About to save background image...") sensor.skip_frames(60) # Give the user time to get ready. pyb.LED(RED_LED_PIN).off() sensor.snapshot().save("temp/bg.bmp") print("Saved background image - Now detecting motion!") pyb.LED(BLUE_LED_PIN).on() diff = 10 # We'll say we detected motion after 10 frames of motion.