diff --git a/carsrun/appCam.py b/carsrun/appCam.py index d35ba90..da41158 100644 --- a/carsrun/appCam.py +++ b/carsrun/appCam.py @@ -7,7 +7,8 @@ # MJRoBot.org 19Jan18 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) #from camera_pi import Camera from picamera2 import Picamera2 @@ -22,6 +23,10 @@ app = Flask(__name__, static_url_path='') # 照片保存路径 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 picam2 = Picamera2() picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)})) @@ -36,6 +41,20 @@ 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 + +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('/') def index(): return render_template('index-t.html') diff --git a/carsrun/car.py b/carsrun/car.py index f6b1743..81f8b14 100644 --- a/carsrun/car.py +++ b/carsrun/car.py @@ -94,4 +94,11 @@ class CAR: def yunright(self): self.input_x+=10 - base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc) \ No newline at end of file + base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc) + + def guiwei(self): + self.input_x = 2 + self.input_y = 2 + self.input_speed = 0 + base.gimbal_base_ctrl(self.input_x, self.input_y, self.input_speed) + \ No newline at end of file diff --git a/carsrun/templates/index-t.html b/carsrun/templates/index-t.html index 0279e62..2c6c302 100644 --- a/carsrun/templates/index-t.html +++ b/carsrun/templates/index-t.html @@ -20,10 +20,14 @@ background: #e8080b; } + Capture Frame +
实时视频流
+ +

小车控制界面

小车控制 @@ -94,6 +98,23 @@