2018年1月

Flask 是 Python 的一款轻量化Web框架,使用Flask可以快速完成Web应用的开发。

1 安装

Pip 方式:

pip install flask

Apt方式:

sudo apt-get install python-flask

在pip安装不了时使用apt强制安装

2 一个最小的应用

from flask import Flask #引用
app = Flask(__name__)

@app.route('/') #路由
def hello_world():
    return 'Hello World!' #返回

if __name__ == '__main__':
    app.run(host='0.0.0.0',port=80) #全IP访问,80端口

使用Armbian系统可以很方便的使用h3disp来设置。

root@orangepione:~# h3disp -m
    480i        use "-m 480i" or "-m 0"
    576i        use "-m 576i" or "-m 1"
    480p        use "-m 480p" or "-m 2"
    576p        use "-m 576p" or "-m 3"
    720p50      use "-m 720p50" or "-m 4"
    720p60      use "-m 720p60" or "-m 5"
    1080i50     use "-m 1080i50" or "-m 6"
    1080i60     use "-m 1080i60" or "-m 7"
    1080p24     use "-m 1080p24" or "-m 8"
    1080p50     use "-m 1080p50" or "-m 9"
    1080p60     use "-m 1080p60" or "-m 10"
    1080p25     use "-m 1080p25" or "-m 11"
    1080p30     use "-m 1080p30" or "-m 12"
    1080p24_3d  use "-m 1080p24_3d" or "-m 13"
    720p50_3d   use "-m 720p50_3d" or "-m 14"
    720p60_3d   use "-m 720p60_3d" or "-m 15"
    1080p24_3d  use "-m 1080p24_3d" or "-m 23"
    720p50_3d   use "-m 720p50_3d" or "-m 24"
    720p60_3d   use "-m 720p60_3d" or "-m 25"
    1080p25     use "-m 1080p25" or "-m 26"
    1080p30     use "-m 1080p30" or "-m 27"
    4kp30       use "-m 4kp30" or "-m 28"
    4kp25       use "-m 4kp25" or "-m 29"
    800x480     use "-m 800x480" or "-m 31"
    1024x768    use "-m 1024x768" or "-m 32"
    1280x1024   use "-m 1280x1024" or "-m 33"
    1360x768    use "-m 1360x768" or "-m 34"
    1440x900    use "-m 1440x900" or "-m 35"
    1680x1050   use "-m 1680x1050" or "-m 36"
    2048x1536   use "-m 2048x1536" or "-m 37"

 Two examples:
    'h3disp -m 1080p60 -d' (1920x1080@60Hz DVI)
    'h3disp -m 720i' (1280x720@30Hz HDMI)

1.安装PyGame(Apt方式):

sudo apt-get install python-pygame

2.安装PyGame(Pip方式):

pip install pygame

3.代码

import pygame
import pygame.camera
from pygame.locals import *  #引用

pygame.init()
pygame.camera.init()  #初始化

camera = pygame.camera.Camera("/dev/video0", (1280, 720))  #指定设备,设置宽度高度
camera.start()
image = camera.get_image()  #Get
pygame.image.save(image, "image.jpg")  #保存
camera.stop()