|
|
@ -7,8 +7,7 @@
|
|
|
|
# MJRoBot.org 19Jan18
|
|
|
|
# MJRoBot.org 19Jan18
|
|
|
|
|
|
|
|
|
|
|
|
from flask import Flask, render_template, Response, redirect, url_for, send_file, jsonify, request
|
|
|
|
from flask import Flask, render_template, Response, redirect, url_for, send_file, jsonify, request
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
import base64
|
|
|
|
|
|
|
|
# Raspberry Pi camera module (requires picamera package)
|
|
|
|
# Raspberry Pi camera module (requires picamera package)
|
|
|
|
#from camera_pi import Camera
|
|
|
|
#from camera_pi import Camera
|
|
|
|
from picamera2 import Picamera2
|
|
|
|
from picamera2 import Picamera2
|
|
|
@ -23,10 +22,6 @@ app = Flask(__name__, static_url_path='')
|
|
|
|
# 照片保存路径
|
|
|
|
# 照片保存路径
|
|
|
|
PHOTO_PATH = "photo.jpg"
|
|
|
|
PHOTO_PATH = "photo.jpg"
|
|
|
|
|
|
|
|
|
|
|
|
# picam2 = Picamera2()
|
|
|
|
|
|
|
|
# picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
|
|
|
|
|
|
|
|
# picam2.start()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def gen_frames(): # generate frame by frame from camera
|
|
|
|
def gen_frames(): # generate frame by frame from camera
|
|
|
|
picam2 = Picamera2()
|
|
|
|
picam2 = Picamera2()
|
|
|
|
picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
|
|
|
|
picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
|
|
|
@ -41,20 +36,6 @@ def gen_frames(): # generate frame by frame from camera
|
|
|
|
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
|
|
|
|
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def capture_frame():
|
|
|
|
|
|
|
|
picam2.close()
|
|
|
|
|
|
|
|
frame = picam2.capture_array() # 假设picam2是你的相机对象
|
|
|
|
|
|
|
|
ret, buffer = cv2.imencode('.jpg', frame, [int(cv2.IMWRITE_JPEG_QUALITY), 50])
|
|
|
|
|
|
|
|
img_str = base64.b64encode(buffer).decode()
|
|
|
|
|
|
|
|
picam2.start()
|
|
|
|
|
|
|
|
return img_str
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/capture_frame')
|
|
|
|
|
|
|
|
def capture_frame_route():
|
|
|
|
|
|
|
|
img_str = capture_frame()
|
|
|
|
|
|
|
|
return jsonify(img_str)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
|
|
|
def index():
|
|
|
|
return render_template('index-t.html')
|
|
|
|
return render_template('index-t.html')
|
|
|
|