Open kcuric opened 4 years ago
Implemented testing environment on local network.
# app.py
from flask import Flask, render_template, Response
import socket
import numpy as np
import cv2
host = "192.168.1.4"
port = 5005
server_address = (host, port)
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(server_address)
print('starting up on %s:%s' % server_address)
app = Flask(__name__)
def gen():
while True:
data, address = sock.recvfrom(65535)
# nparr = np.frombuffer(data, np.uint8)
# img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + data + b'\r\n')
@app.route('/')
def index():
return render_template('index.html')
@app.route('/video_feed')
def video_feed():
return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(ssl_context='adhoc')
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>DIY Survailence System</title>
</head>
<body>
<h1>DIY Survailence System</h1>
<p>Running the app.py</p>
<img src="{{ url_for('video_feed') }}">
</html>
Regarding the previous commit, without the option to reuse the addres, when trying to run the server, an error pops up saying that the address is already in use (shown in the image below).
Needed arguments for the client script:
If the user uses only one camera than providing the camera number is not necessary.
Implement the Flask web application that will be running on the created GCP VM Instance.