调整UI展示页面颜色

优化找圆算法
master
bob.pan 5 years ago
parent 0cc1d79843
commit 7d83d47160

@ -2300,8 +2300,7 @@ float ImageCompareModel::allocateRadius(cv::Mat subImage)
void ImageCompareModel::genOutterMask()
{
m32fMaskImg = genMask(mAlignBaseImg, Point2f(mAlignBaseImg.cols / 2.0, mAlignBaseImg.rows / 2.0));
m8uMaskImg = genMask(mAlignBaseImg, Point2f(mAlignBaseImg.cols / 2.0, mAlignBaseImg.rows / 2.0),
-1.0, -1.0, CV_8UC1);
m8uMaskImg = genMask(mAlignBaseImg, Point2f(mAlignBaseImg.cols / 2.0, mAlignBaseImg.rows / 2.0), -1.0, -1.0, CV_8UC1);
}
void ImageCompareModel::resizeVecMat(vector<Mat> srcVec, vector<Mat> &dstVec)

@ -301,13 +301,17 @@ int CAlgorithmCompare::IImageAnalysis(class IImageObject* pImgObj)
else{
bReload = false;
}
//matMatch = ImageProcess::findCircleObject(matSrc, matBack, bUseBackground, nthreshold/*15*/, &lCircle/* NULL*/);
if (bUseBackground == true)//使用背景图 做减法找圆
{
matMatch = ImageProcess::findCircleByBackground(matSrc, matBack, &lCircle);
}
else {//不需要 背景图找圆算法
Point2f centerPoint;
double radius = 0;
matMatch = ImageProcess::findCircle(matSrc, centerPoint, radius, bEqual, filterCircleSize);
lCircle.ptCenter = centerPoint;
lCircle.fRadius = radius;
}
if (matMatch.cols >= 900 || matMatch.rows >= 900)
{

@ -4,7 +4,6 @@
#include "ED.h"
#include "EDLines.h"
#include "EDCircles.h"
#include "CircleDetector.h"
//摩轮宏定义 表示该算法用于摩轮型号识别检测
@ -47,522 +46,6 @@ Mat findEdge2(const Mat &Src)
}
#define REAIZE 2
cv::Mat ImageProcess::findCircleObject(const Mat &srcImg, const Mat& backgroundImg, bool useBackgroundFlag, int nThres /*= 20*/, luffy_base::luffyCircle *pCircle /*= NULL*/)
{
#ifdef MOTO_DETECT//摩轮型号识别抠图算法
if (!useBackgroundFlag)
{
Mat detectImg;
Mat src = srcImg(Rect(435, 53, 1721, 1824));
cv::resize(src, detectImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE));
int bBaseX = detectImg.cols;
int bBaseY = detectImg.rows;
equalizeHist(detectImg, detectImg);
detectImg = _EnhanImg_sharpen(detectImg);
EDCircles edcircles(detectImg);
vector<mCircle> EDCircle = edcircles.getCircles();
double maxR = 0;
int nIndex = -1;
for (int i = 0; i < EDCircle.size(); i++)
{
int startX = EDCircle[i].center.x - EDCircle[i].r;
int startY = EDCircle[i].center.y - EDCircle[i].r;
if (startX < 0 || startY < 0)
continue;
if (EDCircle[i].center.x + EDCircle[i].r > bBaseX || EDCircle[i].center.y + EDCircle[i].r > bBaseY)
continue;
if (EDCircle[i].r > maxR)
{
maxR = EDCircle[i].r;
nIndex = i;
}
}
if (nIndex != -1)
{
int startX = EDCircle[nIndex].center.x * REAIZE - EDCircle[nIndex].r * REAIZE;
int startY = EDCircle[nIndex].center.y * REAIZE - EDCircle[nIndex].r* REAIZE;
double radius = EDCircle[nIndex].r;
int hight = 2 * radius * REAIZE;
if (startX > 0 && startY > 0 && hight > 0 \
&& startX < src.cols &&startY < src.rows \
&& hight < src.cols&&hight < src.rows \
&& (startX + hight) < src.cols && (startY + hight) < src.rows)
{
Mat cutMat = src(Rect(startX, startY, hight, hight));
if (cutMat.data != NULL)
{
if (hight < 50)
return Mat();
cv::Point2d center;
center.x = EDCircle[nIndex].center.x * REAIZE;
center.y = EDCircle[nIndex].center.y * REAIZE;
pCircle->ptCenter = center;
pCircle->fRadius = radius * REAIZE;
//2021-05-10 增加图像大小判断 对超过900像素的图像进行再一次压缩
if (cutMat.cols >= 900 || cutMat.rows >= 900)
{
Mat newCutImg;
cv::resize(cutMat, newCutImg, cv::Size(cutMat.cols / REAIZE, cutMat.rows / REAIZE));
pCircle->fRadius = pCircle->fRadius / REAIZE;
return newCutImg;
}
return cutMat;
}
}
}
return Mat();
}
else
{
//结合背景图原始找圆算法
Mat src = srcImg;
if (src.empty() || backgroundImg.empty() || src.rows < 500) {
return Mat();
}
assert(backgroundImg.type() == CV_8UC1);
Mat imgTmp = src, imgBinary;
using namespace luffy_base;
luffy_threshold::Threshold(imgTmp, imgBinary, 50);//0421
Mat dilatedImgBin;
dilate(imgBinary, dilatedImgBin, Mat::ones(21, 21, CV_32FC1));
erode(dilatedImgBin, imgBinary, Mat::ones(21, 21, CV_32FC1));
openOper(imgBinary, Mat::ones(1, 11, CV_32FC1));
vector<vector<Point>> conts;
cv::findContours(imgBinary, conts, RETR_EXTERNAL, CHAIN_APPROX_NONE);
imgBinary.setTo(0);
int maxArea = 0;
for (int i = 0; i < conts.size(); i++) {
const vector<Point> &pt = conts.at(i);
if (pt.size() < 120) {
continue;
}
Rect rt = boundingRect(pt);
if (rt.width < 150 || rt.height < 150) {
continue;
}
drawContours(imgBinary, conts, i, Scalar::all(255), -1);
}
Mat hit; vector<Point> pts;
luffy_hit::firstHit4Circle(imgBinary, hit, pts, Point(imgBinary.cols / 2, imgBinary.rows / 2), 0, imgBinary.cols / 2, 360, luffy_hit::emHitIn2Out);
int nMinFitNum = 100;
luffy_imageProc::RansacParam rs(0.01, 3, 150, nMinFitNum, 240);
vector<Point> pts2 = luffy_imageProc::fitModelbyRansac(pts, luffy_imageProc::emModelCircle, &rs);
float fRadius;
Point2f ptCenter;
bool bFind = luffy_imageProc::lsCircleFit(pts2, fRadius, ptCenter);
if (!bFind) {
return Mat();
}
Mat dst;
const int nOffset = 1;
fRadius += nOffset;
Rect rt(ptCenter.x - fRadius + nOffset, ptCenter.y - fRadius + nOffset, 2 * fRadius, 2 * fRadius);
rt &= Rect(0, 0, imgTmp.cols, imgTmp.rows);
imgTmp(rt).copyTo(dst);
static int nCount = cv::getTickCount();
if (pCircle) {
float fScale = src.cols / ALG_RESIZE_IMAGE_WIDTH;
Mat matBig = src - backgroundImg;
pCircle->fRadius = fRadius * fScale;
pCircle->ptCenter = Point(ptCenter.x * fScale, ptCenter.y * fScale);
Mat matBinary;
luffy_threshold::Threshold(matBig, matBinary, nThres);
// add
openOper(matBinary, Mat::ones(3, 3, CV_32FC1));
Mat hit; vector<Point> pts;
luffy_hit::firstHit4Circle(matBinary, hit, pts, pCircle->ptCenter, 0, pCircle->fRadius + 20, 360, luffy_hit::emHitOut2In);//luffy_hit::emHitOut2In
std::map<double, cv::Point> mp;
std::for_each(pts.begin(), pts.end(), [&](Point p) {
double dis = fabs(luffy_math::disofPoints(pCircle->ptCenter, p));
mp[dis] = p;
});
const int bound = 200;
//int startIndex = mp.size() - bound;
std::map<double, cv::Point>::iterator it = mp.begin();
//std::advance(it, startIndex);
std::vector<cv::Point> ppts;
int i = 0;
for (it; it != mp.end(); ++it, ++i)
{
if (i == bound) break;
ppts.push_back(it->second);
}
luffy_imageProc::RansacParam rs(0.01, 5.0, 300, 70, 120);
vector<Point> pts2 = luffy_imageProc::fitModelbyRansac(ppts, luffy_imageProc::emModelCircle, &rs);
float fRadius2;
Point2f ptCenter2;
bool bFind = luffy_imageProc::lsCircleFit(pts2, fRadius2, ptCenter2);
if (bFind) {
pCircle->fRadius = fRadius2;
pCircle->ptCenter = ptCenter2;
Rect rt(ptCenter2.x - fRadius2 + nOffset, ptCenter2.y - fRadius2 + nOffset, 2 * fRadius2, 2 * fRadius2);
if (rt.x < 0 || rt.y < 0 || rt.x + rt.width > matBinary.cols || rt.y + rt.height > matBinary.rows) {
return Mat();
}
rt &= Rect(0, 0, matBinary.cols, matBinary.rows);
src(rt).copyTo(dst);
}
else
{
return Mat();
}
}
return dst;
}
#else//汽轮型号识别抠图算法
/*
2020-06-19 使
使EDCircle2.5
(),
使EDCircle
使()
*/
if (src.empty() || backgroundImg.empty() || src.rows < 500) {
return Mat();
}
bool findFlag = false;
/*第一阶梯找圆*/
assert(backgroundImg.type() == CV_8UC1);
Mat detectImg;
cv::resize(src, detectImg, cv::Size(src.cols / REAIZE, src.rows / REAIZE));
int bBaseX = detectImg.cols;
int bBaseY = detectImg.rows;
Mat upLight_Img = detectImg + 1.5 * detectImg;//20200423 修改 对图像进行叠加,增强目标亮度
blur(upLight_Img, upLight_Img, Size(3, 3));
EDCircles edcircles(upLight_Img);
vector<mCircle> EDCircle = edcircles.getCircles();
double maxR = 0;
int nIndex = -1;
for (int i = 0; i < EDCircle.size(); i++)
{
int startX = EDCircle[i].center.x - EDCircle[i].r;
int startY = EDCircle[i].center.y - EDCircle[i].r;
if (startX < 0 || startY <0)
continue;
if (EDCircle[i].center.x + EDCircle[i].r> bBaseX || EDCircle[i].center.y + EDCircle[i].r>bBaseY)
continue;
if (EDCircle[i].r > maxR)
{
maxR = EDCircle[i].r;
nIndex = i;
}
}
if (nIndex != -1)
{
int startX = EDCircle[nIndex].center.x * REAIZE - EDCircle[nIndex].r * REAIZE;
int startY = EDCircle[nIndex].center.y * REAIZE - EDCircle[nIndex].r* REAIZE;
double centerX = EDCircle[nIndex].center.x * REAIZE;
double centerY = EDCircle[nIndex].center.y * REAIZE;
double radius = EDCircle[nIndex].r;
if (radius < 50)//小于阈值 进行二次查找 radius一般大于100小于50像素的基本是其他小圆
{/*第二阶梯找圆 2020 - 06 - 19 添加 原图查找圆*/
blur(detectImg, detectImg, Size(3,3));
EDCircles edcircles2(detectImg);
vector<mCircle> EDCircle2 = edcircles2.getCircles();
double maxR = 0;
int mIndex = -1;
for (int i = 0; i < EDCircle2.size(); i++)
{
int startX = EDCircle2[i].center.x - EDCircle2[i].r;
int startY = EDCircle2[i].center.y - EDCircle2[i].r;
if (startX < 0 || startY < 0)
continue;
if (EDCircle2[i].center.x + EDCircle2[i].r > bBaseX || EDCircle2[i].center.y + EDCircle2[i].r > bBaseY)
continue;
if (EDCircle2[i].r > maxR)
{
maxR = EDCircle2[i].r;
mIndex = i;
}
}
if (mIndex == -1)
return Mat();
startX = EDCircle2[nIndex].center.x * REAIZE - EDCircle2[nIndex].r * REAIZE;
startY = EDCircle2[nIndex].center.y * REAIZE - EDCircle2[nIndex].r* REAIZE;
centerX = EDCircle2[nIndex].center.x * REAIZE;
centerY = EDCircle2[nIndex].center.y * REAIZE;
radius = EDCircle2[nIndex].r;
if (radius < 50)/*第三阶梯找圆*/
{
if (src.empty() || backgroundImg.empty() || src.rows < 500) {
return Mat();
}
assert(backgroundImg.type() == CV_8UC1);
Mat imgTmp, imgBinary;
const cv::Size cSize = cv::Size(ALG_RESIZE_IMAGE_WIDTH, floorf(ALG_RESIZE_IMAGE_WIDTH / (float)src.cols*(float)src.rows));
cv::resize(src, imgTmp, cSize);
Mat foregroundImg = getForeImage(imgTmp, backgroundImg);// 0421
using namespace luffy_base; //nThres = 90;
luffy_threshold::Threshold(foregroundImg, imgBinary, nThres);//0421
Mat dilatedImgBin;
closeOper(imgBinary, 7);
vector<vector<Point>> conts;
cv::findContours(imgBinary, conts, RETR_EXTERNAL, CHAIN_APPROX_NONE);
imgBinary.setTo(0);
//筛选最大轮廓的作为圆拟合区域
int maxsize = 0;
int nbestIndex = 0;
for (int i = 0; i < conts.size(); i++)
{
if (conts.at(i).size()>maxsize)
{
maxsize = conts.at(i).size();
nbestIndex = i;
}
}
if (conts.size() > 0)
{
drawContours(imgBinary, vector<vector<Point>>(1, conts.at(nbestIndex)), -1, Scalar::all(255), -1);
}
Mat hit; vector<Point> pts;
luffy_hit::firstHit4Circle(imgBinary, hit, pts, Point(cSize.width / 2, cSize.height / 2), 0, cSize.width / 2, 360, luffy_hit::emHitOut2In);
int nMinFitNum = 150;
if (pts.size() < nMinFitNum)//解决检测目标在图像边缘导致的抠图识别问题
{
if (conts.size()>0)
pts = conts.at(nbestIndex);
}
luffy_imageProc::RansacParam rs(0.01, 2, 150, nMinFitNum, 240);
vector<Point> pts2 = luffy_imageProc::fitModelbyRansac(pts, luffy_imageProc::emModelCircle, &rs);
float fRadius;
Point2f ptCenter;
bool bFind = luffy_imageProc::lsCircleFit(pts2, fRadius, ptCenter);
if (!bFind) {
return Mat();
}
Mat dst;
const int nOffset = 1;
fRadius += nOffset;
Rect rt(ptCenter.x - fRadius + nOffset, ptCenter.y - fRadius + nOffset, 2 * fRadius, 2 * fRadius);
rt &= Rect(0, 0, imgTmp.cols, imgTmp.rows);
imgTmp(rt).copyTo(dst);
static int nCount = cv::getTickCount();
if (pCircle) {
float fScale = src.cols / ALG_RESIZE_IMAGE_WIDTH;
Mat matBig = src - backgroundImg;
pCircle->fRadius = fRadius * fScale;
pCircle->ptCenter = Point(ptCenter.x * fScale, ptCenter.y * fScale);
Mat matBinary;
luffy_threshold::Threshold(matBig, matBinary, nThres);
Mat hit; vector<Point> pts;
luffy_hit::firstHit4Circle(matBinary, hit, pts, pCircle->ptCenter, 0, pCircle->fRadius + 10, 360, luffy_hit::emHitOut2In);//luffy_hit::emHitOut2In
luffy_imageProc::RansacParam rs(0.01, 2.5, 200, 150, 220);
vector<Point> pts2 = luffy_imageProc::fitModelbyRansac(pts, luffy_imageProc::emModelCircle, &rs);
float fRadius2;
Point2f ptCenter2;
bool bFind = luffy_imageProc::lsCircleFit(pts2, fRadius2, ptCenter2);
if (bFind) {
pCircle->fRadius = fRadius2;
pCircle->ptCenter = ptCenter2;
Rect rt(ptCenter2.x - fRadius2 + nOffset, ptCenter2.y - fRadius2 + nOffset, 2 * fRadius2, 2 * fRadius2);
if (rt.x < 0 || rt.y < 0 || rt.x + rt.width > matBinary.cols || rt.y + rt.height > matBinary.rows) {
return Mat();
}
rt &= Rect(0, 0, matBinary.cols, matBinary.rows);
src(rt).copyTo(dst);
int nWidth = ((int)((double)dst.cols / fScale / 4)) * 4;
cv::resize(dst, dst, cv::Size(nWidth, nWidth));
}
}
return dst;
}
}
int hight = 2 * radius * REAIZE;
if (startX > 0 && startY > 0 && hight > 0 \
&& startX < src.cols &&startY < src.rows \
&&hight < src.cols&&hight < src.rows \
&& startX+hight<src.cols && startY+hight<src.rows)
{
Mat cutMat = src(Rect(startX, startY, hight, hight));
if (cutMat.data != NULL)
{
if (hight < 50)
return Mat();
Mat dst;
double rate = src.cols*1.0 / ALG_RESIZE_IMAGE_WIDTH;
const cv::Size cSize = cv::Size(cutMat.cols*1.0 / rate, cutMat.rows*1.0 / rate);
cv::resize(cutMat, dst, cSize);
cv::Point2d center;
center.x = centerX;// EDCircle[nIndex].center.x * REAIZE;
center.y = centerY;// EDCircle[nIndex].center.y * REAIZE;
pCircle->ptCenter = center;
pCircle->fRadius = radius * REAIZE / rate;
return dst;
}
}
}
return Mat();
// /*以下为旧代码 目前不使用*/
// if (src.empty() || backgroundImg.empty() || src.rows < 500) {
// return Mat();
// }
//
// assert(backgroundImg.type() == CV_8UC1);
//
// Mat imgTmp, imgBinary;
// const cv::Size cSize = cv::Size(ALG_RESIZE_IMAGE_WIDTH, floorf(ALG_RESIZE_IMAGE_WIDTH / (float)src.cols*(float)src.rows));
// cv::resize(src, imgTmp, cSize);
//
// Mat foregroundImg = getForeImage(imgTmp, backgroundImg);// 0421
//
// using namespace luffy_base; //nThres = 90;
// luffy_threshold::Threshold(foregroundImg, imgBinary, nThres);//0421
//
// Mat dilatedImgBin;
// closeOper(imgBinary, 7);
// //dilate(imgBinary, dilatedImgBin, Mat::ones(7, 7, CV_32FC1));//
// //erode(dilatedImgBin, imgBinary, Mat::ones(7, 7, CV_32FC1));
// //openOper(imgBinary, Mat::ones(1, 13, CV_32FC1));//集智抠图问题修改 20190329
//
// vector<vector<Point>> conts;
// cv::findContours(imgBinary, conts, RETR_EXTERNAL, CHAIN_APPROX_NONE);
// imgBinary.setTo(0);
//
// /*
// for (int i = 0; i < conts.size(); i++) {
// const vector<Point> &pt = conts.at(i);
// if (pt.size() < 20) {
// continue;
// }
// Rect rt = boundingRect(pt);
// if (rt.width < 5 || rt.height < 5) {
// continue;
// }
// drawContours(imgBinary, conts, i, Scalar::all(255), -1);
// }
// */
//
////筛选最大轮廓的作为圆拟合区域
// int maxsize = 0;
// int nbestIndex = 0;
// for (int i = 0; i < conts.size(); i++)
// {
// if (conts.at(i).size()>maxsize)
// {
// maxsize = conts.at(i).size();
// nbestIndex = i;
// }
// }
// if (conts.size() > 0)
// {
// drawContours(imgBinary, vector<vector<Point>>(1,conts.at(nbestIndex)), -1, Scalar::all(255), -1);
// }
// //openOper(imgBinary, 17);//集智抠图问题修改 20190329
//
//
// Mat hit; vector<Point> pts;
// luffy_hit::firstHit4Circle(imgBinary, hit, pts, Point(cSize.width / 2, cSize.height / 2), 0, cSize.width/ 2, 360, luffy_hit::emHitOut2In);
//
// //luffy_imageProc::RansacParam rs(0.02, 2.5, 70, 100, 220);
// //luffy_imageProc::RansacParam rs(0.01, 2, 150, 150, 240);//20190117
//
// int nMinFitNum = 150;
//
// if (pts.size() < nMinFitNum)//解决检测目标在图像边缘导致的抠图识别问题
// {
// if (conts.size()>0)
// pts = conts.at(nbestIndex);
// }
//
// luffy_imageProc::RansacParam rs(0.01, 2, 150, nMinFitNum, 240);
// vector<Point> pts2 = luffy_imageProc::fitModelbyRansac(pts, luffy_imageProc::emModelCircle, &rs);
//#ifdef _DEBUG
// Mat imgColor;
// cv::cvtColor(imgTmp, imgColor, CV_GRAY2BGR);
// for (int i = 0; i < pts.size(); i++) {
// imgColor.at<cv::Vec3b>(pts.at(i))[0] = 255;//B
// imgColor.at< cv::Vec3b >(pts.at(i))[1] = 0;//G
// imgColor.at< cv::Vec3b >(pts.at(i))[2] = 0;//R
// }
// for (int i = 0; i < pts2.size(); i++) {
// imgColor.at<cv::Vec3b>(pts2.at(i))[0] = 0;//B
// imgColor.at< cv::Vec3b >(pts2.at(i))[1] = 0;//G
// imgColor.at< cv::Vec3b >(pts2.at(i))[2] = 255;//R
// }
//#endif
//
// float fRadius;
// Point2f ptCenter;
// bool bFind = luffy_imageProc::lsCircleFit(pts2, fRadius, ptCenter);
//
// if (!bFind) {
// return Mat();
// }
// Mat dst;
// const int nOffset = 1;
// fRadius += nOffset;
// Rect rt(ptCenter.x - fRadius + nOffset, ptCenter.y - fRadius + nOffset, 2 * fRadius, 2 * fRadius);
// rt &= Rect(0, 0, imgTmp.cols, imgTmp.rows);
// imgTmp(rt).copyTo(dst);
// static int nCount = cv::getTickCount();
// if (pCircle) {
// float fScale = src.cols / ALG_RESIZE_IMAGE_WIDTH;
// Mat matBig = src - backgroundImg;
// pCircle->fRadius = fRadius * fScale;
// pCircle->ptCenter = Point(ptCenter.x * fScale, ptCenter.y * fScale);
//
// Mat matBinary;
// luffy_threshold::Threshold(matBig, matBinary, nThres);
// Mat hit; vector<Point> pts;
// luffy_hit::firstHit4Circle(matBinary, hit, pts, pCircle->ptCenter, 0, pCircle->fRadius + 10, 360, luffy_hit::emHitOut2In);//luffy_hit::emHitOut2In
// luffy_imageProc::RansacParam rs(0.01, 2.5, 200, 150, 220);
// vector<Point> pts2 = luffy_imageProc::fitModelbyRansac(pts, luffy_imageProc::emModelCircle, &rs);
// float fRadius2;
// Point2f ptCenter2;
// bool bFind = luffy_imageProc::lsCircleFit(pts2, fRadius2, ptCenter2);
// if (bFind) {
// pCircle->fRadius = fRadius2;
// pCircle->ptCenter = ptCenter2;
// Rect rt(ptCenter2.x - fRadius2 + nOffset, ptCenter2.y - fRadius2 + nOffset, 2 * fRadius2, 2 * fRadius2);
//
// if (rt.x < 0 || rt.y < 0 || rt.x + rt.width > matBinary.cols || rt.y + rt.height > matBinary.rows ) {
// return Mat();
// }
// rt &= Rect(0, 0, matBinary.cols, matBinary.rows);
// src(rt).copyTo(dst);
// int nWidth = ((int)((double)dst.cols / fScale / 4)) * 4;
// cv::resize(dst, dst, cv::Size(nWidth, nWidth));
// }
// }
//
//return dst;
#endif
}
cv::Mat ImageProcess::getForeImage(const Mat & src, const Mat &backgroundImg)
{
@ -572,6 +55,7 @@ cv::Mat ImageProcess::getForeImage(const Mat & src, const Mat &backgroundImg)
}
return (src - resizedBackgroundImg);
}
//输入一张灰度图,输出抠出的圆小图和半径,圆心坐标
cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center ,double &radius, bool bEqual,int filterSize)
{
@ -687,3 +171,49 @@ Mat ImageProcess::DetectCircle(Mat img, Point2f& center, double& radius, bool bE
radius = r;
return s;
}
//使用背景图做减法扣圆
cv::Mat ImageProcess::findCircleByBackground(const Mat &src, const Mat& backgroundImg, luffy_base::luffyCircle *pCircle /*= NULL*/)
{
if (src.empty() || backgroundImg.empty() || src.rows < 500) {
return Mat();
}
assert(backgroundImg.type() == CV_8UC1);
Mat imgTmp = src;
Mat foregroundImg = getForeImage(imgTmp, backgroundImg);
CircleDetector cd;
cd.setAlgoType(CircleDetector::PeakCircle);
cd.setEdgeWidth(6);
cd.setPolarity(Polarity::White2Black);
cd.setFindBy(FindBy::Best);
double difRadiusMin = 0;
double difRadiusMax = (foregroundImg.cols > foregroundImg.rows ? foregroundImg.rows / 2 : foregroundImg.cols / 2) - 50;
cd.setRadii(difRadiusMin, difRadiusMax);
cd.setACThres(3);
vector<float> allScores;
Vec3f bestCircle;
float bestScore = cd.detectBest(foregroundImg, Point2f(imgTmp.cols / 2, imgTmp.rows / 2), bestCircle, &allScores);
if (abs(bestScore) <= FLT_EPSILON || bestCircle == Vec3f::zeros()) {
return Mat();
}
Point2f cen(bestCircle[0], bestCircle[1]);
double r = bestCircle[2];
Rect rect;
rect.x = cen.x - r;
rect.y = cen.y - r;
if (rect.x < 0)
rect.x = 0;
if (rect.y < 0)
rect.y = 0;
rect.width = 2 * r;
rect.height = 2 * r;
Mat rltMat = src(rect);
if (pCircle)
{
pCircle->fRadius = r;
pCircle->ptCenter = cen;
}
return rltMat;
}

@ -21,12 +21,12 @@ public:
ImageProcess();
~ImageProcess();
static cv::Mat findCircleObject(const Mat &src, const Mat& backgroundImg, bool useBackgroundFlag, int nThres = 20, luffy_base::luffyCircle *pCircle = NULL);
static cv::Mat getForeImage(const Mat & src, const Mat &backgroundImg);
//找圆
static cv::Mat findCircle(const Mat &srcImg, Point2f& center, double &radius, bool bEqual = true, int filterSize = 50 );
//精细找圆
static cv::Mat DetectCircle(Mat img, Point2f& center, double& radius, bool bEqual);
static cv::Mat findCircleByBackground(const Mat &src, const Mat& backgroundImg, luffy_base::luffyCircle *pCircle /*= NULL*/);
};
#endif

@ -41,6 +41,9 @@
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<column>
<property name="text">
<string>编号</string>

@ -40,14 +40,22 @@
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<property name="text">
<string>保存</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/img/resource/save.png</normaloff>:/img/resource/save.png</iconset>
<iconset resource="image.qrc">
<normaloff>:/resource/save.png</normaloff>:/resource/save.png</iconset>
</property>
<property name="iconSize">
<size>
@ -55,6 +63,12 @@
<height>20</height>
</size>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
@ -109,6 +123,9 @@
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<column>
<property name="text">
<string>解决方案资源管理</string>
@ -195,6 +212,9 @@
<height>200</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
@ -217,6 +237,9 @@
<height>200</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
@ -257,7 +280,11 @@
<number>5</number>
</property>
<item row="0" column="0">
<widget class="QTextEdit" name="textEdit"/>
<widget class="QTextEdit" name="textEdit">
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_6">
@ -360,6 +387,9 @@
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<column>
<property name="text">
<string>编号</string>
@ -416,6 +446,9 @@
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<column>
<property name="text">
<string>编号</string>

@ -9,7 +9,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>816</width>
<width>828</width>
<height>590</height>
</rect>
</property>
@ -119,9 +119,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
@ -205,6 +211,9 @@
</item>
<item>
<widget class="QGraphicsView" name="graphicsView">
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<property name="transformationAnchor">
<enum>QGraphicsView::AnchorUnderMouse</enum>
</property>

@ -103,6 +103,8 @@ void CDetectorEngine::detectFunc(cv::Mat srcImg, QString modeName, AlgResultCall
if (pTask)
{
pTask->GetTaskInfo()->detectImg = srcImg;
if (!pTask->GetTaskInfo()->templateImg.empty())
{
IDetectorAlgorithm* pAlgo = pTask->GetRunAlgo();
if (pAlgo) {
pAlgo->Exec();
@ -118,12 +120,17 @@ void CDetectorEngine::detectFunc(cv::Mat srcImg, QString modeName, AlgResultCall
}
}
rltMap.insert("AlgoResult", map);
}
rltMap.insert("taskCali", true);//模板已标定
}
else {
rltMap.insert("taskCali", false);//模板未标定
}
rltMap.insert("taskName", pTask->GetTaskName());
rltMap.insert("taskID", pTask->GetID());
rltMap.insert("originImage", EngineBase::convMat2QImage(srcImg));
}
}
}
int nTime = mTime.elapsed();
rltMap.insert("tasktime", nTime*1.0 / 1000);

@ -28,7 +28,6 @@ void TempImage::init(const QString& strbase, const QString &str)
QFileInfo info = fileList[j];
QString strPath = info.absoluteFilePath();
QString strName = info.baseName();
//cv::Mat src = cv::imread((strPath).toLatin1().data(), 0);
cv::Mat src = cv::imread(std::string((const char*)strPath.toLocal8Bit()), 0);
add(src, strName, strPath);
}
@ -88,14 +87,6 @@ std::vector<TempImageInfo*> TempImage::getVectors()
void TempImage::remove(const QString& strKey)
{
// for (int i = 0; i < m_imgTemplateLib.size(); i++) {
// if (m_imgTemplateLib.at(i)->m_strFileName == strKey) {
// hubBase::removeFile(m_imgTemplateLib.at(i)->m_strAbsoluteFilePath);
// TempImageInfo * pTemp = m_imgTemplateLib.at(i);
// m_imgTemplateLib.erase(pTemp);
// break;
// }
// }
for (std::vector<TempImageInfo*>::iterator its = m_imgTemplateLib.begin(); its != m_imgTemplateLib.end(); ++its){
if ((*its)->m_strFileName == strKey){
TempImageInfo* pTemp = (*its);

@ -8,6 +8,7 @@ enum TEM_MODEL{
emTypeModelWarning,
emTypeModelError
};
WheelModel::WheelModel()
{
m_strModelID = QString();
@ -23,7 +24,6 @@ WheelModel::WheelModel()
m_pTempImage = new TempImage;
}
WheelModel::~WheelModel()
{
if (m_pDetectModel) {
@ -69,10 +69,10 @@ bool WheelModel::initComModel(const QString&strBase)
}
QString str = strBase + "template\\" + m_strModelID + "\\model.yml";
std::string strs = str.toLocal8Bit().toStdString();
bool bFlags = m_pDetectModel->readFromFile(strs/*str.toLatin1().data()*/);
bool bFlags = m_pDetectModel->readFromFile(strs);
if (!bFlags) {
m_pDetectModel->train(m_pTempImage->getImgVector());
bFlags = m_pDetectModel->save2file(strs/*string((const char *)str.toLocal8Bit())*/);
bFlags = m_pDetectModel->save2file(strs);
}
return bFlags;
}
@ -154,15 +154,10 @@ void WheelModel::setRepeatNum(int nValue)
int WheelModel::getRepeatNum() const
{
return m_pDetectModel->getRepeatNum();
//return m_nRotate;
}
ICompareModel * WheelModel::getImageComModel() const
{
// if (!m_pDetectModel)
// {
// m_pDetectModel = new ImageCompareModel;
// }
return m_pDetectModel;
}

@ -110,6 +110,9 @@
<pointsize>12</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
</widget>
</item>
<item row="1" column="0">
@ -118,7 +121,7 @@
<widget class="QPushButton" name="workmgr_Add">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="toolTip">
@ -133,7 +136,7 @@
<widget class="QPushButton" name="workmgr_Del">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="toolTip">
@ -148,7 +151,7 @@
<widget class="QPushButton" name="workmgr_Mod">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="toolTip">
@ -163,7 +166,7 @@
<widget class="QPushButton" name="work_Edit_pb">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="toolTip">
@ -233,6 +236,9 @@
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
</widget>
</item>
<item row="2" column="0">
@ -284,6 +290,7 @@
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
@ -318,6 +325,7 @@
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
@ -437,6 +445,11 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
</widget>
</item>
<item row="0" column="0">
@ -463,6 +476,9 @@
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">

@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.1585
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AlgoTest", "AlgoTest\AlgoTest.vcxproj", "{9432FDF3-AEA1-4095-BD7B-63EC9C79EA89}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ModelTest", "ModelTest\ModelTest.vcxproj", "{B12702AD-ABFB-343A-A199-8E24837244A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -15,6 +17,10 @@ Global
{9432FDF3-AEA1-4095-BD7B-63EC9C79EA89}.Debug|x64.Build.0 = Debug|x64
{9432FDF3-AEA1-4095-BD7B-63EC9C79EA89}.Release|x64.ActiveCfg = Release|x64
{9432FDF3-AEA1-4095-BD7B-63EC9C79EA89}.Release|x64.Build.0 = Release|x64
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.ActiveCfg = Debug|x64
{B12702AD-ABFB-343A-A199-8E24837244A3}.Debug|x64.Build.0 = Debug|x64
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.ActiveCfg = Release|x64
{B12702AD-ABFB-343A-A199-8E24837244A3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -96,6 +96,7 @@ Mat findEdge2(const Mat &Src)
QAlgDetect::QAlgDetect(QObject *parent)
: QObject(parent)
{
}
QAlgDetect::~QAlgDetect()
@ -232,3 +233,6 @@ Mat QAlgDetect::DetectCircle(Mat img, QPointF center, double radius,bool bEqual)
Mat s = img(rect);
return s;
}

@ -6,7 +6,9 @@
#include <QImage>
#include <QVariantMap>
using namespace cv;
typedef std::function<void(QImage)> AlgCallBack;
class QAlgDetect : public QObject
{
@ -18,7 +20,7 @@ public:
void detect(QImage img, QVariantMap param, AlgCallBack func);
Mat DetectCircle(Mat img, QPointF center, double radius, bool bEqual);
private:
};
#endif

@ -69,7 +69,7 @@ QModelMgrDlg::QModelMgrDlg(IWheelCtrl *ptr, QWidget *parent)
m_pModelLists = new ModelsView(ui.ModelMgr_Models_tableView, m_pModelMgr->getAllModelMapPtr());
m_pModelLists->setHideItems(QStringList() << "NG");
connect(m_pModelLists, SIGNAL(sgSelectModel(QString)), this, SLOT(onShowModelInfo(QString)));
//connect(m_pModelLists, SIGNAL(sgSelectModel(QString)), this, SLOT(onShowModelPic(QString)));
connect(m_pModelLists, SIGNAL(sgSelectModel(QString)), this, SLOT(onShowModelPic(QString)));
connect(this, SIGNAL(sgTrainShowInfo(QString)), this, SLOT(onShowModelInfo(QString)));
connect(m_pShowImgList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(onItemDoubleClicked(QListWidgetItem*)));
@ -213,13 +213,12 @@ Q_SLOT void QModelMgrDlg::onModifyModel()
int pthrevalue = ui.ModelMgr_horizontalSlider->value();
double value = (falsMinDis - disMax) / 100.0*pthrevalue;
pModel->getImageComModel()->setDisThre(value + disMax);
//if (m_RepetBox)
pModel->setRepeatNum(ui.ModelMgr_model_Repet_spinBox->value());
QString templatepath = m_pCtrl->appRoot() + "\\pattern\\template\\";
templatepath += strModel;
templatepath += "\\model.yml";
std::string strS = templatepath.toLocal8Bit().toStdString();
pModel->getImageComModel()->save2file(strS/*string((const char *)templatepath.toLocal8Bit())*/);
pModel->getImageComModel()->save2file(strS);
m_pModelMgr->modModel(strModel);
m_pModelMgr->saveModel(strModel);
QString str = m_pCtrl->getUserName() + ":" + QString("%1:%2 %3").arg(tr("修改了模板")).arg(strModel).arg(tr("的参数"));
@ -351,11 +350,7 @@ Q_SLOT void QModelMgrDlg::onItemDoubleClicked(QListWidgetItem * item)
{
QObject *obj = sender();
QString objName = obj->objectName();
//if ("ModelMgr_showPic_listWidget_tab1" == objName)
{
// if (m_pCtrl->getDetectState()->m_Debug != 100)
// if (m_pCtrl->getUserLevel() <= 0)
// return;
QString strModel = m_pShowImgList->property("model").toString();
QString itemText = item->text();
QString strWarning = tr("确定删除该图像?");
@ -369,10 +364,6 @@ Q_SLOT void QModelMgrDlg::onItemDoubleClicked(QListWidgetItem * item)
QString m_str = QString("%1 %2 %3").arg(tr("")).arg(m_pShowImgList->count()).arg(tr("个图像"));
ui.label_imgNum->setText(m_str);
}
// else if ("ModelMgr_listWidget_tab2" == objName)
// {
// int a = 0;
// }
}
Q_SLOT void QModelMgrDlg::onPrograssShow(QString title, QString strValue, int size, int model)
@ -503,7 +494,6 @@ Q_SLOT void QModelMgrDlg::onTextChanged(const QString& str)
m_pModelLists->setModelList(models);
QString m_str = QString("%1 %2 %3").arg(tr("")).arg(models.size()).arg(tr("个型号"));
ui.ModelMgr_label_Model_number->setText(m_str);
//m_FindModel = models;
}
else {
QStringList strFilter = models.filter(str);
@ -553,19 +543,6 @@ Q_SLOT void QModelMgrDlg::onShowModelInfo(QString str)
if (IImgNum > 0 && IImgNum < nGlobalMinImgs)
strShow += QString(",%1 %2 %3.").arg(tr("图像数量少于")).arg(nGlobalMinImgs).arg(tr("个,请及时补充训练样本"));
ui.label_imgNum->setText(strShow);
/* if (m_WarningMsg)
{
int nTypeModel = m_pModelMgr->getModel(str)->getImageModel();
if (nTypeModel == 0)
m_WarningMsg->setText(tr("该模板训练成功,可以正常使用"));
else if (nTypeModel == 1)
m_WarningMsg->setText(tr("该模板没有训练,并且没有图像"));
else if (nTypeModel == 2)
m_WarningMsg->setText(tr("该模板训练失败,请检查模板图片中是否有其他类型的图像或该模板是否被重复添加"));
else
m_WarningMsg->setText(QString("。。。。。。"));
}*/
}
Q_SLOT void QModelMgrDlg::onShowModelPic(QString str)
@ -663,8 +640,6 @@ void QModelMgrDlg::TrainAllTskFunc()
{
names.push_back(QString::fromStdString(vec[j].first));
}
//vector<Mat> falseSamples = m_pModelMgr->getAllModelImageExcSelf(pModel->getModelID());
std::vector<modelInfo> m_modelInfo = m_pModelMgr->getAllTarImgs(names);
vector<Mat> falseSamples;
for (int k = 0; k < m_modelInfo.size(); k++)
@ -695,20 +670,8 @@ void QModelMgrDlg::TrainAllTskFunc()
m_compareModel->setIsEnableCache(true);
if (m_trainAllTsk->getStopFlag())
break;
/*if (pModel->getDiameter() && pModel->getThickness())
{
m_compareModel->setRealWidth(pModel->getDiameter());
m_compareModel->setRealHeight(pModel->getThickness());
}*/
//for (int h = 0; h < m_modelInfo.size(); h++)
//{
//const vector<Mat>& vectorMats = m_modelInfo[h].mpAllImage;
/*double md_diameter = m_modelInfo[h].md_diameter;
double md_height = m_modelInfo[h].md_height;*/
m_compareModel->computeDisThre(falseSamples, NULL);
//}
if (m_trainAllTsk->getStopFlag())
break;
double m_double = m_compareModel->getDisThre();
@ -768,7 +731,6 @@ void QModelMgrDlg::TrainOneTskFunc()
emit sgPrograssShow(tr("模板训练进度"), str, 1, emPross_SetValue);
ICompareModel *m_compareModel = pModel->getImageComModel();
//std::vector<cv::Mat> firstFalseSample = m_pModelMgr->getFirstImgFromFalse(pModel->getModelID());
m_compareModel->train(m_MatVec); //////////////////////////////////////////// tain model
QMap<QString, Mat> imgVec = m_pModelMgr->getAllImgsExcSelf(pModel->getModelID());
@ -789,16 +751,6 @@ void QModelMgrDlg::TrainOneTskFunc()
}
if (m_trainOneTsk->getStopFlag())
return;
// vector<pair<string, double> > vec(disMap.begin(), disMap.end());
// std::sort(vec.begin(), vec.end(), CmpByValue());
// disMap.clear();
// for (int j = 0; j < ceil(vec.size() / 2.0); j++)
// {
// names.push_back(QString::fromStdString(vec[j].first));
// }
// if (m_trainOneTsk->getStopFlag())
// return;
//vector<Mat> falseSamples = m_pModelMgr->getAllModelImageExcSelf(pModel->getModelID());
std::vector<modelInfo> m_modelInfo = m_pModelMgr->getAllTarImgs(names);
vector<Mat> falseSamples;
for (int k = 0; k < m_modelInfo.size(); k++)
@ -820,12 +772,11 @@ void QModelMgrDlg::TrainOneTskFunc()
templatepath += "\\model.yml";
m_compareModel->setName(m_strTrainModel.toLatin1().data());
std::string strS = templatepath.toLocal8Bit().toStdString();
m_compareModel->save2file(strS/*string((const char *)templatepath.toLocal8Bit())*/);//////////////////////////////save params
m_compareModel->save2file(strS);//////////////////////////////save params
if (pModel->getPicPath().isEmpty())
{
QString modelName = pModel->getModelID();
QString strSavePath = m_pCtrl->appRoot();
//hubBase::mkdir(strSavePath);
QString n_Pic_path = "\\pattern\\Models\\" + modelName + ".jpg";
QString filepath = strSavePath + n_Pic_path;
imwrite(string((const char *)filepath.toLocal8Bit()), m_MatVec.at(0));
@ -839,20 +790,9 @@ void QModelMgrDlg::TrainOneTskFunc()
emit sgPrograssShow(tr("模板训练进度"), tr("%1的模板 正在获取特征值,请稍后....").arg(m_strTrainModel), 4, emPross_SetLable);
m_compareModel->setIsEnableCache(false);
//if (pModel->getDiameter() && pModel->getThickness())
//{
// m_compareModel->setRealWidth(pModel->getDiameter());
// m_compareModel->setRealHeight(pModel->getThickness());
//}
//for (int h = 0; h < m_modelInfo.size(); h++)
//{
//const vector<Mat>& vectorMats = m_modelInfo[h].mpAllImage;
/*double md_diameter = m_modelInfo[h].md_diameter;
double md_height = m_modelInfo[h].md_height;*/
m_compareModel->computeDisThre(falseSamples, NULL);
//}
strS = templatepath.toLocal8Bit().toStdString();
m_compareModel->save2file(strS/*string((const char *)templatepath.toLocal8Bit())*/);
m_compareModel->save2file(strS);
if (m_trainOneTsk->getStopFlag())
return;
emit sgPrograssShow(tr("模板训练进度"), str, 6, emPross_SetValue);
@ -937,7 +877,6 @@ bool QModelMgrDlg::appImage2Widget(QString strPath, QString strModel)
strPath2 += strModel + "\\" + strFileName + ".png";
cv::imwrite(string((const char *)strPath2.toLocal8Bit()), dst);
//cv::imwrite(strPath2.toLatin1().data(), dst);
pModel->getTempImage()->add(dst, strFileName, strPath2);
QString m_str = QString("%1 %2 %3").arg(tr("")).arg(m_pShowImgList->count()).arg(tr("个图像"));
ui.label_imgNum->setText(m_str);

@ -94,6 +94,9 @@
<height>16777215</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<property name="wheel_prop_tableview_header" stdset="0">
<stringlist>
<string>modelID</string>
@ -125,7 +128,11 @@
</widget>
</item>
<item row="0" column="0">
<widget class="QListWidget" name="listWidget"/>
<widget class="QListWidget" name="listWidget">
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
</widget>
</item>
<item row="0" column="1" rowspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
@ -213,6 +220,9 @@
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="title">
<string>轮毂信息:</string>
</property>
@ -226,7 +236,7 @@
<widget class="QLabel" name="ModelMgr_label_4">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
@ -241,7 +251,7 @@
<widget class="QSpinBox" name="ModelMgr_model_Repet_spinBox">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
</widget>
@ -250,7 +260,7 @@
<widget class="QLabel" name="ModelMgr_label_5">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
@ -271,7 +281,7 @@
</property>
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
@ -304,7 +314,7 @@
<widget class="QLabel" name="label_3">
<property name="font">
<font>
<pointsize>11</pointsize>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
@ -344,6 +354,11 @@
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>加入训练</string>
</property>
@ -412,6 +427,11 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="ModelMgr_label_12">
<property name="font">
<font>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>阈值调节</string>
</property>

@ -256,7 +256,7 @@ lpMainWin::lpMainWin(QWidget *parent)
RecvFunc func = std::bind(&lpMainWin::onWebSocketRecvData, this, std::placeholders::_1, std::placeholders::_2);
m_pWebSocket->openServer(port, func);
}
connect(this, SIGNAL(sgShowDetectLog(QString)), this, SLOT(onShowDetectLog(QString)));
setWindowTitleInfo();
}
@ -757,10 +757,30 @@ QVariant lpMainWin::IGetVariantById(int id)
void lpMainWin::IEngineResult(QVariantMap vMap)
{
bool taskCali = vMap.value("taskCali").toBool();
if (taskCali == false)//模板未标定
{
ui.main_value_Result->setText("该型号未标定");
ui.main_value_Result->setStyleSheet("background-color: rgb(255, 212, 83);");
ui.main_label_angle->setText("-");
ui.main_value_Center_point->setText("-");
ui.main_value_DetectTime->setText("-");
ui.main_value_Score->setText("-");
//获取图像 保存到当天NG图
ValueResult valueRlt;
valueRlt.angle = 361;
valueRlt.strModel = "NG";
valueRlt.score = 0;
valueRlt.strRunState = "no Cali";
onSaveValveResult(valueRlt);
return;
}
//不包含算法检测结果表示没有相关task
if (!vMap.contains("AlgoResult"))
{
ui.main_value_Result->setText("没有找到相关task");
ui.main_value_Result->setStyleSheet("background-color: rgb(255, 212, 83);");
ui.main_label_angle->setText("-");
ui.main_value_Center_point->setText("-");
ui.main_value_DetectTime->setText("-");
@ -784,7 +804,6 @@ void lpMainWin::IEngineResult(QVariantMap vMap)
QImage maskImg = algResult.value("image").value<QImage>();
QString str = algResult.value("resultTip").toString();
QPointF centerPoint = algResult.value("centerPoint").toPointF();
//QString rltmsg = QString("%1 %2 %3").arg(dAngle).arg(errorType).arg(matchScore);
QString taskName = vMap.value("taskName").toString();
double taskTime = vMap.value("tasktime").toDouble();
ui.main_label_angle->setText(QString("%1°").arg(dAngle));
@ -807,12 +826,14 @@ void lpMainWin::IEngineResult(QVariantMap vMap)
if (dAngle >= 361)//NG
{
ui.main_value_Result->setStyleSheet("background-color: rgb(250, 0, 0);");
ui.main_value_Result->setText("找不到气门芯");
ui.main_value_Center_point->setText("-");
ui.main_value_Score->setText(QString("%1").arg(matchScore));
valueRlt.strModel = "NG";
}
else {//OK
ui.main_value_Result->setStyleSheet("background-color: rgb(0, 250, 0);");
ui.main_value_Result->setText("定位成功");
ui.main_value_Center_point->setText(QString("(%1,%2)").arg(centerPoint.x()).arg(centerPoint.y()));
ui.main_value_Score->setText(QString("%1").arg(matchScore));
@ -1262,6 +1283,7 @@ Q_SLOT void lpMainWin::onGetImg()
{
ui.main_lb_res_model_pic->setStyleSheet(QString("QLabel{border: 1px solid rgb(0,0,0,250);background-color: rgb(200, 200, 200);}"));
ui.main_value_Result->setText("获取到图像");
ui.main_value_Result->setStyleSheet("");
ui.main_label_angle->setText("-");
ui.main_value_DetectTime->setText("-");
ui.main_lb_res_model_time->setText("-");
@ -1631,6 +1653,9 @@ void lpMainWin::onSaveValveResult(ValueResult &rlt)
m_pPlcDevice->onSendValueRlt(rlt);
}
sendWebAlgRlt(rlt);
QString strMsg = QString("%1 识别结果:%2 定位角度:%3").arg(QDateTime::currentDateTime().toString("hh:mm:ss")).arg(rlt.strModel).arg(rlt.angle);
emit sgShowDetectLog(strMsg);
}
void lpMainWin::saveValveImage(QImage image, QString strName)
@ -1818,3 +1843,10 @@ Q_SLOT void lpMainWin::setWindowTitleInfo()
}
}
Q_SLOT void lpMainWin::onShowDetectLog(QString strMsg)
{
int size = ui.main_textBrowser->toPlainText().size();
if (size > 100000)
ui.main_textBrowser->clear();
ui.main_textBrowser->append(strMsg);
}

@ -71,6 +71,7 @@ signals:
void operate();
void sgNetData(int, QVariantMap);
void sgAutoExposure();
void sgShowDetectLog(QString strLog);
private:
Q_SLOT void onLogInOut(QString strName, int level, int state);
Q_SLOT void onActionClicked();
@ -118,6 +119,7 @@ protected:
QByteArray Json2byte(QJsonObject obj);
Q_SLOT void setWindowTitleInfo();
Q_SLOT void onShowDetectLog(QString strMsg);
private://trayIcon
void setupTrayIcon();
Q_SLOT void onActivated(QSystemTrayIcon::ActivationReason reason);

@ -155,7 +155,7 @@
</font>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@ -185,32 +185,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>检测日志</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<item row="0" column="0">
<widget class="QTextEdit" name="textEdit">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
@ -546,8 +523,14 @@ font: 75 24pt &quot;Consolas&quot;;</string>
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(197, 197, 197);
</string>
</property>
<property name="text">
<string>定位结果</string>
</property>
@ -731,6 +714,9 @@ font: 75 24pt &quot;Consolas&quot;;</string>
<pointsize>11</pointsize>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(212, 212, 212);</string>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>

Loading…
Cancel
Save