Merge pull request '云台控制归位,小车控制校验' (#3) from zyp into main

pull/5/head
pa2ltb7y5 3 weeks ago
commit 19b584ad97

@ -7,7 +7,8 @@
# MJRoBot.org 19Jan18 # MJRoBot.org 19Jan18
from flask import Flask, render_template, Response, redirect, url_for, send_file, jsonify, request from flask import Flask, render_template, Response, redirect, url_for, send_file, jsonify, request
from PIL import Image
import base64
# Raspberry Pi camera module (requires picamera package) # Raspberry Pi camera module (requires picamera package)
#from camera_pi import Camera #from camera_pi import Camera
from picamera2 import Picamera2 from picamera2 import Picamera2
@ -22,6 +23,10 @@ app = Flask(__name__, static_url_path='')
# 照片保存路径 # 照片保存路径
PHOTO_PATH = "photo.jpg" PHOTO_PATH = "photo.jpg"
# picam2 = Picamera2()
# picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
# picam2.start()
def gen_frames(): # generate frame by frame from camera def gen_frames(): # generate frame by frame from camera
picam2 = Picamera2() picam2 = Picamera2()
picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)})) picam2.configure(picam2.create_video_configuration(main={"format": 'XRGB8888', "size": (640, 480)}))
@ -36,6 +41,20 @@ def gen_frames(): # generate frame by frame from camera
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') # concat frame one by one and show result
def capture_frame():
picam2.close()
frame = picam2.capture_array() # 假设picam2是你的相机对象
ret, buffer = cv2.imencode('.jpg', frame, [int(cv2.IMWRITE_JPEG_QUALITY), 50])
img_str = base64.b64encode(buffer).decode()
picam2.start()
return img_str
@app.route('/capture_frame')
def capture_frame_route():
img_str = capture_frame()
return jsonify(img_str)
@app.route('/') @app.route('/')
def index(): def index():
return render_template('index-t.html') return render_template('index-t.html')

@ -94,4 +94,11 @@ class CAR:
def yunright(self): def yunright(self):
self.input_x+=10 self.input_x+=10
base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc) base.gimbal_ctrl(self.input_x, self.input_y, self.input_speed, self.input_acc)
def guiwei(self):
self.input_x = 2
self.input_y = 2
self.input_speed = 0
base.gimbal_base_ctrl(self.input_x, self.input_y, self.input_speed)

@ -20,10 +20,14 @@
background: #e8080b; background: #e8080b;
} }
</style> </style>
<title>Capture Frame</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head> </head>
<body> <body>
<h5>实时视频流</h5> <h5>实时视频流</h5>
<img src="{{ url_for('video_feed') }}"> <img src="{{ url_for('video_feed') }}">
<button id="captureButton">Capture Frame</button>
<img id="frameImage" src="" alt="Captured Frame" style="display:none; width: 640px; height: 480px;">
<p> 小车控制界面</p> <p> 小车控制界面</p>
<bodylink = "red"> <bodylink = "red">
<a href="control" target="_blank">小车控制</a> <a href="control" target="_blank">小车控制</a>
@ -94,6 +98,23 @@
<script> <script>
$(document).ready(function() {
$('#captureButton').click(function() {
$.ajax({
url: '/capture_frame', // 后端路由地址
type: 'GET',
success: function(response) {
// 将响应中的图像数据设置到img标签的src属性
$('#frameImage').attr('src', 'data:image/jpeg;base64,' + response);
// 显示图像
$('#frameImage').show();
},
error: function(error) {
console.log('Error:', error);
}
});
});
});
function printClicked() { function printClicked() {
// console.log("132465789891651354684"); // console.log("132465789891651354684");
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 240 KiB

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

@ -169,24 +169,24 @@ router.post('/login', urlencodedParser, function (req, res, next) {
res.redirect('login'); res.redirect('login');
} else { } else {
username = name username = name
var exec = require('child_process').exec; // var exec = require('child_process').exec;
exec(`python C:/Users/17217/Desktop/english/users/admin/log.py `+username) // exec(`python C:/Users/17217/Desktop/english/users/admin/log.py `+username)
db.run("delete from "+name,function(){ //每次先将表信息清空再重新读取文件夹里面的文件信息 // db.run("delete from "+name,function(){ //每次先将表信息清空再重新读取文件夹里面的文件信息
}); // });
fs.readdir('./users/'+name, 'utf8', function(err, data) { // fs.readdir('./users/'+name, 'utf8', function(err, data) {
console.log(data); // console.log(data);
for (var key in data) { // for (var key in data) {
console.log(key); // console.log(key);
var a=key // var a=key
console.log(data[key]); // console.log(data[key]);
var b=data[key] // var b=data[key]
var c = fs.statSync(path.join(__dirname,'../users/'+name+'/'+data[key])) // var c = fs.statSync(path.join(__dirname,'../users/'+name+'/'+data[key]))
console.log(c.size) // console.log(c.size)
var add = db.prepare("INSERT INTO "+name+"(fid,fname,fsize,fowner) VALUES(?,?,?,?)");//读取用户名文件夹下文件ID、文件名、大小并写入数据库中 // var add = db.prepare("INSERT INTO "+name+"(fid,fname,fsize,fowner) VALUES(?,?,?,?)");//读取用户名文件夹下文件ID、文件名、大小并写入数据库中
add.run(a,b,c.size,name); // add.run(a,b,c.size,name);
add.finalize(); // add.finalize();
} // }
}) // })
if (name == 'admin') if (name == 'admin')
{ {
req.session.error = '' req.session.error = ''

@ -60,6 +60,7 @@
<% } %> <% } %>
<h1> <a href="/zuozhan">作战员1入口</a></h1> <h1> <a href="/zuozhan">作战员1入口</a></h1>
<h1> <a href="/zuozhan2">作战员2入口</a></h1> <h1> <a href="/zuozhan2">作战员2入口</a></h1>
<h1> <a href="http://192.168.98.242:80">侦查员入口</a></h1>
<h1> <a href="/guanli">用户信息管理</a></h1> <h1> <a href="/guanli">用户信息管理</a></h1>
<h1> <%= message %> <a href="/logout">退出登录</a></h1> <h1> <%= message %> <a href="/logout">退出登录</a></h1>
</div> </div>

Loading…
Cancel
Save