Commit 7eafd63c authored by LammaFisher's avatar LammaFisher
Browse files

ok

parent 312e6a98
Pipeline #194735 failed with stages
in 0 seconds
import cv2
import mediapipe as mp
import requests
import datetime
import time
import json
import base64
import asyncio
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
server="http://192.168.8.40:81/"
deviceid=-100
IMEI="XXXXXXXXXX"
#register in server
url=server+"register.php?id={}&IMEI={}".format(deviceid,IMEI)
requests.get(url=url)
# For webcam input:
cap = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
while True:
while True:
datetime_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
report_obj={ 'time' : datetime_str, 'status' : 'waiting', 'device' : 'raspberry pi', 'power' : 100, 'locked' : 1 }
url=server+"report.php?id={}&IMEI={}".format(deviceid,IMEI)
r=requests.post(url=url,data=json.dumps(report_obj))
print(url)
r.encoding = 'utf-8'
print(r.status_code)
print(r.text)
receive=json.loads(r.text)
if receive['command']=='record':
break
time.sleep(1)
if receive['command']=='shutdown':
break
time0=time.time()
lastreporttime=0
starttime=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640,480))
with mp_face_detection.FaceDetection(model_selection=0, min_detection_confidence=0.4) as face_detection:
while cap.isOpened():
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
# If loading a video, use 'break' instead of 'continue'.
continue
# To improve performance, optionally mark the image as not writeable to
# pass by reference.
# font
font = cv2.FONT_HERSHEY_SIMPLEX
# org
org = (50, 50)
# fontScale
fontScale = 1
# Blue color in BGR
color = (255, 255, 255)
# Line thickness of 2 px
thickness = 2
curr_time = datetime.datetime.now()
time_str = curr_time.strftime("%H:%M:%S")
# Using cv2.putText() method
image.flags.writeable = False
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
results = face_detection.process(image)
if(results.detections):
facecount=len(results.detections)
else:
facecount=0
senconds=time.time()-time0;
print("Recording..."+str(facecount)+" face detacted at {} seconds.".format(senconds))
# Draw the face detection annotations on the image.
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
if results.detections:
for detection in results.detections:
mp_drawing.draw_detection(image, detection)
image = cv2.putText(image, time_str, org, font, fontScale, color, thickness, cv2.LINE_AA)
out.write(image)
# Flip the image horizontally for a selfie-view display.
#report every 1 second
if lastreporttime<time.time()-1:
lastreporttime=time.time()
datetime_str = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
scale_percent = 20 # percent of original size
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dim = (width, height)
small_image = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
cv2.imwrite("small_image.png",small_image)
f = open('small_image.png', 'rb')
small_image_png=f.read()
report_obj={ 'time' : datetime_str, 'status' : 'recording', 'device' : 'raspberry pi', 'power' : 100, 'locked' : 1, 'faces':facecount, 'starttime': starttime, 'position': time.time()-time0, 'image':base64.b64encode(small_image_png).decode("utf-8")}
url=server+"report.php?id={}&IMEI={}".format(deviceid,IMEI)
t1=time.time()
r=requests.post(url=url,data=json.dumps(report_obj))
print("xxxx")
print(time.time()-t1)
print(url)
r.encoding = 'utf-8'
print(r.status_code)
print(r.text)
#print(base64.b64encode(image))
receive=json.loads(r.text)
if receive['command']=='finish':
break
# cv2.imshow('MediaPipe Face Detection', image)
if cv2.waitKey(5) & 0xFF == 27:
break
out.release()
f = open('output.avi', 'rb')
avi=f.read()
time1=time.time()
url=server+"upload.php?id={}&IMEI={}&mode=camera&starttime={}&length={}&filesize={}".format(deviceid,IMEI,starttime,time1-time0,len(avi))
print(url)
r=requests.get(url=url)
r.encoding = 'utf-8'
print(r.text)
receive=json.loads(r.text)
fileid=receive['fileid']
url=server+"upload.php?id={}&IMEI={}&mode=camera&fileid={}".format(deviceid,IMEI,fileid)
r=requests.post(url=url, data=avi)
r.encoding = 'utf-8'
print(r.text)
cap.release()
<?php
require_once __DIR__.'/../../include/config.php';
require_once __DIR__.'/../../include/dataset.php';
require_once __DIR__.'/../../include/device/file.php';
require_once __DIR__.'/template.php';
use \device\file as file;
getintnull('s_loginuid','s_mode','s_err'); getstr();
$page=isset($_GET['page'])?(int)$_GET['page']:1; if($page<1) $page=1;
$where=''; $parameters=array(); $linkarr=array();
if($s_loginuid==1) { $where.=' and `loginuid`!=0'; $linkarr['s_loginuid']=$s_loginuid;}
if(!is_null($s_loginuid)&&$s_loginuid==0) { $where.=' and (`loginuid`=0 or `loginuid` is null)'; $linkarr['s_loginuid']=$s_loginuid;}
if($s_mode>0) { $where.=' and `id`>0'; $linkarr['s_mode']=$s_mode;}
if($s_mode<0) { $where.=' and `id`<0'; $linkarr['s_mode']=$s_mode;}
if($s_err==1) { $where.=" and (
strftime('%s','now','localtime') - strftime('%s',`reporttime`)>30 or
(`id`>0 and `reportstatus`=='recording' and `reportdevice`!='earphone') or
(`id`<0 and `reportstatus`=='recording' and `reportlocked`=1) or
`reportpower`<30 or
(`record`=1 and `reportstatus`!='recording') or
(`record`!=1 and `reportstatus`=='recording')
)
"; $linkarr['s_err']=$s_err;}
$order='(`loginuid`>0 or `loginuid`<0) desc,`loginuid` desc, `id` asc';
$where=' where 1'.$where;
$links=http_build_query($linkarr);
$xlsx_where=base64_encode($where);
$xlsx_parameters=base64_encode(json_encode($parameters));
$xlsx_timestamp=time();
$xlsx_sign=encryptpass(md5($xlsx_where.$xlsx_parameters).$xlsx_timestamp);
$xlsx_where=urlencode($xlsx_where);$xlsx_parameters=urlencode($xlsx_parameters);
$headcode='
<script type="text/javascript" src="function.js"></script>
';
htmlhead('Devices',['form'],$headcode);
?>
<div class="crumbs">
<ul id="breadcrumbs" class="breadcrumb">
<li><i class="icon-home"></i><a href="./">Recording</a></li>
<li class="current"><a href="#" title="">Devices</a></li>
</ul>
<ul class="crumb-buttons"><li><a href="" target="_blank"><i class="icon-wrench"></i><span>Jiajun Wu (jiajunw6)</span></a></li></ul>
</div>
<div class="page-header">
<div class="page-title">
<h3>Cameras and Recorders</h3>
<span>Remote control platform</span>
</div>
</div>
<!--=== Page Content ===-->
<div class="row">
<div class="col-md-12">
<div class="widget box">
<div class="widget-header">
<h4><i class="icon-search"></i> Filter</h4>
</div>
<div class="widget-content">
<form name="sform" id="sform" class="form-horizontal row-border" action="?" method="get">
<div class="form-group">
<label class="col-md-0-1 control-label">Login:</label>
<div class="col-md-1">
<select class="form-control" name="s_loginuid">
<option value="">ALL</option>
<option value="1"<?php if(!is_null($s_loginuid)&&$s_loginuid==1) echo ' selected="selected"';?>>Yes</option>
<option value="0"<?php if(!is_null($s_loginuid)&&$s_loginuid==0) echo ' selected="selected"';?>>No</option>
?>
</select>
</div>
<label class="col-md-0-1 control-label">Mode:</label>
<div class="col-md-1">
<select class="form-control" name="s_mode">
<option value="">ALL</option>
<option value="1"<?php if($s_mode==1) echo ' selected="selected"';?>>Audio Recorder</option>
<option value="-1"<?php if($s_mode==-1) echo ' selected="selected"';?>>Camera</option>
</select>
</div>
<label class="col-md-0-1 control-label">Exception:</label>
<div class="col-md-1">
<select class="form-control" name="s_err">
<option value=""></option>
<option value="1"<?php if($s_err==1) echo ' selected="selected"';?>>Yes</option>
</select>
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn btn-sm btn-success" value="Search">
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<!--=== Table Classes ===-->
<div class="col-md-12">
<div class="widget box">
<div class="widget-header">
<h4><i class="icon-reorder"></i> Devices</h4>
<div class="toolbar no-padding">
<div class="btn-group">
<span class="btn btn-xs widget-collapse"><i class="icon-angle-down"></i></span>
</div>
</div>
</div>
<div class="widget-content no-padding">
<table class="table table-hover table-striped table-bordered table-highlight-head">
<thead>
<tr>
<th width="5%">ID</th>
<th>Mode</th>
<th>ip</th>
<th>Identity</th>
<th>Latest Report</th>
<th>Status</th>
<th>Mode</th>
<th>Battery</th>
<th>Faces</th>
<th>Quick Preview</th>
</tr>
</thead>
<tbody>
<?php
$pagesize=200;
$sql="SELECT count(`id`) FROM `devices` $where";
$stmt = $conn->prepare($sql);
$stmt->execute($parameters);
$recordcount = (int)$stmt->fetch()[0];
$pagecount = ceil($recordcount/$pagesize);
if($page>$pagecount) $page=$pagecount;
$pagestart=($page-1)*$pagesize;
$sql="SELECT * FROM `devices` $where order by $order limit $pagestart,$pagesize";
$stmt = $conn->prepare($sql);
$stmt->execute($parameters);
while($stmt&&$arr=$stmt->fetch( PDO::FETCH_ASSOC )) {
for($i=0;$i<4;$i++) {
?>
<tr>
<td><?php echo $arr['id'];?></td>
<td><?php echo $arr['registermode'];?></td>
<td><?php echo $arr['reportip'];?></td>
<td><?php if($arr['loginuid']) echo '<a class="btn btn-xs btn-default" href="devices_save.php?id='.$arr['id'].'&loginuid=0">'."[{$arr['loginuid']}]</a>".$arr['title']; else echo '<span class="label label-xs label-default">Not Login</span>';
if($i) echo ' - Simulated Device'; else echo ' - Real Device';
?></td>
<td><?php
if($arr['reporttime']) {
if(strtotime('now')-strtotime($arr['reporttime'])>30)
echo '<span class="label label-xs label-danger">'.cdate('H:i:s',$arr['reporttime']).'</span>';
else
echo '<span class="label label-xs label-default">'.cdate('H:i:s',$arr['reporttime']).'</span>';
}
?></td>
<td><?php
if($arr['record']) {
echo '<a class="btn btn-xs btn-danger" href="devices_save.php?id='.$arr['id'].'&record=0">■</a>';
} else {
echo '<a class="btn btn-xs btn-default" href="devices_save.php?id='.$arr['id'].'&record=1">▶</a>';
}
if(($arr['reportstatus']=='recording'&&!$arr['record'])||$arr['reportstatus']!='recording'&&$arr['record']) {
echo ' <span class="label label-xs label-warning">'.$arr['reportstatus'].'</span>';
} else
echo ' <span class="label label-xs label-default">'.$arr['reportstatus'].'</span>';
if($arr['reportstatus']=='recording') echo ' <span class="label label-xs label-success">'.$arr['reportposition'].'</span>';
?></td>
<td><?php
echo $arr['reportdevice'];
?></td>
<td><?php
if($arr['reportpower']) {
if($arr['reportpower']<30)
echo '<span class="label label-xs label-danger">'.$arr['reportpower'].'%</span>';
else
echo '<span class="label label-xs label-default">'.$arr['reportpower'].'%</span>';
}
?></td>
<td><?php
if($arr['id']<0&&$arr['reportstatus']=='recording'&&$arr['reportfaces']<2)
echo '<span class="label label-xs label-danger">'.$arr['reportfaces'].'</span>';
else
echo $arr['reportfaces'];
?></td>
<td><?php if($arr['reportstatus']=='recording') {
if($arr['reportimage']) echo '<img width="200" height="150" src="data:image/png;base64,'.$arr['reportimage'].'"/>';
if($arr['reportsound']) {
$soundarr=json_decode_no_null($arr['reportsound']);
$soundarr[]=0;
$sound=max($soundarr);
if($sound<10) echo '<span class="label label-xs label-danger">'.$sound.'db</span>'; else echo $sound.'db';
}
}else if($arr['reportfileid']) {
$file=new file($arr['reportfileid']);
echo '<a class="btn btn-sm btn-info" href="http://localhost/upload/'.$file->path.'">Download Video</a>';
}
?></td>
</tr>
<?php
}
}
?>
</tbody>
</table>
<div class="row">
<div class="table-footer">
<div class="col-md-4">
<div class="table-actions">
<a class="btn btn-sm icon-th" href=""><?php echo " $recordcount Devices in total";?></a>
</div>
</div>
<div class="col-md-8">
<ul class="pagination">
<li class="<?php if($page==1) echo 'disabled';?>"><a href="<?php if($page>1) echo '?'.$links.'&page=1'; else echo 'javascript:void(0);';?>">First</a></li>
<li class="<?php if($page==1) echo 'disabled';?>"><a href="<?php if($page>1) echo '?'.$links.'&page='.($page-1); else echo 'javascript:void(0);';?>">&larr; Prev</a></li>
<li><a href="javascript:gotopage('<?php echo $links;?>');"><?php echo $page;?> / <?php echo $pagecount;?></a></li>
<li class="<?php if($page==$pagecount) echo 'disabled';?>"><a href="<?php if($page<$pagecount) echo '?'.$links.'&page='.($page+1); else echo 'javascript:void(0);';?>">Next &rarr;</a></li>
<li class="<?php if($page==$pagecount) echo 'disabled';?>"><a href="<?php if($page<$pagecount) echo '?'.$links.'&page='.$pagecount; else echo 'javascript:void(0);';?>">Last</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /Table Classes -->
</div>
<!-- /.row -->
<!-- /Page Content -->
<div class="row">
<div class="col-md-12">
<div class="widget box">
<div class="widget-header">
<h4><i class="icon-cog"></i> Action</h4>
</div>
<div class="widget-content">
<div class="tabbable box-tabs">
<ul class="nav nav-tabs">
<li class="active"><a href="#box_tab1" data-toggle="tab">Record</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="box_tab1">
<form class="form-horizontal" action="devices_save.php?" method="get">
<div class="form-group">
<label class="col-md-2 control-label">Button:<span class="required">*</span></label>
<div class="col-md-6">
<a class="btn btn-danger" href="devices_save.php?record=0" >■ Stop All</a>
<a class="btn btn-success" href="devices_save.php?record=1" >▶ Record All</a>
<a class="btn btn-warning" href="devices_save.php?reset=1">Reset ALL</a>
</div>
<div class="col-md-2">
</div>
</div>
</form>
</div>
</div>
</div> <!-- /.tabbable portlet-tabs -->
</div> <!-- /.widget-content -->
</div> <!-- /.widget .box -->
</div> <!-- /.col-md-12 -->
</div> <!-- /.row -->
<?php
htmlfoot();
<?php
require_once __DIR__.'/../../include/config.php';
require_once __DIR__.'/../../include/dataset.php';
require_once __DIR__.'/template.php';
//取得get参数
getintnull('id','loginuid','record','upload','reset'); getstr('url');
$where=' where 1';
if($id) $where.=' and `id`='.$id;
if(!is_null($loginuid)&&$loginuid==0) {
//$where.=' and `id`>0'; //只有录音设备才能下线
$conn->exec("update `devices` set `logintime`=null, `loginuid`=null, `title`='未登录' {$where}");
}
if(!is_null($record)){
$where.=' and `loginuid`!=0';
$conn->exec("update `devices` set `record`={$record} {$where}");
}
if(isset($_GET['url'])){
$conn->exec("update `devices` set `url`='{$url}' {$where}");
}
if($upload){
//$where.=' and `id`<0';
$conn->exec("update `devices` set `fileid`=(
select `id` from `device_files` `f` where `f`.`deviceid`=`devices`.`id` and `marktime`>'2021-03-30' and `savetime` is null order by `id` desc limit 1
) {$where} ");
}
if($reset) {
$conn->exec("update devices set
`registertime`=null,
`registermode`=null,
`reportip`=null,
`reporttime`=null,
`reportstatus`=null,
`reportdevice`=null,
`reportpower`=null,
`reportlocked`=null,
`reportsound`=null,
`reportimage`=null,
`reportstarttime`=null,
`reportposition`=null,
`reportfileid`=null,
`logintime`=null,
`loginuid`=null,
`title`=null,
`record`=null,
`url`=null,
`fileid`=null {$where}");
}
diegoto('','devices.php?s_loginuid=1');
<?php
header("Location: devices.php");
?>
\ No newline at end of file
<?php
require_once __DIR__.'/../template.php';
function submodulemenus() {
?>
<li class="current">
<a href="devices.php">
<i class="icon-camera-retro"></i>
Devices
</a>
</li>
<!--
<li class="current">
<a href="devices.php?s_err=1">
<i class="icon-random"></i>
异常监控
</a>
</li>
<li class="current">
<a href="students.php">
<i class="icon-user"></i>
学生视角
</a>
</li>
<li class="current">
<a href="groups.php">
<i class="icon-dashboard"></i>
小组视角
</a>
</li>
-->
<?php
?>
<?php
}
?>
/* ========================================================
*
* Melon - Flat & Responsive Admin Template
*
* ========================================================
*
* File: error.css
* Description: Error page (e.g. 404) template styling
*
* ======================================================== */
.clearfix {
*zoom: 1;
}
.clearfix:before,
.clearfix:after {
display: table;
content: "";
line-height: 0;
}
.clearfix:after {
clear: both;
}
.error {
background-color: #f9f9f9;
padding-top: 20px;
}
.error .title,
.error .footer {
margin: 0 auto;
text-align: center;
}
.error .title h1,
.error .footer h1 {
color: #4d7496;
font-size: 120px;
text-shadow: 0 1px 0 #fff;