def get_gain(self): """ The gain measured in gain-units. The gain range is 16 to 63 (unity gain = 16 gain-units; multiply by 1/16 to get the true gain). """ return sensor.__read_reg(0xBA)
def OV5640AF_Init(): result = sensor.__read_reg(0x3029) print('FW_STATUS: %X' % result) if result == 0x00: AFConfigFile = open('AF_REG.txt', 'r') addr = 0x8000 sensor.__write_reg(0x3000, 0x20) while True: AFConfig = AFConfigFile.readline() if not AFConfig: break str_new = AFConfig.replace(' ', '') str_new = str_new.replace(',', '') str_new = str_new.replace('0x', '') str_new = str_new[:-8] len_s = int(len(str_new) / 2) list_nums = [] i = 0 for i in range(0, len_s): chs = str_new[2 * i:2 * i + 2] num = int(chs, 16) list_nums.append(num) bys = bytes(list_nums) # print(bys) for char in bys: sensor.__write_reg(addr, char) addr += 1 sensor.__write_reg(0x3022, 0x00) sensor.__write_reg(0x3023, 0x00) sensor.__write_reg(0x3024, 0x00) sensor.__write_reg(0x3025, 0x00) sensor.__write_reg(0x3026, 0x00) sensor.__write_reg(0x3027, 0x00) sensor.__write_reg(0x3028, 0x00) sensor.__write_reg(0x3029, 0x7f) sensor.__write_reg(0x3000, 0x00) while (True): result = sensor.__read_reg(0x3029) print('FW_STATUS: %X' % result) if result != 0x7F: break sleep(500)
# In Memory Shadow Removal w/ Frame Differencing Example # # Note: You will need an SD card to run this example. # # This example demonstrates using frame differencing with your OpenMV Cam using # shadow removal to help reduce the affects of cast shadows in your scene. import sensor, image, pyb, os, time TRIGGER_THRESHOLD = 5 sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others) if sensor.get_id() == sensor.OV7725: # Reduce sensor PLL from 6x to 4x. sensor.__write_reg(0x0D, (sensor.__read_reg(0x0D) & 0x3F) | 0x40) sensor.skip_frames(time=2000) # Let new settings take affect. sensor.set_auto_whitebal(False) # Turn off white balance. sensor.set_auto_gain(False) # Turn this off too. clock = time.clock() # Tracks FPS. if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory print("About to save background image...") sensor.skip_frames(time=2000) # Give the user time to get ready. sensor.snapshot().save("temp/bg.bmp") print("Saved background image - Now frame differencing!") while (True): clock.tick() # Track elapsed milliseconds between snapshots(). img = sensor.snapshot() # Take a picture and return the image.
# Note: Actual FPS is higher, streaming the FB makes it slower. print(clock.fps()) if KEY.value() == 1: while KEY.value() == 1: blue_led.on() sleep(0.05) blue_led.off() sleep(0.05) keycount += 1 if keycount > 3: # 长按K1,释放对焦马达,镜头回到初始状态 sensor.__write_reg(0x3022, 0x08) while KEY.value() == 1: blue_led.on() sleep(0.1) blue_led.off() sleep(0.1) if keycount <= 3: sensor.__write_reg(0x3022, 0x03) # 判断对焦是否完成 if keycount != 0: # 读取对焦状态 result = sensor.__read_reg(0x3029) print('FW_STATUS: %X' % result) if result == 0x10 or result == 0x70: # 对焦完成,暂停对焦过程,使镜头将保持在此对焦位置 sensor.__write_reg(0x3022, 0x06) keycount = 0
def get_exposure_lines(self): """ The exposure measured in row-time from 1 to 2047. """ return sensor.__read_reg(0xBB)
sensor.__write_reg(0x13, 0b00000000) # disable automated gain gain_db = sensor.get_gain_db() exposure_us = sensor.get_exposure_us() rgb_gain_db = sensor.get_rgb_gain_db() print("gain_db is " + str(gain_db)) print("exposure is " + str(exposure_us)) print("rgb_gain_db is " + str(rgb_gain_db)) reg_list = [ 0x00, 0x01, 0x02, 0x03, 0x08, 0x10, 0x2d, 0x2e, 0x2f, 0x33, 0x34, 0x35, 0x36, 0x37, 0x37, 0x38 ] sensor_config = [] for i in range(0, 16): sensor_config += [sensor.__read_reg(reg_list[i])] result = interface.call("sensor_config", struct.pack("<16I", *sensor_config)) if result is not None: remote_gain_db, remote_exposure_us, remote_r_gain_db, remote_g_gain_db, remote_b_gain_db = struct.unpack( "<fIfff", result) print("sending back: " + str(remote_gain_db) + ", " + str(remote_exposure_us) + ", " + str(remote_r_gain_db) + ", " + str(remote_g_gain_db) + ", " + str(remote_b_gain_db)) if remote_exposure_us != exposure_us: print("exposure_us is " + str(exposure_us) + " but we got " + str(remote_exposure_us)) exit(1) if remote_gain_db != gain_db: print("gain_db is " + str(gain_db) + " but we got " +
# Untitled - By: aakoch - Sun Apr 22 2018 import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time=200) sensor.__write_reg(0xC, sensor.__read_reg(0x0C) | 0xC0) # flips and mirrors sensor.skip_frames(time=200) #sensor.__write_reg(0xC, sensor.__read_reg(0x0C) | 0x1) # color bars #sensor.skip_frames(time = 200) #sensor.__write_reg(0xC, sensor.__read_reg(0x0C) & 0xFE) # color bars off #sensor.skip_frames(time = 2000) #sensor.__write_reg(0xE, sensor.__read_reg(0x0E) | 0x80) # "night mode"? - I can't tell a differenct #sensor.skip_frames(time = 2000) #sensor.__write_reg(0xE, sensor.__read_reg(0x0E) & 0x7F) # "night mode" off? #sensor.skip_frames(time = 2000) sensor.set_auto_whitebal(False, (10, 0, 0)) sensor.set_auto_gain(False, 10) sensor.skip_frames(time=2000) sensor.snapshot() print("0x0=", hex(sensor.__read_reg(0x0)))
# Untitled - By: HsienYu - Thu Jun 15 2017 import sensor, time, image, math from pyb import Servo # Reset sensor sensor.reset() # Sensor settings sensor.set_contrast(1) sensor.set_gainceiling(16) # HQVGA and GRAYSCALE are the best for face tracking. sensor.set_framesize(sensor.HQVGA) sensor.set_pixformat(sensor.GRAYSCALE) sensor.__write_reg(0x0C, sensor.__read_reg(0x0C) | (1 << 7)) #Flips Camera s1 = Servo(1) # servo on position 1 (PD12, VIN, GND) s2 = Servo(2) # servo on position 1 (PD13, VIN, GND) # Load Haar Cascade # By default this will use all stages, lower satges is faster but less accurate. face_cascade = image.HaarCascade("frontalface", stages=15) # Default Pan/Tilt for the camera in degrees. # Camera range is from -90 to 90 cam_pan = 60 cam_tilt = 60 # Turn the camera to the default position """ s1.angle(0,0)
# Reset sensor sensor.reset() x = 0 y = 0 z = 0 a = 0 i = 303 j = 303 # Sensor settings sensor.set_contrast(3) sensor.set_gainceiling(16) # HQVGA and GRAYSCALE are the best for face tracking. sensor.set_framesize(sensor.HQVGA) sensor.set_pixformat(sensor.GRAYSCALE) sensor.__write_reg(0x0C, sensor.__read_reg(0x0C) | (1 << 7)) # Load Haar Cascade # By default this will use all stages, lower satges is faster but less accurate. face_cascade = image.HaarCascade("frontalface", stages=25) print(face_cascade) led = pyb.LED(3) # FPS clock clock = time.clock() while (True): clock.tick() led.on() # Capture snapshot img = sensor.snapshot() # Find objects.
# In Memory Shadow Removal w/ Frame Differencing Example # # This example demonstrates using frame differencing with your OpenMV Cam using # shadow removal to help reduce the affects of cast shadows in your scene. import sensor, image, pyb, os, time TRIGGER_THRESHOLD = 5 sensor.reset() # Initialize the camera sensor. sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others) if sensor.get_id() == sensor.OV7725: # Reduce sensor PLL from 6x to 4x. sensor.__write_reg(0x0D, (sensor.__read_reg(0x0D) & 0x3F) | 0x40) sensor.skip_frames(time = 2000) # Let new settings take affect. sensor.set_auto_whitebal(False) # Turn off white balance. sensor.set_auto_gain(False) # Turn this off too. clock = time.clock() # Tracks FPS. # Take from the main frame buffer's RAM to allocate a second frame buffer. # There's a lot more RAM in the frame buffer than in the MicroPython heap. # However, after doing this you have a lot less RAM for some algorithms... # So, be aware that it's a lot easier to get out of RAM issues now. However, # frame differencing doesn't use a lot of the extra space in the frame buffer. # But, things like AprilTags do and won't work if you do this... extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) print("About to save background image...") sensor.skip_frames(time = 2000) # Give the user time to get ready. extra_fb.replace(sensor.snapshot()) print("Saved background image - Now frame differencing!")