Example #1
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])
Example #2
0
# Untitled - By: Henry - Sat Oct 6 2018

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
clock = time.clock()

#sensor.set_saturation(3)
#sensor.set_brightness(3) #-3
#sensor.set_contrast(3)

sensor.set_windowing((40, 0, 240, 240))

while (True):
    clock.tick()
    img = sensor.snapshot()
    print(clock.fps(), \
sensor.get_rgb_gain_db())
Example #3
0
#sensor.set_saturation(1)
#sensor.set_windowing((60,0,width,height))
clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are
# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the
# camera resolution. Don't set "merge=True" becuase that will merge blobs which we don't want here.


def sortStuff(stuff):
    return stuff[4]


while (True):
    print(sensor.get_rgb_gain_db())
    print(clock.fps())
    clock.tick()
    img = sensor.snapshot()
    blobs = []
    blobs2 = [[], [], []]
    for blob in img.find_blobs(ballThresholds,
                               pixels_threshold=2,
                               area_threshold=2,
                               roi=((60, 0, width, height)),
                               x_stride=2,
                               y_stride=2):
        blobs2[0].append(blob)
    for blob in img.find_blobs(goalThresholds,
                               pixels_threshold=20,
                               area_threshold=20,
# time you turn the camera on making it hard to get
# color tracking settings right. By manually recording
# the gain values you like and then forcing them to
# the sensor on startup you can control the colors
# the camera sees.

import sensor, image, time

sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.

# You can control the white balance gains here. The first value is the
# R gain in db, and then the G gain in db, followed by the B gain in db.
#
# Uncomment the below line with gain values you like (get them from the print out).
#
# sensor.set_auto_whitebal(False, rgb_gain_db = (0.0, 0.0, 0.0))

# Note: Putting (0.0, 0.0, 0.0) for the gain results in something close to zero
# comming out. Do not expect the exact value going in to be equal to the value
# comming out.

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    print(clock.fps(), \
        sensor.get_rgb_gain_db())   # Prints the AWB current RGB gains.
Example #5
0
# time you turn the camera on making it hard to get
# color tracking settings right. By manually recording
# the gain values you like and then forcing them to
# the sensor on startup you can control the colors
# the camera sees.

import sensor, image, time

sensor.reset()  # Reset and initialize the sensor.
sensor.set_pixformat(
    sensor.GRAYSCALE)  # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)  # Set frame size to QVGA (320x240)
sensor.skip_frames(time=2000)  # Wait for settings take effect.
clock = time.clock()  # Create a clock object to track the FPS.

# You can control the white balance gains here. The first value is the
# R gain in db, and then the G gain in db, followed by the B gain in db.
#
# Uncomment the below line with gain values you like (get them from the print out).
#

# Note: Putting (0.0, 0.0, 0.0) for the gain results in something close to zero
# comming out. Do not expect the exact value going in to be equal to the value
# comming out.

while (True):
    clock.tick()  # Update the FPS clock.
    img = sensor.snapshot()  # Take a picture and return the image.
    print(clock.fps(), \
        sensor.get_rgb_gain_db())   # Prints the AWB current RGB gains.
sensor.set_pixformat(sensor_format)
sensor.set_framesize(sensor_size)
# Note that there is a -2 compared to QVGA as there looks to be a little misalignement when moving from QVGA to QQQVGA
# As we use the same remap arrays for both definitions, it is important that both are aligned
sensor.set_windowing(
    (int((sensor.width() - img_width) / 2) - 2,
     int((sensor.height() - img_height) / 2), img_width, img_height))

# wait a bit a get a snapshot
sensor.skip_frames(time=2000)
sensor.snapshot()

#get the gains and exposure
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))

# 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)
Example #7
0
#camera = Camera()
#camera.set_log_level(INFO_LOG_LEVEL)
#camera.take()
adjust_exposure(60)
sensor.set_auto_whitebal(False)
sensor.set_auto_gain(False)

l_bins = 10
for r_gain in range(-20, 0):
    for g_gain in range(-20, 0):
        for b_gain in range(0, 20, 2):
            for i in range(0, 10):

                img = sensor.snapshot()
                #camera.adjust_exposure(60)
                img.draw_string(0, 0, "r{:.3f}, g{:.3f}, b{:.3f}".format(*sensor.get_rgb_gain_db()))
                sensor.set_auto_whitebal(False, rgb_gain_db=(r_gain, g_gain, b_gain))
            #hist = img.get_histogram()
    #print(hist.a_bins())

#for l_bins in range(2, 100, 10):
    #for a_bins in range(3, 100, 10):
        #for b_bins in range(3, 100, 10):
            #for i in range(1, 5000000):
                #clock.tick()
                #img = sensor.snapshot()
                #img.draw_rectangle(line_roi)
                ##stats = img.get_statistics(line_roi, l_bins=l_bins, a_bins=a_bins, b_bins=b_bins)
                ##img.binary([(57, 93, -53, -7, -2, 37)])
                ##print(l_bins, stats.l_bins(), b_bins, "stats=", stats)
                #hist = img.get_histogram(l_bins=l_bins, a_bins=a_bins, b_bins=b_bins)
Example #8
0
while False:
    uart_out.write('TEST\n')
    utime.sleep_ms(100)

target_blue_ball_threshold_MWB = (40, 78, -55, -35, -50, 30)
target_blue_ballthreshold = (39, 56, -25, -3, -42, -16
                             )  ##Lab颜色空间中,L亮度;a的正数代表红色,负端代表绿色;b的正数代表黄色,负端代表兰色
target_lab_threshold = (45, 70, -60, -30, 0, 40)  ##?
tag_cnt = 0

while True:
    clock.tick()
    gain = sensor.get_gain_db()
    EXPO_T = sensor.get_exposure_us() / 1000  # in ms
    RGB_gain_WB = sensor.get_rgb_gain_db()
    print("Image gain: %3.1f dB" % gain)
    #print("Image gain: %3.1f dB" % gain+",RGB gain is"+str(RGB_gain_WB))
    print("Exposure T: %3.1f ms" % EXPO_T)

    img = sensor.snapshot()
    tag_cnt = 0
    #blobs = img.find_blobs([red_threshold_01],   roi = roi2,   area_threshold=1000)
    blobs = img.find_blobs([target_blue_ball_threshold_MWB],
                           roi=Target_ROI,
                           x_stride=8,
                           y_stride=8,
                           area_threshold=100,
                           pixels_threshold=100,
                           merge=True,
                           margin=20)
Example #9
0
from pyb import UART, LED

LOWER_THRESHOLD = 100
THRESHOLD = (0, LOWER_THRESHOLD)
led = LED(3)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time=2000)

sensor.set_contrast(0)
sensor.set_brightness(0)
sensor.set_saturation(0)
sensor.set_auto_exposure(False, sensor.get_exposure_us())
sensor.set_auto_whitebal(False, sensor.get_rgb_gain_db())

SENSOR_WIDTH = sensor.width()
SENSOR_HEIGHT = sensor.height()

uart = UART(3)
uart.init(9600, bits=8, parity=None, stop=1, timeout_char=1000)


def uartSend(inputStr):
    uart.writechar(ord('{'))
    for iter in inputStr:
        uart.writechar(ord(iter))
    uart.writechar(ord('}'))