Binary file not shown.
@ -1,31 +1,46 @@
|
||||
from flask import Flask, render_template, Response
|
||||
from picamera2 import Picamera2
|
||||
import time
|
||||
from flask import Flask, request, jsonify
|
||||
import cv2
|
||||
import threading
|
||||
import time
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
def gen_frames(): # generate frame by frame from camera
|
||||
picam2 = Picamera2()
|
||||
picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
|
||||
picam2.start()
|
||||
while True:
|
||||
# Capture frame-by-frame
|
||||
frame = picam2.capture_array() # read the camera frame
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
ret, buffer = cv2.imencode('.jpg', frame)
|
||||
frame = buffer.tobytes()
|
||||
yield (b'--frame\r\n'
|
||||
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
return render_template('index.html')
|
||||
|
||||
@app.route('/video_feed')
|
||||
def video_feed():
|
||||
#Video streaming route. Put this in the src attribute of an img tag
|
||||
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundary=frame')
|
||||
# 设置存储照片的目录路径
|
||||
photo_path = '/Desktop/cars/photo/'
|
||||
|
||||
# 初始化摄像头
|
||||
camera = cv2.VideoCapture(-1)
|
||||
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
|
||||
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
|
||||
|
||||
# 初始化变量
|
||||
photo_num_count = 0
|
||||
capture_lock = threading.Lock()
|
||||
last_photo_time = time.time()
|
||||
|
||||
# 拍照函数
|
||||
def capture_photo():
|
||||
global photo_num_count
|
||||
with capture_lock:
|
||||
ret, frame = camera.read()
|
||||
if ret:
|
||||
photo_num_count += 1
|
||||
photo_filename = f'{photo_path}photo_{photo_num_count}.jpg'
|
||||
cv2.imwrite(photo_filename, frame)
|
||||
print(f'{photo_num_count} photos saved. new photo: {photo_filename}')
|
||||
|
||||
# 拍照请求处理
|
||||
@app.route('/photo', methods=['POST'])
|
||||
def photo():
|
||||
capture_photo()
|
||||
return jsonify({"status": "photo captured"})
|
||||
|
||||
# 停止请求处理
|
||||
@app.route('/stop', methods=['POST'])
|
||||
def stop():
|
||||
camera.release()
|
||||
print("Camera stopped")
|
||||
return jsonify({"status": "camera stopped"})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
app.run(host='0.0.0.0', port=5000)
|
After Width: | Height: | Size: 61 KiB |
@ -0,0 +1,218 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<script src="http://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script>
|
||||
<meta charset="utf-8">
|
||||
<title>Live Video Based on Flask</title>
|
||||
<link rel="stylesheet" href='/style.css'/>
|
||||
<style type="text/css">
|
||||
#front {
|
||||
margin-left: 40px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
#rear{
|
||||
margin-top: 3px;
|
||||
margin-left: 40px;
|
||||
}
|
||||
.btn{
|
||||
background: #e8080b;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h5>实时视频流</h5>
|
||||
<img src="{{ url_for('video_feed') }}">
|
||||
<p> 小车控制界面</p>
|
||||
<bodylink = "red">
|
||||
<a href="control" target="_blank">小车控制</a>
|
||||
|
||||
|
||||
<!-- 添加文本传输的输入框和按钮 -->
|
||||
<div class="form-group">
|
||||
<label for="inputIp">目标服务器 IP 地址:</label>
|
||||
<input type="text" class="form-control" id="inputIp" placeholder="输入 IP 地址">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputPort">目标服务器 端口:</label>
|
||||
<input type="text" class="form-control" id="inputPort" placeholder="输入端口号">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputText">要发送的文本内容:</label>
|
||||
<textarea class="form-control" id="inputText" rows="3" placeholder="输入文本内容"></textarea>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" onclick="sendText()">发送文本</button>
|
||||
|
||||
|
||||
<div id="container" class="container">
|
||||
|
||||
<div>
|
||||
<button id="front" type="button" onclick="forward()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-up" style="margin-left: 56px;"> </button>
|
||||
</div>
|
||||
<!-- <div>
|
||||
<button id="printButton" type="button" onclick="printClicked()" class="btn btn-lg btn-primary">打印点击</button>
|
||||
</div> -->
|
||||
|
||||
<div>
|
||||
<button type="button" onclick="left()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-left" > </button>
|
||||
<button type="button" onclick="stop()" class="btn btn-lg btn-primary glyphicon glyphicon-stop"> </button>
|
||||
<button type="button" onclick="right()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-right" > </button>
|
||||
<!-- ---------------------------------------- -->
|
||||
<button type="button" onclick="takePhoto()">拍照</button>
|
||||
<!-- ---------------------------------------- -->
|
||||
</div>
|
||||
<button id="rear" type="button" onclick="back()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-down" style="margin-left: 56px;"> </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src='/Decoder.js'></script>
|
||||
<script src='/YUVCanvas.js'></script>
|
||||
<script src='/Player.js'></script>
|
||||
<script>
|
||||
// player
|
||||
window.player = new Player({ useWorker: true, webgl: 'auto', size: { width: 848, height: 480 } })
|
||||
var playerElement = document.getElementById('viewer')
|
||||
playerElement.appendChild(window.player.canvas)
|
||||
// Websocket
|
||||
var wsUri = window.location.protocol.replace(/http/,'ws')+'//'+window.location.hostname+':9000'
|
||||
var ws = new WebSocket(wsUri)
|
||||
ws.binaryType = 'arraybuffer'
|
||||
ws.onopen = function (e) {
|
||||
console.log('Client connected')
|
||||
ws.onmessage = function (msg) {
|
||||
// decode stream
|
||||
window.player.decode(new Uint8Array(msg.data));
|
||||
}
|
||||
}
|
||||
ws.onclose = function (e) {
|
||||
console.log('Client disconnected')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
function printClicked() {
|
||||
// console.log("132465789891651354684");
|
||||
}
|
||||
// ---------------------------------------
|
||||
function takePhoto() {
|
||||
window.location.href = "{{ url_for('take_photo') }}"; // 重定向到拍照请求
|
||||
}
|
||||
// ---------------------------------------
|
||||
function forward() {
|
||||
console.log("132465789891651354684");
|
||||
$.ajax({
|
||||
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/forward" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function back() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/back" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
} function right() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/right" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
} function left() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/left" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
} function stop() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/stop" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function refreshPage() {
|
||||
location.reload(); // 刷新页面
|
||||
}
|
||||
// 发送文本
|
||||
function sendText() {
|
||||
const ip = document.getElementById('inputIp').value;
|
||||
const port = document.getElementById('inputPort').value;
|
||||
const text = document.getElementById('inputText').value;
|
||||
|
||||
// 使用fetch API发送POST请求
|
||||
fetch('/send_text', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `ip=${ip}&port=${port}&text=${encodeURIComponent(text)}`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => console.log(data))
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
</script>
|
||||
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,218 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" media="screen">
|
||||
<script src="http://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script>
|
||||
<meta charset="utf-8">
|
||||
<title>Live Video Based on Flask</title>
|
||||
<link rel="stylesheet" href='/style.css'/>
|
||||
<style type="text/css">
|
||||
#front {
|
||||
margin-left: 40px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
#rear{
|
||||
margin-top: 3px;
|
||||
margin-left: 40px;
|
||||
}
|
||||
.btn{
|
||||
background: #e8080b;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h5>实时视频流</h5>
|
||||
<img src="{{ url_for('video_feed') }}">
|
||||
<p> 小车控制界面</p>
|
||||
<bodylink = "red">
|
||||
<a href="control" target="_blank">小车控制</a>
|
||||
|
||||
|
||||
<!-- 添加文本传输的输入框和按钮 -->
|
||||
<div class="form-group">
|
||||
<label for="inputIp">目标服务器 IP 地址:</label>
|
||||
<input type="text" class="form-control" id="inputIp" placeholder="输入 IP 地址">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputPort">目标服务器 端口:</label>
|
||||
<input type="text" class="form-control" id="inputPort" placeholder="输入端口号">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputText">要发送的文本内容:</label>
|
||||
<textarea class="form-control" id="inputText" rows="3" placeholder="输入文本内容"></textarea>
|
||||
</div>
|
||||
<button type="button" class="btn btn-primary" onclick="sendText()">发送文本</button>
|
||||
|
||||
|
||||
<div id="container" class="container">
|
||||
|
||||
<div>
|
||||
<button id="front" type="button" onclick="forward()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-up" style="margin-left: 56px;"> </button>
|
||||
</div>
|
||||
<!-- <div>
|
||||
<button id="printButton" type="button" onclick="printClicked()" class="btn btn-lg btn-primary">打印点击</button>
|
||||
</div> -->
|
||||
|
||||
<div>
|
||||
<button type="button" onclick="left()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-left" > </button>
|
||||
<button type="button" onclick="stop()" class="btn btn-lg btn-primary glyphicon glyphicon-stop"> </button>
|
||||
<button type="button" onclick="right()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-right" > </button>
|
||||
<!-- ---------------------------------------- -->
|
||||
<button type="button" onclick="takePhoto()">拍照</button>
|
||||
<!-- ---------------------------------------- -->
|
||||
</div>
|
||||
<button id="rear" type="button" onclick="back()" class="btn btn-lg btn-primary glyphicon glyphicon-circle-arrow-down" style="margin-left: 56px;"> </button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src='/Decoder.js'></script>
|
||||
<script src='/YUVCanvas.js'></script>
|
||||
<script src='/Player.js'></script>
|
||||
<script>
|
||||
// player
|
||||
window.player = new Player({ useWorker: true, webgl: 'auto', size: { width: 848, height: 480 } })
|
||||
var playerElement = document.getElementById('viewer')
|
||||
playerElement.appendChild(window.player.canvas)
|
||||
// Websocket
|
||||
var wsUri = window.location.protocol.replace(/http/,'ws')+'//'+window.location.hostname+':9000'
|
||||
var ws = new WebSocket(wsUri)
|
||||
ws.binaryType = 'arraybuffer'
|
||||
ws.onopen = function (e) {
|
||||
console.log('Client connected')
|
||||
ws.onmessage = function (msg) {
|
||||
// decode stream
|
||||
window.player.decode(new Uint8Array(msg.data));
|
||||
}
|
||||
}
|
||||
ws.onclose = function (e) {
|
||||
console.log('Client disconnected')
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
function printClicked() {
|
||||
// console.log("132465789891651354684");
|
||||
}
|
||||
// ---------------------------------------
|
||||
function takePhoto() {
|
||||
window.location.href = "{{ url_for('take_photo') }}"; // 重定向到拍照请求
|
||||
}
|
||||
// ---------------------------------------
|
||||
function forward() {
|
||||
console.log("132465789891651354684");
|
||||
$.ajax({
|
||||
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/forward" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function back() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/back" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
} function right() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/right" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
} function left() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/left" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
} function stop() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/control/stop" ,
|
||||
data: $('#form1').serialize(), //提交的数据
|
||||
success: function (result) {
|
||||
console.log(result); //打印服务端返回的数据(调试用)
|
||||
if (result.resultCode == 200) {
|
||||
}
|
||||
;
|
||||
},
|
||||
error : function() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
function refreshPage() {
|
||||
location.reload(); // 刷新页面
|
||||
}
|
||||
// 发送文本
|
||||
function sendText() {
|
||||
const ip = document.getElementById('inputIp').value;
|
||||
const port = document.getElementById('inputPort').value;
|
||||
const text = document.getElementById('inputText').value;
|
||||
|
||||
// 使用fetch API发送POST请求
|
||||
fetch('/send_text', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
body: `ip=${ip}&port=${port}&text=${encodeURIComponent(text)}`
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => console.log(data))
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
</script>
|
||||
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,6 +1,7 @@
|
||||
guard df123qwerty 2023-04-24-10-13-55
|
||||
guard df123qwerty 2023-04-24-10-14-31
|
||||
guard df123qwerty 2023-04-24-10-16-50
|
||||
guard df123qwerty 2023-04-24-10-17-04
|
||||
guard df123qwerty 2023-04-24-10-17-05
|
||||
guard df123qwerty 2023-04-24-10-17-07
|
||||
admin - 2024-10-31T08:18:22.560Z
|
||||
zyp - 2024-10-31T08:18:32.459Z
|
||||
admin - 2024-10-31T08:28:40.653Z
|
||||
zyp - 2024-10-31T08:28:46.935Z
|
||||
chenjk - 2024-10-31T09:41:40.969Z
|
||||
chenjk - 2024-10-31T09:41:52.294Z
|
||||
chenjk - 2024-10-31T09:42:24.196Z
|
||||
|
@ -1,16 +1 @@
|
||||
guard df123qwerty 2023-04-18-09-45-13
|
||||
guard df123qwerty 2023-04-18-09-46-50
|
||||
guard df123qwerty 2023-04-18-09-46-52
|
||||
guard df123qwerty 2023-04-18-10-16-00
|
||||
guard df123qwerty 2023-04-18-10-20-29
|
||||
guard Null 2023-04-18-10-28-11
|
||||
guard df123qwerty 2023-04-18-15-01-55
|
||||
guard df123qwerty 2023-04-18-18-21-13
|
||||
guard df123qwerty 2023-04-18-21-56-05
|
||||
guard df123qwerty 2023-04-18-22-00-38
|
||||
guard df123qwerty 2023-04-19-08-47-19
|
||||
guard df123qwerty 2023-04-19-09-03-15
|
||||
guard df123qwerty 2023-04-19-09-48-46
|
||||
guard df123qwerty 2023-04-19-10-07-22
|
||||
guard df123qwerty 2023-04-19-10-54-03
|
||||
guard df123qwerty 2023-04-19-10-54-22
|
||||
|
||||
|
@ -1,37 +1 @@
|
||||
qinziyao 2023-04-18-21-36-05
|
||||
admin 2023-04-18-21-36-27
|
||||
xuchen 2023-04-18-21-42-33
|
||||
admin 2023-04-18-21-42-47
|
||||
admin 2023-04-18-21-58-14
|
||||
guard 2023-04-18-21-58-38
|
||||
qinziyao 2023-04-18-22-31-50
|
||||
qinziyao 2023-04-18-22-54-14
|
||||
fighter1 2023-04-19-08-25-10
|
||||
fighter1 2023-04-19-08-38-37
|
||||
admin 2023-04-19-08-42-53
|
||||
guard 2023-04-19-08-46-52
|
||||
admin 2023-04-19-08-48-23
|
||||
fighter2 2023-04-19-09-02-35
|
||||
admin 2023-04-19-09-02-57
|
||||
fighter2 2023-04-19-09-04-44
|
||||
admin 2023-04-19-09-05-31
|
||||
fighter2 2023-04-19-09-05-47
|
||||
fighter1 2023-04-19-09-05-52
|
||||
qinziyao 2023-04-19-09-42-50
|
||||
guard 2023-04-19-10-04-46
|
||||
qinziyao 2023-04-19-10-06-53
|
||||
admin 2023-04-19-10-08-09
|
||||
fighter1 2023-04-19-10-11-27
|
||||
flying_pigeon 2023-04-19-10-18-42
|
||||
guard 2023-04-19-10-53-14
|
||||
qinziyao 2023-04-21-23-36-47
|
||||
admin 2023-04-21-23-57-01
|
||||
tester 2023-04-23-08-21-17
|
||||
tester 2023-04-23-08-26-06
|
||||
qinziyao 2023-04-23-11-28-31
|
||||
admin 2023-04-23-15-33-25
|
||||
admin 2023-04-23-17-12-05
|
||||
qinziyao 2023-04-23-20-24-04
|
||||
admin 2023-04-23-20-25-27
|
||||
halo 2023-04-23-20-42-59
|
||||
admin 2023-04-23-20-48-24
|
||||
|
||||
|
Loading…
Reference in new issue