import sensor, image, time, lcd, struct, ustruct, _thread
from maix import KPU,GPIO, I2S, FFT
from machine import Timer,PWM,I2C
from fpioa_manager import fm
lcd.init() # Init lcd display
lcd.clear(lcd.RED) # Clear lcd screen.
sensor.reset() # Reset and initialize the sensor.
sensor.reset(freq=24000000, dual_buff=1) # 设置摄像头频率 24M 开启双缓冲模式 会提高帧率 但内存占用增加
sensor.set_auto_exposure(1) # 设置自动曝光
sensor.set_auto_gain(False) # 颜色跟踪必须关闭自动增益
sensor.set_auto_whitebal(False) # 颜色跟踪必须关闭白平衡
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.set_windowing((224,224)) # 分辨率为B224X224
sensor.skip_frames(time = 2000) # Wait for settings take effect.
clock = time.clock() # Create a clock object to track the FPS.
fm.register(35, fm.fpioa.GPIO0)
fm.register(16, fm.fpioa.GPIOHS0)
KEY=GPIO(GPIO.GPIOHS0, GPIO.IN, GPIO.PULL_UP)
global state,key_node,need_number_ficture
need_number_ficture=need_number_ficture+1
if(need_number_ficture == 9):
KEY.irq(fun, GPIO.IRQ_FALLING)
tim = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PWM)
beep = PWM(tim, freq=1000, duty=0, pin=9)
clock = time.clock() # 创建一个clock对象,用来计算帧率
clock.tick() # 更新计算帧率的clock
img.save("img/"+str(need_number_ficture)+"/"+str(save_count)+".jpg")
img.draw_string(0, 10,str(need_number_ficture)+"/"+str(save_count)+".jpg", color = (200, 0, 0), scale = 2, mono_space = False,
char_rotation = 0, char_hmirror = False, char_vflip = False,
string_rotation = 0, string_hmirror = False, string_vflip = False)