|
|
|
|
@ -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,45 +88,39 @@ 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);
|
|
|
|
|
return DetectCircle(srcImg, Mat(), center, radius, bEqual, cParam);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,14 +133,32 @@ 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)
|
|
|
|
|
{
|
|
|
|
|
difRadiusMin = 0;
|
|
|
|
|
difRadiusMax = abs(abs(center.y - (img.cols / 2)) - 50);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
cd.setRadii(difRadiusMin, difRadiusMax);
|
|
|
|
|
cd.setACThres(cParam.CircleACThres);
|
|
|
|
|
vector<float> allScores;
|
|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|