Я использовал raspberry pi и html для потоковой передачи видео, а затем я хотел увеличить 9 частей, чтобы сделать 9 кнопок в html, чтобы увеличить 9 конкретных частей.
Что мне нужно, так это размеризображения было 640x480. Если вы сделаете 9 экранов, разделив координаты x и y на 3 части и нажмете кнопку, я хочу, чтобы вывод был увеличен до того же размера, что и исходный размер.
------------------------------------------- appCam.py -----------------------
from flask import Flask, render_template, Response
app = Flask(__name__)
from camera_pi import Camera
import time
# get data from DHT sensor
#Original streaming video output
@app.route("/")
def index():
return render_template('index.html')
#For example, the video output corresponding to the 213x160 portion of a #640x480 streaming video (same size as the original video)
#One of nine pieces
@app.route('/camera')
def cam():
return render_template('camera.html')
@app.route('/camera1')
def cam1():
return render_template('camera1.html')
@app.route('/camera2')
def cam2():
return render_template('camera2.html')
@app.route('/camera3')
def cam3():
return render_template('camera3.html')
@app.route('/camera4')
def cam3():
return render_template('camera4.html')
@app.route('/camera5')
def cam3():
return render_template('camera5.html')
@app.route('/camera6')
def cam3():
return render_template('camera6.html')
@app.route('/camera7')
def cam3():
return render_template('camera7.html')
@app.route('/camera8')
def cam3():
return render_template('camera8.html')
@app.route('/camera9')
def cam3():
return render_template('camera9.html')
def gen(camera):
"""Video streaming generator function."""
while True:
frame = camera.get_frame()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
@app.route('/video_feed')
def video_feed():
"""Video streaming route. Put this in the src attribute of an img tag."""
return Response(gen(Camera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', port =8040, debug=True, threaded=True)
-------------------------------------- camera_pi.py ----------------------
import time
import io
import threading
import picamera
class Camera(object):
thread = None # background thread that reads frames from camera
frame = None # current frame is stored here by background thread
last_access = 0 # time of last client access to the camera
def initialize(self):
if Camera.thread is None:
# start background frame thread
Camera.thread = threading.Thread(target=self._thread)
Camera.thread.start()
# wait until frames start to be available
while self.frame is None:
time.sleep(0)
def get_frame(self):
Camera.last_access = time.time()
self.initialize()
return self.frame
@classmethod
def _thread(cls):
with picamera.PiCamera() as camera:
# camera setup
camera.resolution = (640, 480)
#camera.hflip = True
#camera.vflip = True
#camera.zoom(0.0,0.0,0.333,0.333)
# let camera warm up
time.sleep(2)
stream = io.BytesIO()
for foo in camera.capture_continuous(stream, 'jpeg',
use_video_port=True):
# store frame
stream.seek(0)
cls.frame = stream.read()
# reset stream for next frame
stream.seek(0)
stream.truncate()
# if there hasn't been any clients asking for frames in
# the last 10 seconds stop the thread
if time.time() - cls.last_access > 10:
break
cls.thread = None
------------------------ HTML ----------------------------------------------
<!doctype html>
<html>
<head>
<title>HIDATA</title>
<link rel="stylesheet" href='../static/style.css'/>
<style>
body {
text-align: center;
}
</style>
</head>
<body>
<h1>HIDATA</h1>
<h3>
<img src="{{ url_for('video_feed') }}" width="100%">
</h3>
<hr>
<h3><a href="/camera" class="button" w>ALL LIVE</a>
<br>
<br>
<a href="/camera1" class="button">1veiw</a>
<a href="/camera2" class="button">2veiw</a>
<a href="/camera3" class="button">3veiw</a>
<br>
<a href="/camera4" class="button">4veiw</a>
<a href="/camera5" class="button">5veiw</a>
<a href="/camera6" class="button">6veiw</a>
<br>
<a href="/camera7" class="button">7veiw</a>
<a href="/camera8" class="button">8veiw</a>
<a href="/camera9" class="button">9veiw</a>
</h3>
<hr>
<p></p>
</body>
</html>
Мне нужно сделать video_feed1 ~ 9, используя url_for ('video_feed'), но я не знаю, как.
Я заметил, что могу частично увеличить масштаб с помощью camera.zoom (0.0,0.0,0.333,0.333).