xiaowwwwww 发表于 2020-9-10 13:30:44

【新人求助】网页控制万博网页版登陆页派摄像头改变分辨率,并将图片传到网页,但是遇到了一个bug

切换分辨率的时候遇到bug:
附上代码: 万博网页版登陆页派端:
from flask import Flask, render_template, Response, request
import cv2
import io
import time
import numpy as np
from time import sleep

app = Flask(__name__)

class VideoCamera(object):
def __init__(self, width, height): # 初始化相机

self.video = cv2.VideoCapture(0)
self.width = width
self.height = height
self.video.set(3, width)
self.video.set(4, height)

def __del__(self):
self.video.release()

def get_frame(self):
success, image = self.video.read()
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()

@app.route('/') #主页
def index():
return render_template('index.html')

def gen(camera):
while True:
frame = camera.get_frame()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')

@app.route('/video_feed') # 这个地址返回视频流响应
def video_feed():
camera0 = VideoCamera(640, 480)
return Response(gen(camera0),
mimetype='multipart/x-mixed-replace; boundary=frame')

@app.route('/720p')
def index_1():
return render_template('index1.html')

def gen1(camera):
while True:
time1 = time.time()
frame = camera.get_frame()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
time2 = time.time()
print(time2 - time1)

@app.route('/video_feed1') # 这个地址返回视频流响应
def video_feed1():
camera0 = VideoCamera(1280, 720)
return Response(gen1(camera0),
mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
app.run(host='0.0.0.0', debug = True, port = 8888)


HTML代码:
页: [1]
查看完整版本: 【新人求助】网页控制万博网页版登陆页派摄像头改变分辨率,并将图片传到网页,但是遇到了一个bug