Commit 045a3ddf by “liusq”

调度算法优化秒到毫秒

parent fe54e885
......@@ -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;
......
......@@ -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
}
}
qDebug() << "最新车牌" << newInfo.getLicensePlate() << "区域当前车牌" << park->getCurrentPlate().getLicensePlate();
qDebug() << "不同的区域:" << park->getSpaceIndex() << ",数量:" << count;
qInfo() << "最新车牌" << newInfo.getLicensePlate() << "区域当前车牌" << park->getCurrentPlate().getLicensePlate();
qInfo() << "不同的区域:" << 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);
qDebug()<<sSn<<":"<<"当前车形数量:"<<car_size;
qInfo()<<sSn<<":"<<"当前车形数量:"<<car_size;
if (car_size <= 0 && car_size!=-2) {
qDebug() << sSn<<"区域:"<<park->getSpaceIndex() << ": 出场:";
qInfo() << sSn<<"区域:"<<park->getSpaceIndex() << ": 出场:";
//如果有车辆检测到并且不在停车区域内部,视为出场
park->setCurrentPlate(newInfo);
result = Exit;
}else {
// 没有车辆或车辆在停车区域内部,移除队列
park->removeNoQueue();
qDebug() << sSn << ": no出场:" << car_size;
qInfo() << sSn << ": no出场:" << car_size;
}
}else{
qDebug()<<sSn<<":"<<"老车出场:"<<park->getCurrentPlate().getLicensePlate();
qDebug()<<sSn<<":"<<"新车入场:"<<newInfo.getLicensePlate();
qInfo()<<sSn<<":"<<"老车出场:"<<park->getCurrentPlate().getLicensePlate();
qInfo()<<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) {
qDebug() << "图片已成功保存至:" << fileName;
qInfo() << "图片已成功保存至:" << fileName;
} else {
qDebug() << "图片保存失败!";
qInfo() << "图片保存失败!";
}
}
......@@ -685,9 +676,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
bool success = cv::imwrite(fileName.toStdString(), areaMat);
if (success) {
qDebug() << "图片已成功保存至:" << fileName;
qInfo() << "图片已成功保存至:" << fileName;
} else {
qDebug() << "图片保存失败!";
qInfo() << "图片保存失败!";
}
}
......@@ -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) {
qDebug()<<QString("sn:%1 =>识别的车牌号是:%2").arg(sSn).arg(var.new_plate);
qInfo()<<QString("sn:%1 =>识别的车牌号是:%2").arg(sSn).arg(var.new_plate);
}
licensePlateRecognitionResults(newPlate);
......
......@@ -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;
......
......@@ -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;
......
......@@ -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) {
qDebug() << "在任务运行过程中发生异常:" << e.what();
qInfo() << "在任务运行过程中发生异常:" << e.what();
} catch (...) {
qDebug() << "在任务运行过程中发生未知异常";
qInfo() << "在任务运行过程中发生未知异常";
}
}
......@@ -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();
qDebug()<<"startMap != endMap-->";
qInfo()<<"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();
qDebug()<<"clearHandle:离线的设备是:"<<key;
qInfo()<<"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)) {
qDebug() << successMsg << "目录已存在";
qInfo() << successMsg << "目录已存在";
setVideoPath(flag, directory.absoluteFilePath(dirName));
} else {
if (directory.mkdir(dirName)) {
qDebug() << successMsg << "目录创建成功";
qInfo() << successMsg << "目录创建成功";
setVideoPath(flag, directory.absoluteFilePath(dirName));
} else {
qDebug() << failureMsg << "目录创建失败";
qInfo() << failureMsg << "目录创建失败";
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment