Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gamera_videos_no_ui
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liusq
gamera_videos_no_ui
Commits
045a3ddf
Commit
045a3ddf
authored
Jul 12, 2024
by
“liusq”
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
调度算法优化秒到毫秒
parent
fe54e885
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
59 additions
and
84 deletions
+59
-84
AlgorithmTaskManage.h
+29
-34
CameraHandle.cpp
+13
-22
CameraHandle.h
+6
-6
MediaFaceImage.cpp
+2
-5
TaskRunnable.cpp
+3
-3
mainwindow.cpp
+6
-14
No files found.
AlgorithmTaskManage.h
View file @
045a3ddf
...
...
@@ -45,40 +45,35 @@ public:
private
:
template
<
typename
T
>
T
*
schedulingAlgorithmTemplate
(
std
::
vector
<
T
*>&
objects
,
std
::
mutex
&
mtx
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mtx
);
qint64
currentTime
=
QDateTime
::
currentSecsSinceEpoch
();
qint64
maxWaitTime
=
0
;
int
maxWaitTimeCount
=
0
;
std
::
vector
<
T
*>
schedulableObjects
;
for
(
T
*
obj
:
objects
)
{
if
(
obj
->
getIsRunning
())
continue
;
qint64
waitTime
=
std
::
abs
(
currentTime
-
obj
->
getThreadTime
());
if
(
waitTime
>
maxWaitTime
)
{
schedulableObjects
.
clear
();
schedulableObjects
.
push_back
(
obj
);
maxWaitTime
=
waitTime
;
maxWaitTimeCount
=
1
;
}
else
if
(
waitTime
==
maxWaitTime
)
{
schedulableObjects
.
push_back
(
obj
);
maxWaitTimeCount
++
;
}
}
if
(
maxWaitTimeCount
==
1
)
{
return
schedulableObjects
.
at
(
0
);
}
if
(
schedulableObjects
.
empty
())
{
return
nullptr
;
}
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_int_distribution
<>
dis
(
0
,
schedulableObjects
.
size
()
-
1
);
return
schedulableObjects
[
dis
(
gen
)];
}
T
*
schedulingAlgorithmTemplate
(
std
::
vector
<
T
*>&
objects
,
std
::
mutex
&
mtx
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mtx
);
qint64
currentTime
=
QDateTime
::
currentMSecsSinceEpoch
();
qint64
maxWaitTime
=
0
;
std
::
vector
<
T
*>
schedulableObjects
;
for
(
T
*
obj
:
objects
)
{
if
(
obj
->
getIsRunning
())
continue
;
qint64
waitTime
=
std
::
abs
(
currentTime
-
obj
->
getThreadTime
());
if
(
waitTime
>
maxWaitTime
)
{
schedulableObjects
.
clear
();
schedulableObjects
.
push_back
(
obj
);
maxWaitTime
=
waitTime
;
}
else
if
(
waitTime
==
maxWaitTime
)
{
schedulableObjects
.
push_back
(
obj
);
}
}
if
(
schedulableObjects
.
empty
())
{
return
nullptr
;
}
if
(
schedulableObjects
.
size
()
==
1
)
{
return
schedulableObjects
.
at
(
0
);
}
std
::
random_device
rd
;
std
::
mt19937
gen
(
rd
());
std
::
uniform_int_distribution
<>
dis
(
0
,
schedulableObjects
.
size
()
-
1
);
return
schedulableObjects
[
dis
(
gen
)];
}
static
AlgorithmTaskManage
*
instance
;
...
...
CameraHandle.cpp
View file @
045a3ddf
...
...
@@ -2,7 +2,6 @@
#include "TaskRunnable.h"
#include "AlgorithmTaskManage.h"
#include "ScopeSemaphoreExit.h"
#include <QElapsedTimer>
#include <QRegularExpression>
CameraHandle
::
CameraHandle
(){
...
...
@@ -31,7 +30,6 @@ CameraHandle::~CameraHandle() {
stopRequested_
=
true
;
Common
&
instace
=
Common
::
getInstance
();
dev_snap_syn_timer
->
stop
();
qInfo
()
<<
"CameraHandle:关闭"
;
QThreadPool
::
globalInstance
()
->
waitForDone
();
instace
.
deleteObj
(
dev_snap_syn_timer
);
...
...
@@ -44,7 +42,6 @@ CameraHandle::~CameraHandle() {
parkMap
.
clear
();
XSDK_DevLogout
(
this
->
hDevice
);
qInfo
()
<<
"CameraHandle:成功"
;
}
int
CameraHandle
::
sdkDevLoginSyn
(
QString
sDevId
,
int
nDevPort
,
QString
sUserName
,
QString
sPassword
,
int
nTimeout
)
{
...
...
@@ -425,8 +422,8 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma
}
}
q
Debug
()
<<
"最新车牌"
<<
newInfo
.
getLicensePlate
()
<<
"区域当前车牌"
<<
park
->
getCurrentPlate
().
getLicensePlate
();
q
Debug
()
<<
"不同的区域:"
<<
park
->
getSpaceIndex
()
<<
",数量:"
<<
count
;
q
Info
()
<<
"最新车牌"
<<
newInfo
.
getLicensePlate
()
<<
"区域当前车牌"
<<
park
->
getCurrentPlate
().
getLicensePlate
();
q
Info
()
<<
"不同的区域:"
<<
park
->
getSpaceIndex
()
<<
",数量:"
<<
count
;
if
(
count
>=
3
)
{
//第一次进场 当前车牌就是进来这个,老车牌就是空
if
(
park
->
getCurrentPlate
().
getLicensePlate
().
length
()
<=
0
){
...
...
@@ -446,21 +443,21 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma
std
::
map
<
int
,
int
>
resMap
;
int
car_size
=
algorithmTaskManage
.
executeFindHuManCar
(
frame
,
0x01
,
currentPlates
,
resMap
,
sSn
);
q
Debug
()
<<
sSn
<<
":"
<<
"当前车形数量:"
<<
car_size
;
q
Info
()
<<
sSn
<<
":"
<<
"当前车形数量:"
<<
car_size
;
if
(
car_size
<=
0
&&
car_size
!=-
2
)
{
q
Debug
()
<<
sSn
<<
"区域:"
<<
park
->
getSpaceIndex
()
<<
": 出场:"
;
q
Info
()
<<
sSn
<<
"区域:"
<<
park
->
getSpaceIndex
()
<<
": 出场:"
;
//如果有车辆检测到并且不在停车区域内部,视为出场
park
->
setCurrentPlate
(
newInfo
);
result
=
Exit
;
}
else
{
// 没有车辆或车辆在停车区域内部,移除队列
park
->
removeNoQueue
();
q
Debug
()
<<
sSn
<<
": no出场:"
<<
car_size
;
q
Info
()
<<
sSn
<<
": no出场:"
<<
car_size
;
}
}
else
{
q
Debug
()
<<
sSn
<<
":"
<<
"老车出场:"
<<
park
->
getCurrentPlate
().
getLicensePlate
();
q
Debug
()
<<
sSn
<<
":"
<<
"新车入场:"
<<
newInfo
.
getLicensePlate
();
q
Info
()
<<
sSn
<<
":"
<<
"老车出场:"
<<
park
->
getCurrentPlate
().
getLicensePlate
();
q
Info
()
<<
sSn
<<
":"
<<
"新车入场:"
<<
newInfo
.
getLicensePlate
();
//当前不为空,新车,新车入场,老车出场
//exitAndMoMap[Exit]=park->getCurrentPlate();
...
...
@@ -557,8 +554,6 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
std
::
vector
<
vides_data
::
ParkingArea
>
currentPlates
;
int
uniforms
=
0x00
;
std
::
map
<
int
,
int
>
resMap
;
QElapsedTimer
timer
;
timer
.
start
();
//穿工服算法
if
((
algorithmPermissions
&
0x01
<<
2
)
!=
0
)
{
...
...
@@ -575,12 +570,8 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
uniforms
=
faSize
;
}
}
qint64
elapsedTime
=
timer
.
elapsed
();
qInfo
()
<<
"人脸数量==>"
<<
faSize
;
qInfo
()
<<
"未穿工服数量==>"
<<
uniforms
;
qInfo
()
<<
"humanDetectionManage.executeFindHuManCa:执行时间"
<<
elapsedTime
/
1000
;
if
(
uniforms
==-
2
||
faSize
==-
2
){
qInfo
()
<<
"没有可用的HumanDetection对象可以调度"
;
return
;
...
...
@@ -668,9 +659,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
bool
success
=
cv
::
imwrite
(
fileName
.
toStdString
(),
frame
);
if
(
success
)
{
q
Debug
()
<<
"图片已成功保存至:"
<<
fileName
;
q
Info
()
<<
"图片已成功保存至:"
<<
fileName
;
}
else
{
q
Debug
()
<<
"图片保存失败!"
;
q
Info
()
<<
"图片保存失败!"
;
}
}
...
...
@@ -685,9 +676,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
bool
success
=
cv
::
imwrite
(
fileName
.
toStdString
(),
areaMat
);
if
(
success
)
{
q
Debug
()
<<
"图片已成功保存至:"
<<
fileName
;
q
Info
()
<<
"图片已成功保存至:"
<<
fileName
;
}
else
{
q
Debug
()
<<
"图片保存失败!"
;
q
Info
()
<<
"图片保存失败!"
;
}
}
...
...
@@ -698,7 +689,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
vides_data
::
requestLicensePlate
newPlate
;
newPlate
.
sn
=
sSn
;
uint64_t
countValue
=
faceCount
.
load
(
std
::
memory_order_relaxed
);
uint64_t
countValue
=
faceCount
.
load
(
std
::
memory_order_relaxed
);
if
(
countValue
==
0
){
vides_data
::
requestLicensePlate
initPlate
;
...
...
@@ -833,7 +824,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
qDebug
()
<<
QString
(
"%1==>当前车牌数量:%2"
).
arg
(
sSn
).
arg
(
newPlate
.
plates
.
size
());
if
(
newPlate
.
plates
.
size
()
>
0
){
foreach
(
auto
var
,
newPlate
.
plates
)
{
q
Debug
()
<<
QString
(
"sn:%1 =>识别的车牌号是:%2"
).
arg
(
sSn
).
arg
(
var
.
new_plate
);
q
Info
()
<<
QString
(
"sn:%1 =>识别的车牌号是:%2"
).
arg
(
sSn
).
arg
(
var
.
new_plate
);
}
licensePlateRecognitionResults
(
newPlate
);
...
...
CameraHandle.h
View file @
045a3ddf
...
...
@@ -59,7 +59,7 @@ public:
void
notificationUpdateImageMap
(
std
::
map
<
QString
,
QString
>&
maps
,
int
numberFaces
,
float
confidence
);
void
featureRemove
();
void
featureRemove
();
void
updateImage
(
const
cv
::
Mat
&
frame
,
qint64
currentTime
);
...
...
@@ -98,9 +98,9 @@ public:
void
findIp
(
QString
&
ip
);
void
sdkDownloadFileByTime
(
XSDK_HANDLE
hDevice
,
int
id
,
QString
startTimer
,
QString
endTime
);
QString
startTimer
,
QString
endTime
);
void
batchRegionalPushLicensePlate
(
QByteArray
&
imgs
,
qint64
currentTime
,
vides_data
::
requestLicensePlate
&
newPlate
);
void
faceUniformOverlap
(
std
::
map
<
QString
,
vides_data
::
requestFaceReconition
>&
mapFaces
,
std
::
vector
<
vides_data
::
ParkingArea
>
&
uniforms
,
std
::
list
<
QString
>&
outUniforms
);
...
...
@@ -110,7 +110,7 @@ public:
QString
getSSn
();
int
getMediaHandle
();
void
setMediaHandle
(
int
mediaHandle
);
void
initAlgorithmPermissions
(
__uint8_t
algorithm
);
void
initParkingSpaceInfo
(
const
std
::
list
<
vides_data
::
responseArea
>&
areas
);
...
...
@@ -152,7 +152,7 @@ private :
SXSDKLoginParam
*
loginParam
;
SXMediaFaceImageReq
*
sxMediaFaceImageReq
;
QString
sSn
;
QString
url
;
std
::
map
<
int
,
vides_data
::
responseRecognitionData
>
videoCurrentData
;
...
...
@@ -172,7 +172,7 @@ private :
QTimer
*
dev_snap_syn_timer
;
int
offlineCount
=
0
;
QSemaphore
semaphore
;
int
image_save
;
...
...
MediaFaceImage.cpp
View file @
045a3ddf
...
...
@@ -61,11 +61,8 @@ static int sdkInitCallback(XSDK_HANDLE hObject, int nMsgId, int nParam1,
threadPool
->
setMaxThreadCount
(
12
);
auto
taskCallBack
=
std
::
bind
(
&
CameraHandle
::
callbackFunction
,
cameraHandle
,
hObject
,
qString
);
auto
taskRunnable
=
new
TaskRunnable
(
taskCallBack
,
hObject
,
cameraHandle
->
getChannel
(),
RunFunction
::
SdkCallbackFunction
);
// task->setAutoDelete(false); // 确保task不会在执行后被自动删除
threadPool
->
start
(
taskRunnable
);
// if (!threadPool->tryStart(task)) { // 尝试启动任务,如果线程池满了则不会启动
// qDebug() << "线程池已满,无法启动TaskRunnable";
// }
threadPool
->
start
(
taskRunnable
);
}
}
break
;
...
...
TaskRunnable.cpp
View file @
045a3ddf
...
...
@@ -4,7 +4,7 @@ TaskRunnable::TaskRunnable(std::function<void()> newTask, int hDevice, int chann
:
m_hDevice
(
hDevice
),
m_channel
(
channel
),
runFunction
(
func
){
if
(
runFunction
==
SdkDevSnapSyn
)
{
this
->
devSnapSyn
=
newTask
;
}
}
if
(
runFunction
==
SdkCallbackFunction
){
this
->
callbackFunction
=
newTask
;
}
...
...
@@ -45,9 +45,9 @@ void TaskRunnable::run() {
callbackFunction
();
// 调用函数
}
}
catch
(
const
std
::
exception
&
e
)
{
q
Debug
()
<<
"在任务运行过程中发生异常:"
<<
e
.
what
();
q
Info
()
<<
"在任务运行过程中发生异常:"
<<
e
.
what
();
}
catch
(...)
{
q
Debug
()
<<
"在任务运行过程中发生未知异常"
;
q
Info
()
<<
"在任务运行过程中发生未知异常"
;
}
}
mainwindow.cpp
View file @
045a3ddf
...
...
@@ -33,14 +33,6 @@ MainWindow::MainWindow()
deleteFrameFileTimer
->
start
(
deMkvflieTimer
);
initFaceFaceRecognition
();
// FaceReconition &faceRecognition = FaceReconition::getInstance();
// float confidence=qSetting->value("devices/confidence").toFloat();
// int faceNumbers=qSetting->value("devices/faceNumbers").toInt();
// if(localImageMap.size()>0){
// faceRecognition.initSourceImageMap(localImageMap,faceNumbers,confidence);
// }
float
heightReference
=
qSetting
->
value
(
"devices/height_reference"
).
toFloat
();
...
...
@@ -314,12 +306,12 @@ void MainWindow::updateLocalFace(const QString &httpurl) {
//float confidence=qSetting->value("devices/confidence").toFloat();
//int faceNumbers=qSetting->value("devices/faceNumbers").toInt();
q
Debug
()
<<
"startMap != endMap-->"
;
q
Info
()
<<
"startMap != endMap-->"
;
// faceRecognition.initSourceImageMap(localImageMap,faceNumbers, confidence);
algorithmTaskManage
.
modifyImageFeature
(
localImageMap
,
faceNumbers
,
confidence
,
false
);
}
}
}
for
(
vides_data
::
responseFaceReconition
*
data
:
datas
)
{
instance
.
deleteObj
(
data
);
...
...
@@ -356,7 +348,7 @@ void MainWindow::clearHandle(QString sDevId, int nDevPort){
if
(
it
!=
this
->
faceDetectionParkingPushs
.
end
())
{
MediaFaceImage
*
mediaFaceImage
=
MediaFaceImage
::
getInstance
();
q
Debug
()
<<
"clearHandle:离线的设备是:"
<<
key
;
q
Info
()
<<
"clearHandle:离线的设备是:"
<<
key
;
CameraHandle
*
offlineCameraHandle
=
it
->
second
;
// 注意使用->second获取值
int
hDevice
=
offlineCameraHandle
->
getHdevice
();
instace
.
deleteObj
(
offlineCameraHandle
);
...
...
@@ -885,14 +877,14 @@ void MainWindow::setVideoPath(int flag, const QString& path) {
void
MainWindow
::
createDirectory
(
int
flag
,
const
QString
&
dirName
,
const
QString
&
successMsg
,
const
QString
&
failureMsg
)
{
QDir
directory
;
if
(
directory
.
exists
(
dirName
))
{
q
Debug
()
<<
successMsg
<<
"目录已存在"
;
q
Info
()
<<
successMsg
<<
"目录已存在"
;
setVideoPath
(
flag
,
directory
.
absoluteFilePath
(
dirName
));
}
else
{
if
(
directory
.
mkdir
(
dirName
))
{
q
Debug
()
<<
successMsg
<<
"目录创建成功"
;
q
Info
()
<<
successMsg
<<
"目录创建成功"
;
setVideoPath
(
flag
,
directory
.
absoluteFilePath
(
dirName
));
}
else
{
q
Debug
()
<<
failureMsg
<<
"目录创建失败"
;
q
Info
()
<<
failureMsg
<<
"目录创建失败"
;
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment