def light_mode_night():
    #sensor.__write_reg(addr, reg&mask)
    sensor.__write_reg(0x13, 0xff)  #AWB on
    sensor.__write_reg(0x0e, 0xe5)
    sensor.__write_reg(0x11, 0x03)
    sensor.__write_reg(0x22, 0x7f)
    #60Hz banding filter
    sensor.__write_reg(0x23, 0x03)
Пример #2
0
def sensor_config(data):
    global processing
    sensor_regs = struct.unpack("<16I", data)
    reg_list = [
        0x00, 0x01, 0x02, 0x03, 0x08, 0x10, 0x2d, 0x2e, 0x2f, 0x33, 0x34, 0x35,
        0x36, 0x37, 0x37, 0x38
    ]
    i = 0
    for sr in sensor_regs:
        sensor.__write_reg(reg_list[i], sr)
        i += 1

    gain_db = sensor.get_gain_db()
    exposure_us = sensor.get_exposure_us()
    rgb_gain_db = sensor.get_rgb_gain_db()

    processing = False
    return struct.pack("<fIfff", gain_db, exposure_us, rgb_gain_db[0],
                       rgb_gain_db[1], rgb_gain_db[2])
Пример #3
0
 def init(self, gain_db = 0, shutter_us = 500000, framesize = sensor.WQXGA2, force_reset = True, flip = False):
     if self.simulate:
         self.shutter = shutter_us
         self.gain = gain_db
         self.snap_started = False
         return
     if force_reset or self.has_error or self.gain != gain_db or self.shutter != shutter_us or self.framesize != framesize or self.flip != flip:
         sensor.reset()
         sensor.set_pixformat(self.pixfmt)
         sensor.set_framesize(framesize)
         if flip: # upside down camera
             sensor.set_vflip(True)
             sensor.set_hmirror(True)
         self.flip = flip
         self.framesize = framesize
         if shutter_us < 0:
             sensor.set_auto_exposure(True)
         else:
             if shutter_us > 500000:
                 sensor.__write_reg(0x3037, 0x08)   # slow down PLL
                 if shutter_us > 1000000:
                     pyb.delay(100)
                     sensor.__write_reg(0x3037, 0x18)   # slow down PLL
                     if shutter_us > 2750000:
                         pyb.delay(100)
                         sensor.__write_reg(0x3036, 40) # slow down PLL
                     # warning: doesn't work well, might crash
                     elif shutter_us > 1500000:
                         pyb.delay(100)
                         sensor.__write_reg(0x3036, 80) # slow down PLL
                         # warning: doesn't work well, might crash
                 pyb.delay(200)
             sensor.set_auto_exposure(False, shutter_us)
         self.shutter = shutter_us
         if gain_db < 0:
             sensor.set_auto_gain(True)
         else:
             sensor.set_auto_gain(False, gain_db)
         self.gain = gain_db
         self.wait_init = 2
         self.width = sensor.width()
         self.height = sensor.height()
def light_mode_home():
    sensor.__write_reg(0x13, 0xfd)  #AWB off
    sensor.__write_reg(0x01, 0x96)
    sensor.__write_reg(0x02, 0x40)
    sensor.__write_reg(0x03, 0x80)
    sensor.__write_reg(0x0e, 0x65)
    sensor.__write_reg(0x2d, 0x00)
    sensor.__write_reg(0x2e, 0x00)

    sensor.__write_reg(0x22, 0x7f)
    #60Hz banding filter
    sensor.__write_reg(0x23, 0x03)
# 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!")
Пример #6
0
          -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.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(time = 2000) # 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)

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    img.morph(kernel_size, kernel)
    img.binary(thresholds)

    # Erode pixels with less than 2 neighbors using a 3x3 image kernel
    img.erode(1, threshold = 2)

    print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    # connected to your computer. The FPS should increase once disconnected.
Пример #7
0
        img.draw_rectangle(r)

    # Print FPS.
    # 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:
            # 对焦完成,暂停对焦过程,使镜头将保持在此对焦位置
Пример #8
0
# Create and init RTC object.
rtc = pyb.RTC()

# (year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])
rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))

# Print RTC info.
print(rtc.datetime())

sensor.reset()

# Enable sensor softsleep
sensor.sleep(True)

# Optionally bypass the regulator on OV7725
# for the lowest possible power consumption.
if (sensor.get_id() == sensor.OV7725):
    # Bypass internal regulator
    sensor.__write_reg(0x4F, 0x18)

# Shutdown the sensor (pulls PWDN high).
sensor.shutdown(True)

# Enable RTC interrupts every 30 seconds.
# Note the camera will RESET after wakeup from Deepsleep Mode.
rtc.wakeup(30000)

# Enter Deepsleep Mode.
machine.deepsleep()
print("gain_db is " + str(gain_db))
print("exposure is " + str(exposure_us))
print("rgb_gain_db is " + str(rgb_gain_db))

# Set the gain and exposure as fixed (not concerned about the values)
sensor.set_auto_gain(False, gain_db)
sensor.set_auto_exposure(False, exposure_us)
sensor.set_auto_whitebal(False, rgb_gain_db)

# Setup contrast, brightness and saturation
sensor.set_contrast(0)  # range -3 to +3
sensor.set_brightness(0)  # range -3 to +3
sensor.set_saturation(0)  # range -3 to +3

# Disable night mode (auto frame rate) and black level calibration (BLC)
sensor.__write_reg(0x0E, 0b00000000)  # Disable night mode
sensor.__write_reg(0x3E, 0b00000000)  # Disable BLC

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
]
Пример #10
0
# 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)))
Пример #11
0
# 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)
def light_mode_night():
    #sensor.__write_reg(addr, reg&mask)
    sensor.__write_reg(0x13, 0xff)  #AWB on
    sensor.__write_reg(0x0e, 0xe5)
    sensor.__write_reg(0x11, 0x03);
def light_mode_home():
    sensor.__write_reg(0x13, 0xfd)  #AWB off
    sensor.__write_reg(0x01, 0x06)
    sensor.__write_reg(0x02, 0x40)
    sensor.__write_reg(0x0e, 0x65)
    sensor.__write_reg(0x2d, 0x00)
    sensor.__write_reg(0x2e, 0x00)
def light_mode_auto():
    #sensor.__write_reg(addr, reg&mask)
    sensor.__write_reg(0x13, 0xff)  #AWB off
    sensor.__write_reg(0x0e, 0x65)
    sensor.__write_reg(0x2d, 0x00)
    sensor.__write_reg(0x2e, 0x00)
Пример #15
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.
Пример #16
0
import sensor, image, time, fir

# Reset sensor
sensor.reset()

# Set sensor settings
sensor.set_contrast(1)
sensor.set_brightness(0)
sensor.set_saturation(2)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)

# The following registers fine-tune the image
# sensor window to align it with the FIR sensor.
if (sensor.get_id() == sensor.OV2640):
    sensor.__write_reg(0xFF, 0x01) # switch to reg bank
    sensor.__write_reg(0x17, 0x19) # set HSTART
    sensor.__write_reg(0x18, 0x43) # set HSTOP

# Initialize the thermal sensor
fir.init()

# FPS clock
clock = time.clock()

while (True):
    clock.tick()

    # Capture an image
    image = sensor.snapshot()
Пример #17
0
mlx.init(mlx.IR_REFRESH_64HZ)

# Reset sensor
sensor.reset()

# Set sensor settings
sensor.set_contrast(1)
sensor.set_brightness(0)
sensor.set_saturation(2)
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA)

# The following registers fine-tune the image
# sensor window to align it with the FIR sensor.
if (sensor.get_id() == sensor.OV2640):
    sensor.__write_reg(0xFF, 0x01)  # switch to reg bank
    sensor.__write_reg(0x17, 0x19)  # set HSTART
    sensor.__write_reg(0x18, 0x43)  # set HSTOP

# FPS clock
clock = time.clock()

# Ambient temperature
ta = 0.0
# Minimum object temperature
to_min = 0.0
# Maximum object temperature
to_max = 0.0

while (True):
    clock.tick()
    # Send multipart header
    client.send("HTTP/1.1 200 OK\r\n"   \
                "Server: OpenMV\r\n"    \
                "Content-Type: multipart/x-mixed-replace;boundary=openmv\r\n" \
                "Cache-Control: no-cache\r\n" \
                "Pragma: no-cache\r\n\r\n")

# 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

# 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)

while (test):
    clock.tick()  # Update the FPS clock.
    img = sensor.snapshot()  # Take a picture and return the image.
    if enable_lens_corr: img.lens_corr(2.0)  # for 2.8mm lens...
    #img.save("bg.bmp")              # Used to superimpose picture over obs indicators
    img.mean(2)
    img.find_edges(image.EDGE_CANNY)
    img.binary(thresholds)
    img.erode(1, threshold=2)

    EdgeArray = []
    EdgeDiff = []
    ObsArray = []
Пример #19
0
    d_term = (de / dt) * kd

    old_error = error
    output = steering_direction * (p_term + i_term + d_term)
    output = constrain(output, -50, 50)
    return output


# Compute the weight divisor (we're computing this so you don't have to make weights add to 1).
weight_sum = 0
for r in ROIS: weight_sum += r[4] # r[4] is the roi weight.

# Camera setup...
clock = time.clock() # Tracks FPS.
sensor.reset() # Initialize the camera sensor.
sensor.__write_reg(0x6B, 0x22)  # switches camera into advanced calibration mode. See this for more: http://forums.openmv.io/viewtopic.php?p=1358#p1358
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
sensor.set_vflip(True)
sensor.set_hmirror(True)
sensor.set_auto_gain(True)    # do some calibration at the start
sensor.set_auto_whitebal(True)
sensor.skip_frames(time = 0)  # When you're inside, set time to 2000 to do a white balance calibration. Outside, this can be 0
sensor.set_auto_gain(False)   # now turn off autocalibration before we start color tracking
sensor.set_auto_whitebal(False)


while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot().histeq() # Take a picture and return the image. The "histeq()" function does a histogram equalization to compensate for lighting changes
    print("FPS: ",clock.fps())
def light_mode_cloudy():
    sensor.__write_reg(0x13, 0xfd)  #AWB off
    sensor.__write_reg(0x01, 0x58)
    sensor.__write_reg(0x02, 0x60)
    sensor.__write_reg(0x03, 0x80)
    sensor.__write_reg(0x0e, 0x65)
    sensor.__write_reg(0x2d, 0x00)
    sensor.__write_reg(0x2e, 0x00)
Пример #21
0
def OV5640AF_Init():
    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(0.5)
def light_mode_office():
    sensor.__write_reg(0x13, 0xfd)
    sensor.__write_reg(0x01, 0x84)
    sensor.__write_reg(0x02, 0x4c)
    sensor.__write_reg(0x03, 0x80)
    sensor.__write_reg(0x0e, 0x65)
    sensor.__write_reg(0x2d, 0x00)
    sensor.__write_reg(0x22, 0x7f)
    #60Hz banding filter
    sensor.__write_reg(0x23, 0x03)
Пример #23
0
# 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.
def light_mode_auto():
    #sensor.__write_reg(addr, reg&mask)
    sensor.__write_reg(0x13, 0xff)  #AWB off
    sensor.__write_reg(0x0e, 0x65)
    sensor.__write_reg(0x2d, 0x00)
    sensor.__write_reg(0x2e, 0x00)

    sensor.__write_reg(0x22, 0x89)
    #60Hz banding filter
    sensor.__write_reg(0x23, 0x03)