完成框架目录和模块重构;新增核心、单例、工具、加密及框架 SDK;统一任务、相机和 RPC 接口,并增加离线检测、相机标定、备份恢复、版本管理、崩溃守护和心跳监控功能。
89 lines
3.7 KiB
C++
89 lines
3.7 KiB
C++
#pragma once
|
|
#include <qstring.h>
|
|
#include <iostream>
|
|
#include <random>
|
|
|
|
struct valueControlStruct {
|
|
double minThreshold;
|
|
double maxThreshold;
|
|
bool enable;
|
|
};
|
|
//生成一个数据的上下限与是否启用
|
|
//类名 值名 单位名 默认下限 默认上限 默认是否启用 数据同步类
|
|
template <typename ParamSyncManager>
|
|
static valueControlStruct genValueControlStruct(QString className,
|
|
QString valueName,
|
|
QString unitStr,
|
|
double basicMaxThreshold,
|
|
double basicMinThreshold,
|
|
bool basicEnable,
|
|
ParamSyncManager* sync) {
|
|
valueControlStruct r;
|
|
r.maxThreshold = sync->get(className, valueName + "上限(" + unitStr + ")", basicMaxThreshold).toDouble();
|
|
r.minThreshold = sync->get(className, valueName + "下限(" + unitStr + ")", basicMinThreshold).toDouble();
|
|
r.enable = sync->get(className, valueName + "判定启用", basicEnable).toBool();
|
|
return r;
|
|
}
|
|
|
|
|
|
static std::pair<bool, double> getPerfectOutputValue(
|
|
double realValue,
|
|
double minValue,
|
|
double maxValue,
|
|
double offsetValue)
|
|
{
|
|
static thread_local std::mt19937 rng(std::random_device{}());
|
|
std::uniform_real_distribution<double> dist(0.0, 0.2); //随机数
|
|
|
|
if (realValue < minValue) {// 低于下限
|
|
if (minValue - realValue <= offsetValue) {// 在补偿范围内
|
|
return { true, minValue + dist(rng) };// 返回补偿后的值
|
|
}
|
|
return { false, realValue }; // 不在在补偿范围内 返回真实值
|
|
}
|
|
else if (realValue > maxValue) {
|
|
if (realValue - maxValue <= offsetValue) {// 在补偿范围内
|
|
return { true, maxValue - dist(rng) };// 返回补偿后的值
|
|
}
|
|
return { false, realValue }; // 不在在补偿范围内 返回真实值
|
|
}
|
|
|
|
return { false, realValue };// 在范围内,无需补偿,返回真实值
|
|
}
|
|
static std::string controlAccuracy(float num, int length) {
|
|
std::string resultString = std::to_string(num);
|
|
resultString = resultString.substr(0, resultString.find(".") + length + 1);
|
|
return resultString;
|
|
}
|
|
//包含判断结果 输出打印任务 补偿
|
|
static void valueJudgement(double& value, double upThreshold, double downThreshold, double offset,
|
|
bool jugementEnable, bool& halconOk, std::string valueDisplayText, std::string valueDanWei, std::string ngText,
|
|
cv::Point p, std::vector<std::string>& defects, cvPainter& _cvPainter) {
|
|
cv::Scalar color = cv::Scalar(0, 255, 0);
|
|
double newValue = getPerfectOutputValue(value, downThreshold, upThreshold, offset).second;
|
|
if (newValue > upThreshold || newValue < downThreshold) {
|
|
color = cv::Scalar(0, 0, 255);
|
|
if (jugementEnable == true) {
|
|
halconOk = false;
|
|
defects.push_back(ngText);
|
|
}
|
|
}
|
|
_cvPainter.appendPaintJob(valueDisplayText + controlAccuracy(newValue, 4) + valueDanWei, p, color);
|
|
value = newValue;
|
|
}
|
|
static void valueJudgement(double& value, valueControlStruct valueControlStructInput, double offset,
|
|
bool& halconOk, std::string valueDisplayText, std::string valueDanWei, std::string ngText,
|
|
cv::Point p, std::vector<std::string>& defects, cvPainter& _cvPainter) {
|
|
cv::Scalar color = cv::Scalar(0, 255, 0);
|
|
double newValue = getPerfectOutputValue(value, valueControlStructInput.minThreshold, valueControlStructInput.maxThreshold, offset).second;
|
|
if (newValue > valueControlStructInput.maxThreshold || newValue < valueControlStructInput.minThreshold) {
|
|
color = cv::Scalar(0, 0, 255);
|
|
if (valueControlStructInput.enable == true) {
|
|
halconOk = false;
|
|
defects.push_back(ngText);
|
|
}
|
|
}
|
|
_cvPainter.appendPaintJob(valueDisplayText + controlAccuracy(newValue, 4) + valueDanWei, p, color);
|
|
value = newValue;
|
|
}
|