Commit 045a3ddf by “liusq”

调度算法优化秒到毫秒

parent fe54e885
...@@ -45,40 +45,35 @@ public: ...@@ -45,40 +45,35 @@ public:
private: private:
template<typename T> template<typename T>
T* schedulingAlgorithmTemplate(std::vector<T*>& objects, std::mutex& mtx) { T* schedulingAlgorithmTemplate(std::vector<T*>& objects, std::mutex& mtx) {
std::lock_guard<std::mutex> lock(mtx); std::lock_guard<std::mutex> lock(mtx);
qint64 currentTime = QDateTime::currentSecsSinceEpoch(); qint64 currentTime = QDateTime::currentMSecsSinceEpoch();
qint64 maxWaitTime = 0; qint64 maxWaitTime = 0;
int maxWaitTimeCount = 0; std::vector<T*> schedulableObjects;
std::vector<T*> schedulableObjects;
for (T* obj : objects) {
for (T* obj : objects) { if (obj->getIsRunning()) continue;
if (obj->getIsRunning()) continue; qint64 waitTime = std::abs(currentTime - obj->getThreadTime());
qint64 waitTime = std::abs(currentTime - obj->getThreadTime()); if (waitTime > maxWaitTime) {
if (waitTime > maxWaitTime) { schedulableObjects.clear();
schedulableObjects.clear(); schedulableObjects.push_back(obj);
schedulableObjects.push_back(obj); maxWaitTime = waitTime;
maxWaitTime = waitTime; } else if (waitTime == maxWaitTime) {
maxWaitTimeCount = 1; schedulableObjects.push_back(obj);
} else if (waitTime == maxWaitTime) { }
schedulableObjects.push_back(obj); }
maxWaitTimeCount++; if (schedulableObjects.empty()) {
} return nullptr;
} }
if (schedulableObjects.size() == 1) {
if (maxWaitTimeCount == 1) { return schedulableObjects.at(0);
return schedulableObjects.at(0); }
}
if (schedulableObjects.empty()) { std::random_device rd;
return nullptr; std::mt19937 gen(rd());
} std::uniform_int_distribution<> dis(0, schedulableObjects.size() - 1);
return schedulableObjects[dis(gen)];
std::random_device rd; }
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(0, schedulableObjects.size() - 1);
return schedulableObjects[dis(gen)];
}
static AlgorithmTaskManage* instance; static AlgorithmTaskManage* instance;
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#include "TaskRunnable.h" #include "TaskRunnable.h"
#include "AlgorithmTaskManage.h" #include "AlgorithmTaskManage.h"
#include "ScopeSemaphoreExit.h" #include "ScopeSemaphoreExit.h"
#include <QElapsedTimer>
#include <QRegularExpression> #include <QRegularExpression>
CameraHandle::CameraHandle(){ CameraHandle::CameraHandle(){
...@@ -31,7 +30,6 @@ CameraHandle::~CameraHandle() { ...@@ -31,7 +30,6 @@ CameraHandle::~CameraHandle() {
stopRequested_=true; stopRequested_=true;
Common & instace= Common::getInstance(); Common & instace= Common::getInstance();
dev_snap_syn_timer->stop(); dev_snap_syn_timer->stop();
qInfo() << "CameraHandle:关闭";
QThreadPool::globalInstance()->waitForDone(); QThreadPool::globalInstance()->waitForDone();
instace.deleteObj(dev_snap_syn_timer); instace.deleteObj(dev_snap_syn_timer);
...@@ -44,7 +42,6 @@ CameraHandle::~CameraHandle() { ...@@ -44,7 +42,6 @@ CameraHandle::~CameraHandle() {
parkMap.clear(); parkMap.clear();
XSDK_DevLogout(this->hDevice); XSDK_DevLogout(this->hDevice);
qInfo() << "CameraHandle:成功";
} }
int CameraHandle::sdkDevLoginSyn(QString sDevId, int nDevPort, QString sUserName, QString sPassword, int nTimeout) { 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 ...@@ -425,8 +422,8 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma
} }
} }
qDebug() << "最新车牌" << newInfo.getLicensePlate() << "区域当前车牌" << park->getCurrentPlate().getLicensePlate(); qInfo() << "最新车牌" << newInfo.getLicensePlate() << "区域当前车牌" << park->getCurrentPlate().getLicensePlate();
qDebug() << "不同的区域:" << park->getSpaceIndex() << ",数量:" << count; qInfo() << "不同的区域:" << park->getSpaceIndex() << ",数量:" << count;
if (count>= 3) { if (count>= 3) {
//第一次进场 当前车牌就是进来这个,老车牌就是空 //第一次进场 当前车牌就是进来这个,老车牌就是空
if(park->getCurrentPlate().getLicensePlate().length()<=0){ if(park->getCurrentPlate().getLicensePlate().length()<=0){
...@@ -446,21 +443,21 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma ...@@ -446,21 +443,21 @@ void CameraHandle::checkAndUpdateCurrentPlate(ParkingSpaceInfo*park,const cv::Ma
std::map<int,int>resMap; std::map<int,int>resMap;
int car_size =algorithmTaskManage.executeFindHuManCar(frame,0x01,currentPlates,resMap,sSn); 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) { if (car_size <= 0 && car_size!=-2) {
qDebug() << sSn<<"区域:"<<park->getSpaceIndex() << ": 出场:"; qInfo() << sSn<<"区域:"<<park->getSpaceIndex() << ": 出场:";
//如果有车辆检测到并且不在停车区域内部,视为出场 //如果有车辆检测到并且不在停车区域内部,视为出场
park->setCurrentPlate(newInfo); park->setCurrentPlate(newInfo);
result = Exit; result = Exit;
}else { }else {
// 没有车辆或车辆在停车区域内部,移除队列 // 没有车辆或车辆在停车区域内部,移除队列
park->removeNoQueue(); park->removeNoQueue();
qDebug() << sSn << ": no出场:" << car_size; qInfo() << sSn << ": no出场:" << car_size;
} }
}else{ }else{
qDebug()<<sSn<<":"<<"老车出场:"<<park->getCurrentPlate().getLicensePlate(); qInfo()<<sSn<<":"<<"老车出场:"<<park->getCurrentPlate().getLicensePlate();
qDebug()<<sSn<<":"<<"新车入场:"<<newInfo.getLicensePlate(); qInfo()<<sSn<<":"<<"新车入场:"<<newInfo.getLicensePlate();
//当前不为空,新车,新车入场,老车出场 //当前不为空,新车,新车入场,老车出场
//exitAndMoMap[Exit]=park->getCurrentPlate(); //exitAndMoMap[Exit]=park->getCurrentPlate();
...@@ -557,8 +554,6 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){ ...@@ -557,8 +554,6 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
std::vector<vides_data::ParkingArea> currentPlates; std::vector<vides_data::ParkingArea> currentPlates;
int uniforms=0x00; int uniforms=0x00;
std::map<int,int>resMap; std::map<int,int>resMap;
QElapsedTimer timer;
timer.start();
//穿工服算法 //穿工服算法
if ((algorithmPermissions & 0x01<<2) != 0) { if ((algorithmPermissions & 0x01<<2) != 0) {
...@@ -575,12 +570,8 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){ ...@@ -575,12 +570,8 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
uniforms=faSize; uniforms=faSize;
} }
} }
qint64 elapsedTime = timer.elapsed();
qInfo()<<"人脸数量==>"<<faSize; qInfo()<<"人脸数量==>"<<faSize;
qInfo()<<"未穿工服数量==>"<<uniforms; qInfo()<<"未穿工服数量==>"<<uniforms;
qInfo() << "humanDetectionManage.executeFindHuManCa:执行时间"<<elapsedTime / 1000;
if(uniforms==-2 || faSize==-2){ if(uniforms==-2 || faSize==-2){
qInfo() << "没有可用的HumanDetection对象可以调度"; qInfo() << "没有可用的HumanDetection对象可以调度";
return ; return ;
...@@ -668,9 +659,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){ ...@@ -668,9 +659,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
bool success = cv::imwrite(fileName.toStdString(), frame); bool success = cv::imwrite(fileName.toStdString(), frame);
if (success) { if (success) {
qDebug() << "图片已成功保存至:" << fileName; qInfo() << "图片已成功保存至:" << fileName;
} else { } else {
qDebug() << "图片保存失败!"; qInfo() << "图片保存失败!";
} }
} }
...@@ -685,9 +676,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){ ...@@ -685,9 +676,9 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
bool success = cv::imwrite(fileName.toStdString(), areaMat); bool success = cv::imwrite(fileName.toStdString(), areaMat);
if (success) { if (success) {
qDebug() << "图片已成功保存至:" << fileName; qInfo() << "图片已成功保存至:" << fileName;
} else { } else {
qDebug() << "图片保存失败!"; qInfo() << "图片保存失败!";
} }
} }
...@@ -698,7 +689,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){ ...@@ -698,7 +689,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
vides_data::requestLicensePlate newPlate; vides_data::requestLicensePlate newPlate;
newPlate.sn=sSn; newPlate.sn=sSn;
uint64_t countValue = faceCount.load(std::memory_order_relaxed); uint64_t countValue =faceCount.load(std::memory_order_relaxed);
if(countValue==0 ){ if(countValue==0 ){
vides_data::requestLicensePlate initPlate; vides_data::requestLicensePlate initPlate;
...@@ -833,7 +824,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){ ...@@ -833,7 +824,7 @@ void CameraHandle::updateImage(const cv::Mat & frame,qint64 currentTime){
qDebug()<<QString("%1==>当前车牌数量:%2").arg(sSn).arg(newPlate.plates.size()); qDebug()<<QString("%1==>当前车牌数量:%2").arg(sSn).arg(newPlate.plates.size());
if(newPlate.plates.size()>0){ if(newPlate.plates.size()>0){
foreach (auto var, newPlate.plates) { 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); licensePlateRecognitionResults(newPlate);
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
void notificationUpdateImageMap(std::map<QString,QString>&maps,int numberFaces,float confidence); void notificationUpdateImageMap(std::map<QString,QString>&maps,int numberFaces,float confidence);
void featureRemove(); void featureRemove();
void updateImage(const cv::Mat & frame,qint64 currentTime); void updateImage(const cv::Mat & frame,qint64 currentTime);
...@@ -98,9 +98,9 @@ public: ...@@ -98,9 +98,9 @@ public:
void findIp(QString &ip); void findIp(QString &ip);
void sdkDownloadFileByTime(XSDK_HANDLE hDevice,int id, 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 batchRegionalPushLicensePlate(QByteArray &imgs,qint64 currentTime,vides_data::requestLicensePlate &newPlate);
void faceUniformOverlap(std::map<QString,vides_data::requestFaceReconition>&mapFaces, void faceUniformOverlap(std::map<QString,vides_data::requestFaceReconition>&mapFaces,
std::vector<vides_data::ParkingArea> &uniforms, std::vector<vides_data::ParkingArea> &uniforms,
std::list<QString>&outUniforms); std::list<QString>&outUniforms);
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
QString getSSn(); QString getSSn();
int getMediaHandle(); int getMediaHandle();
void setMediaHandle(int mediaHandle); void setMediaHandle(int mediaHandle);
void initAlgorithmPermissions(__uint8_t algorithm); void initAlgorithmPermissions(__uint8_t algorithm);
void initParkingSpaceInfo(const std::list<vides_data::responseArea>&areas); void initParkingSpaceInfo(const std::list<vides_data::responseArea>&areas);
...@@ -152,7 +152,7 @@ private : ...@@ -152,7 +152,7 @@ private :
SXSDKLoginParam *loginParam; SXSDKLoginParam *loginParam;
SXMediaFaceImageReq *sxMediaFaceImageReq; SXMediaFaceImageReq *sxMediaFaceImageReq;
QString sSn; QString sSn;
QString url; QString url;
std::map<int, vides_data::responseRecognitionData> videoCurrentData; std::map<int, vides_data::responseRecognitionData> videoCurrentData;
...@@ -172,7 +172,7 @@ private : ...@@ -172,7 +172,7 @@ private :
QTimer *dev_snap_syn_timer; QTimer *dev_snap_syn_timer;
int offlineCount=0; int offlineCount=0;
QSemaphore semaphore; QSemaphore semaphore;
int image_save; int image_save;
......
...@@ -61,11 +61,8 @@ static int sdkInitCallback(XSDK_HANDLE hObject, int nMsgId, int nParam1, ...@@ -61,11 +61,8 @@ static int sdkInitCallback(XSDK_HANDLE hObject, int nMsgId, int nParam1,
threadPool->setMaxThreadCount(12); threadPool->setMaxThreadCount(12);
auto taskCallBack=std::bind(&CameraHandle::callbackFunction, cameraHandle, hObject, qString); auto taskCallBack=std::bind(&CameraHandle::callbackFunction, cameraHandle, hObject, qString);
auto taskRunnable = new TaskRunnable(taskCallBack, hObject,cameraHandle->getChannel(), RunFunction::SdkCallbackFunction); auto taskRunnable = new TaskRunnable(taskCallBack, hObject,cameraHandle->getChannel(), RunFunction::SdkCallbackFunction);
// task->setAutoDelete(false); // 确保task不会在执行后被自动删除 threadPool->start(taskRunnable);
threadPool->start(taskRunnable);
// if (!threadPool->tryStart(task)) { // 尝试启动任务,如果线程池满了则不会启动
// qDebug() << "线程池已满,无法启动TaskRunnable";
// }
} }
} }
break; break;
......
...@@ -4,7 +4,7 @@ TaskRunnable::TaskRunnable(std::function<void()> newTask, int hDevice, int chann ...@@ -4,7 +4,7 @@ TaskRunnable::TaskRunnable(std::function<void()> newTask, int hDevice, int chann
:m_hDevice(hDevice), m_channel(channel), runFunction(func){ :m_hDevice(hDevice), m_channel(channel), runFunction(func){
if (runFunction == SdkDevSnapSyn) { if (runFunction == SdkDevSnapSyn) {
this->devSnapSyn = newTask; this->devSnapSyn = newTask;
} }
if(runFunction==SdkCallbackFunction){ if(runFunction==SdkCallbackFunction){
this->callbackFunction = newTask; this->callbackFunction = newTask;
} }
...@@ -45,9 +45,9 @@ void TaskRunnable::run() { ...@@ -45,9 +45,9 @@ void TaskRunnable::run() {
callbackFunction(); // 调用函数 callbackFunction(); // 调用函数
} }
} catch (const std::exception& e) { } catch (const std::exception& e) {
qDebug() << "在任务运行过程中发生异常:" << e.what(); qInfo() << "在任务运行过程中发生异常:" << e.what();
} catch (...) { } catch (...) {
qDebug() << "在任务运行过程中发生未知异常"; qInfo() << "在任务运行过程中发生未知异常";
} }
} }
...@@ -33,14 +33,6 @@ MainWindow::MainWindow() ...@@ -33,14 +33,6 @@ MainWindow::MainWindow()
deleteFrameFileTimer->start(deMkvflieTimer); deleteFrameFileTimer->start(deMkvflieTimer);
initFaceFaceRecognition(); 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(); float heightReference=qSetting->value("devices/height_reference").toFloat();
...@@ -314,12 +306,12 @@ void MainWindow::updateLocalFace(const QString &httpurl) { ...@@ -314,12 +306,12 @@ void MainWindow::updateLocalFace(const QString &httpurl) {
//float confidence=qSetting->value("devices/confidence").toFloat(); //float confidence=qSetting->value("devices/confidence").toFloat();
//int faceNumbers=qSetting->value("devices/faceNumbers").toInt(); //int faceNumbers=qSetting->value("devices/faceNumbers").toInt();
qDebug()<<"startMap != endMap-->"; qInfo()<<"startMap != endMap-->";
// faceRecognition.initSourceImageMap(localImageMap,faceNumbers, confidence); // faceRecognition.initSourceImageMap(localImageMap,faceNumbers, confidence);
algorithmTaskManage.modifyImageFeature(localImageMap,faceNumbers,confidence,false); algorithmTaskManage.modifyImageFeature(localImageMap,faceNumbers,confidence,false);
} }
} }
for (vides_data::responseFaceReconition* data : datas) for (vides_data::responseFaceReconition* data : datas)
{ {
instance.deleteObj(data); instance.deleteObj(data);
...@@ -356,7 +348,7 @@ void MainWindow::clearHandle(QString sDevId, int nDevPort){ ...@@ -356,7 +348,7 @@ void MainWindow::clearHandle(QString sDevId, int nDevPort){
if (it != this->faceDetectionParkingPushs.end()) { if (it != this->faceDetectionParkingPushs.end()) {
MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance(); MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
qDebug()<<"clearHandle:离线的设备是:"<<key; qInfo()<<"clearHandle:离线的设备是:"<<key;
CameraHandle* offlineCameraHandle = it->second; // 注意使用->second获取值 CameraHandle* offlineCameraHandle = it->second; // 注意使用->second获取值
int hDevice=offlineCameraHandle->getHdevice(); int hDevice=offlineCameraHandle->getHdevice();
instace.deleteObj(offlineCameraHandle); instace.deleteObj(offlineCameraHandle);
...@@ -885,14 +877,14 @@ void MainWindow::setVideoPath(int flag, const QString& path) { ...@@ -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) { void MainWindow::createDirectory(int flag,const QString& dirName, const QString& successMsg, const QString& failureMsg) {
QDir directory; QDir directory;
if (directory.exists(dirName)) { if (directory.exists(dirName)) {
qDebug() << successMsg << "目录已存在"; qInfo() << successMsg << "目录已存在";
setVideoPath(flag, directory.absoluteFilePath(dirName)); setVideoPath(flag, directory.absoluteFilePath(dirName));
} else { } else {
if (directory.mkdir(dirName)) { if (directory.mkdir(dirName)) {
qDebug() << successMsg << "目录创建成功"; qInfo() << successMsg << "目录创建成功";
setVideoPath(flag, directory.absoluteFilePath(dirName)); setVideoPath(flag, directory.absoluteFilePath(dirName));
} else { } 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