“MicroMV 简易照相机”的版本间的差异

来自Microduino Wikipedia
跳转至: 导航搜索
第1行: 第1行:
 
=='''硬件准备'''==
 
=='''硬件准备'''==
• MicroMV
+
• MicroMV<br/>
• TFT屏
+
• TFT屏<br/>
• 按键
+
• 按键<br/>
  
 
=='''代码准备'''==
 
=='''代码准备'''==

2018年5月16日 (三) 05:17的版本

硬件准备

• MicroMV
• TFT屏
• 按键

代码准备

import sensor, image, time, os, lcd, pyb
from pyb import Pin, LED

pinSW = Pin('P5', Pin.IN, Pin.PULL_UP)
green_led = LED(2)
blue_led  = LED(3)

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

temp = "temp"+str(pyb.rng())
num = 0

os.mkdir(temp) # Make a temp directory

pinVal = pinSW.value()
mode = 0

img = sensor.snapshot()

while(True):
    pinCache = pinVal
    pinVal = pinSW.value()
    if (pinCache==1) and (pinVal ==0):
        if(mode == 0):
            mode = 1
            lcd.deinit()
            green_led.on()
            blue_led.on()
            sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
            sensor.skip_frames(time = 500)     # Wait for settings take effect.
            print("take a shot")
            green_led.off()
            blue_led.off()
            _img = sensor.snapshot()
            _img = _img.compressed(quality=90)
            _img.save(temp+"/"+str(num)) # or "example.bmp" (or others)
            #sensor.snapshot().save(temp+"/"+str(num))
            num += 1

        else:
            mode = 0
            sensor.set_framesize(sensor.QCIF)   # Set frame size to QVGA (320x240)
            sensor.skip_frames(time = 500)     # Wait for settings take effect.
            lcd.init() # Initialize the lcd screen.

    else:
        clock.tick()                    # Update the FPS clock.
        lcd.display(img)
        print(clock.fps())              # Note: OpenMV Cam runs about half as fast when connected

    if (mode == 0):
        img = sensor.snapshot()         # Take a picture and return the image.

函数说明

 photo=sensor.snapshot()#拍照赋值给photo
 photo=photo.compressed(quality=90)#photo压缩成jpg,压缩质量为90(质量越大,损失越小)
 photo.save(temp+"/"+str(num))#保存图片到指定路径
 lcd.init()#lcd屏幕初始化
 lcd.display(img)#屏幕显示图像