改良抠图算法,增加filtersize在抠图中的使用

jizhi
bob.pan 5 years ago
parent dfdb90d173
commit e4b21ea643

@ -1876,7 +1876,7 @@ void ImageCompareModelInvoker::operator()(const cv::Range& range) const
{
int i0 = range.start;
int i1 = range.end;
assert(abs(i1 - i0) == 1);
// assert(abs(i1 - i0) == 1);
//if (abs(i1 - i0) == 1)
// return;
m_pModel->parallelDetect(i0, m_pData);

@ -85,6 +85,7 @@ int CAlgorithmFluorescence::IImageAnalysis(class IImageObject* pImgObj, TP_ALGOR
cParam.CirclePolarity = vMap.value("Circle_Polarity",0).toInt();
cParam.CircleACThres = vMap.value("Circle_ACThres",3).toInt();
cParam.CircleEdgeWidth = vMap.value("Circle_EdgeWidth",3).toInt();
cParam.filterSize = filterSize;
if (nthreshold <= 0)
nthreshold = 15;

@ -71,6 +71,8 @@ cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center, double &rad
vector<mCircle> EDCircle = edcircles.getCircles();
double maxR = 0;
int nIndex = -1;
float centerX = 0;
float centerY = 0;
for (int i = 0; i < EDCircle.size(); i++)
{
int startX = EDCircle[i].center.x - EDCircle[i].r;
@ -86,23 +88,20 @@ cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center, double &rad
{
maxR = EDCircle[i].r;
nIndex = i;
centerX = EDCircle[i].center.x * REAIZE;
centerY = EDCircle[i].center.y * REAIZE;
}
}
if (nIndex != -1)
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;
radius = EDCircle[nIndex].r;
int hight = 2 * radius * REAIZE;
radius = EDCircle[nIndex].r * REAIZE;
center.x = (EDCircle[nIndex].center.x * REAIZE);
center.y = (EDCircle[nIndex].center.y * REAIZE);
radius = radius * REAIZE;
return DetectCircle(srcImg, Mat(), center, radius, bEqual, cParam);
}
else {
center.x = srcImg.cols/2;
center.y = srcImg.rows/2;
center.x = centerX;
center.y = centerY;
radius = 0;
return DetectCircle(srcImg, Mat(), center, radius, bEqual, cParam);
}
@ -111,20 +110,17 @@ cv::Mat ImageProcess::findCircle(const Mat &srcImg, Point2f& center, double &rad
Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, double& radius, bool bEqual, const CircleParam& cParam)
{
Mat img;
if (!background.empty())
{
if (!background.empty()) {
img = getForeImage(srcImg, background);
}
else {
img = srcImg;
}
Mat detectImg;
if (bEqual == true)
{
if (bEqual == true) {
equalizeHist(img, detectImg);
}
else
{
else {
detectImg = img;
}
@ -137,13 +133,31 @@ Mat ImageProcess::DetectCircle(Mat srcImg, Mat background, Point2f& center, doub
cd.setPolarity(Polarity::White2Black);
cd.setFindBy(FindBy::Best);
double difRadiusMin = radius - 100;
double difRadiusMax = radius + 100;
if (difRadiusMin < 0)
{
if (center.x == 0 || center.y == 0)
{
center.x = img.cols / 2;
center.y = img.rows / 2;
}
int rY = img.rows - center.y;
int rX = img.cols - center.x;
int min_dify = center.y > rY ? rY : center.y;
int min_difx = center.x > rX ? rX : center.x;
int maxRadius = abs(abs(min_difx > min_dify ? min_dify : min_difx)-50);
double difRadiusMin = radius - 150;
double difRadiusMax = radius + 250;
if (difRadiusMin <= 0)
{
difRadiusMin = cParam.filterSize;
difRadiusMax = maxRadius;
}
//控制范围,不让检测越界
//if (difRadiusMin < cParam.filterSize)
difRadiusMin = cParam.filterSize;
//if (difRadiusMax > maxRadius)
difRadiusMax = maxRadius;
if (difRadiusMin > difRadiusMax)
difRadiusMin = 0;
difRadiusMax = abs(abs(center.y - (img.cols / 2)) - 50);
}
cd.setRadii(difRadiusMin, difRadiusMax);
cd.setACThres(cParam.CircleACThres);
@ -191,6 +205,8 @@ cv::Mat ImageProcess::findCircleByBackground(const Mat &srcImg, const Mat& backg
vector<mCircle> EDCircle = edcircles.getCircles();
double maxR = 0;
int nIndex = -1;
float centerX = 0;
float centerY = 0;
for (int i = 0; i < EDCircle.size(); i++)
{
int startX = EDCircle[i].center.x - EDCircle[i].r;
@ -206,23 +222,20 @@ cv::Mat ImageProcess::findCircleByBackground(const Mat &srcImg, const Mat& backg
{
maxR = EDCircle[i].r;
nIndex = i;
centerX = EDCircle[i].center.x * REAIZE;
centerY = EDCircle[i].center.y * REAIZE;
}
}
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;
radius = EDCircle[nIndex].r;
int hight = 2 * radius * REAIZE;
radius = EDCircle[nIndex].r * REAIZE;
center.x = (EDCircle[nIndex].center.x * REAIZE);
center.y = (EDCircle[nIndex].center.y * REAIZE);
radius = radius * REAIZE;
return DetectCircle(srcImg, backgroundImg, center, radius, bEqual, cParam);
}
else {
center.x = srcImg.cols / 2;
center.y = srcImg.rows / 2;
center.x = centerX;
center.y = centerY;
radius = 0;
return DetectCircle(srcImg, backgroundImg, center, radius, bEqual, cParam);
}

@ -18,6 +18,7 @@ struct CircleParam {
int CirclePolarity{ 0 };
int CircleACThres{ 3 };
int CircleEdgeWidth{ 3 };
int filterSize{ 50 };
};
class ImageProcess
{

@ -74,7 +74,7 @@ lpCheckKey::~lpCheckKey()
//检查linese是否匹配
bool lpCheckKey::checkLinese()
{
std::string biosID = lpHardwareInfo::instance()->getBiosID();
std::string biosID = lpHardwareInfo::instance()->getHardDrive();
m_SerialNo = lpCryptokey::genSerialNumber(QString(biosID.c_str()));
QSettings settingKey("Leaper_Register");
QString strKey = settingKey.value("key").toString();

@ -152,6 +152,9 @@
<property name="buttonSymbols">
<enum>QAbstractSpinBox::NoButtons</enum>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item>

@ -23,9 +23,9 @@
#include <QProcess>
#include "lpCryptokey.h"
#define VERSION_HUB "3.0.1.3"
#define VERSION_ALG "3.0.1.3"
#define UPDATE_TIME "2021-09-23"
#define VERSION_HUB "3.0.1.4"
#define VERSION_ALG "3.0.1.4"
#define UPDATE_TIME "2021-09-26"
#pragma execution_character_set("utf-8")
lpMainWin::lpMainWin(QWidget *parent)

Loading…
Cancel
Save