万博网页版登陆页派论坛

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

xiaowwwwww 发表于 2020-9-10 13:30:44 | 显示全部楼层 |阅读模式
切换分辨率的时候遇到bug: 1599710813(1).jpg
附上代码: 万博网页版登陆页派端:
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代码: 1599710243(1).png 1599710379(1).jpg
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版 | Archiver | 万博网页版登陆页派论坛 ( 粤ICP备15075382号-1 )