Commit e1f406f7 张士柳

1 个父辈 96811a3b
...@@ -879,6 +879,78 @@ namespace eyemLib_Sharp ...@@ -879,6 +879,78 @@ namespace eyemLib_Sharp
#endregion #endregion
#region 二维几何计算
/// <summary>
/// 根据两个点计算直线
/// </summary>
/// <param name="tpPoint1">点一</param>
/// <param name="tpPoint2">点二</param>
/// <param name="tpLine">直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, ref EyemOcsDABC tpLine);
/// <summary>
/// 计算两直线交点
/// </summary>
/// <param name="tpLine1">线一</param>
/// <param name="tpLine2">线二</param>
/// <param name="taPoint">交点</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, ref EyemOcsDXY tpPoint);
/// <summary>
/// 计算两点的垂直平分线
/// </summary>
/// <param name="tpPoint1">点一</param>
/// <param name="tpPoint2">点二</param>
/// <param name="tpLine">线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, ref EyemOcsDABC tpLine);
/// <summary>
/// 过一点作已知直线的垂线
/// </summary>
/// <param name="tpPoint"></param>
/// <param name="tpLine"></param>
/// <param name="tpVertical"></param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, ref EyemOcsDABC tpVertical);
/// <summary>
/// 指定点和斜率计算直线
/// </summary>
/// <param name="tpPoint">点</param>
/// <param name="dSlope">斜率(角度)</param>
/// <param name="tpLine">直线</param>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, ref EyemOcsDABC tpLine);
/// <summary>
/// 计算两直线角度(锐角)
/// </summary>
/// <param name="tpLine1">直线一</param>
/// <param name="tpLine2">直线二</param>
/// <param name="dpAngle">角度</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, ref double dpAngle);
/// <summary>
/// 两条直线的角平分线
/// </summary>
/// <param name="tpLine1">直线一</param>
/// <param name="tpLine2">直线二</param>
/// <param name="tpLineC">直线</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemClp2dCenterLineOfTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, ref EyemOcsDABC tpLineC);
#endregion
#region 项目 #region 项目
//普通器件 //普通器件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
...@@ -1003,6 +1075,7 @@ namespace eyemLib_Sharp ...@@ -1003,6 +1075,7 @@ namespace eyemLib_Sharp
{ {
EyemImage image; EyemImage image;
EyemImage tpDstImg = new EyemImage(); EyemImage tpDstImg = new EyemImage();
EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//int flag = eyemImageReadRaw(fileName, 3072, 3072, 2, out ucpImage); //int flag = eyemImageReadRaw(fileName, 3072, 3072, 2, out ucpImage);
int flag = eyemImageRead(fileName, -1, out image); int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0) if (flag != 0)
...@@ -1029,9 +1102,9 @@ namespace eyemLib_Sharp ...@@ -1029,9 +1102,9 @@ namespace eyemLib_Sharp
//flag = eyemCvtColor(tpDstImg, ColorConversionCodes.COLOR_GRAY2BGR, ref tpDstImg); //flag = eyemCvtColor(tpDstImg, ColorConversionCodes.COLOR_GRAY2BGR, ref tpDstImg);
flag = eyemLibImpl(image, out tpDstImg); //flag = eyemLibImpl(image, out tpDstImg);
//EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//flag = eyemMarkerTracing(image, 130, ref tpCircle); //flag = eyemMarkerTracing(image, 130, ref tpCircle);
...@@ -1162,12 +1235,35 @@ namespace eyemLib_Sharp ...@@ -1162,12 +1235,35 @@ namespace eyemLib_Sharp
//EyemOcsDABC tpLine = new EyemOcsDABC(); //EyemOcsDABC tpLine = new EyemOcsDABC();
//IntPtr tpPoint = eyemStructArray2IntPtr(taPoints.ToArray()); //IntPtr tpPoint = eyemStructArray2IntPtr(taPoints.ToArray());
////eyemFitLine(taPoints.Count, tpPoint, 10, ref tpLine); //eyemFitLine(taPoints.Count, tpPoint, 10, ref tpLine);
////eyemRobustFitLine(taPoints.Count, tpPoint, 6, 0, ref tpLine); //eyemRobustFitLine(taPoints.Count, tpPoint, 6, 0, ref tpLine);
//EyemOcsDABC tpLine2 = new EyemOcsDABC();
//EyemOcsDXY tpPoint1 = new EyemOcsDXY();
//tpPoint1.dX = -2; tpPoint1.dY = 0;
//EyemOcsDXY tpPoint2 = new EyemOcsDXY();
//tpPoint2.dX = 2; tpPoint2.dY = 0;
//eyemClp2dLineTwoPoints(tpPoint1, tpPoint2, ref tpLine2);
//EyemOcsDXY taPointx = new EyemOcsDXY();
//taPointx.dX = 0; taPointx.dY = 0;
//EyemOcsDABC tpVertic = new EyemOcsDABC();
//eyemClp2dLinePointAndSlope(taPointx, 22.5, ref tpVertic);
//EyemOcsDABC tpVertic2 = new EyemOcsDABC();
//eyemClp2dLinePointAndSlope(taPointx, 45.0, ref tpVertic2);
//EyemOcsDABC tpVerticC = new EyemOcsDABC();
//eyemClp2dCenterLineOfTwoLines(tpVertic, tpVertic2, ref tpVerticC);
//EyemOcsDXY taPointy = new EyemOcsDXY();
//eyemClp2dIntersectionTwoLines(tpLine, tpVertic2, ref taPointy);
//k = -tpLine.dA / tpLine.dB;
//b = -tpLine.dC / tpLine.dB;
//Marshal.FreeHGlobal(tpPoint); //Marshal.FreeHGlobal(tpPoint);
return;
#endregion #endregion
#region Test WriteImage #region Test WriteImage
...@@ -1184,7 +1280,7 @@ namespace eyemLib_Sharp ...@@ -1184,7 +1280,7 @@ namespace eyemLib_Sharp
tpRoi.iWidth = image.iWidth; tpRoi.iWidth = image.iWidth;
tpRoi.iHeight = image.iHeight; tpRoi.iHeight = image.iHeight;
//flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg); flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg);
string pNumObj = ""; string pNumObj = "";
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2]; string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
......
...@@ -19,7 +19,7 @@ namespace eyemLib_Sharp ...@@ -19,7 +19,7 @@ namespace eyemLib_Sharp
//初始化 //初始化
EyemLib.Init(); EyemLib.Init();
string[] fileNames = Directory.GetFiles(@"D:\Temp", "*.*", SearchOption.AllDirectories); string[] fileNames = Directory.GetFiles(@"D:\批量测试图像", "*.*", SearchOption.AllDirectories);
//int iter = 0; //int iter = 0;
//for (int i = 0; i < 10000; i++) //for (int i = 0; i < 10000; i++)
......
...@@ -996,6 +996,23 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double ...@@ -996,6 +996,23 @@ int eyemBinThreshold(EyemImage tpSrcImg, int iLightDark, double dThresh, double
cv::Mat binary; cv::Mat binary;
//执行二值化操作 //执行二值化操作
cv::threshold(image, binary, dThresh, dMaxVal, iLightDark); cv::threshold(image, binary, dThresh, dMaxVal, iLightDark);
///<输出结果图像
{
tpDstImg->iWidth = binary.cols; tpDstImg->iHeight = binary.rows; tpDstImg->iDepth = binary.depth(); tpDstImg->iChannels = binary.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, binary.data, _Size);
}
return FUNC_OK; return FUNC_OK;
} }
...@@ -1008,7 +1025,6 @@ int eyemBinNiBlack(EyemImage tpSrcImg, EyemImage *tpDstImg, int iType, int iWinS ...@@ -1008,7 +1025,6 @@ int eyemBinNiBlack(EyemImage tpSrcImg, EyemImage *tpDstImg, int iType, int iWinS
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
//CV_Assert(src.channels() == 1);
CV_Assert(iWinSize % 2 == 1 && iWinSize > 1); CV_Assert(iWinSize % 2 == 1 && iWinSize > 1);
if (binMethod == BINARIZATION_SAUVOLA) { if (binMethod == BINARIZATION_SAUVOLA) {
CV_Assert(src.depth() == CV_8U); CV_Assert(src.depth() == CV_8U);
...@@ -1074,7 +1090,7 @@ int eyemBinNiBlack(EyemImage tpSrcImg, EyemImage *tpDstImg, int iType, int iWinS ...@@ -1074,7 +1090,7 @@ int eyemBinNiBlack(EyemImage tpSrcImg, EyemImage *tpDstImg, int iType, int iWinS
default: default:
break; break;
} }
//输出结果
///<输出计数结果标记图像 ///<输出计数结果标记图像
{ {
tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels(); tpDstImg->iWidth = dst.cols; tpDstImg->iHeight = dst.rows; tpDstImg->iDepth = dst.depth(); tpDstImg->iChannels = dst.channels();
...@@ -1105,10 +1121,6 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffse ...@@ -1105,10 +1121,6 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffse
} }
cv::Mat srcMean, variance; cv::Mat srcMean, variance;
//cv::Mat srcMean = cv::Mat(tpThresholdImg.iHeight, tpThresholdImg.iWidth, CV_8UC1, tpThresholdImg.ucpImage);
//if (srcMean.empty()) {
// return FUNC_IMAGE_NOT_EXIST;
//}
cv::blur(src, srcMean, cv::Size(11, 7)); cv::blur(src, srcMean, cv::Size(11, 7));
cv::Mat thresh; cv::Mat thresh;
{ {
...@@ -1146,7 +1158,6 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffse ...@@ -1146,7 +1158,6 @@ int eyemBinDynThreshold(EyemImage tpSrcImg, EyemImage tpThresholdImg, int iOffse
} }
} }
} }
cv::imwrite("smallpices.png", showMat);
//输出结果图 //输出结果图
return FUNC_OK; return FUNC_OK;
} }
......
...@@ -13,8 +13,7 @@ void eyemClp2dCenterTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsD ...@@ -13,8 +13,7 @@ void eyemClp2dCenterTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsD
int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine) int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine)
{ {
if ((tpPoint1.dX - tpPoint2.dX) < DBL_EPS && (tpPoint1.dY - tpPoint2.dY) < DBL_EPS) if (std::abs(tpPoint1.dX - tpPoint2.dX) < DBL_EPS && std::abs(tpPoint1.dY - tpPoint2.dY) < DBL_EPS) {
{
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
} }
tpLine.dA = -(tpPoint1.dY - tpPoint2.dY); tpLine.dA = -(tpPoint1.dY - tpPoint2.dY);
...@@ -25,12 +24,11 @@ int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC ...@@ -25,12 +24,11 @@ int eyemClp2dLineTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC
int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine) int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcsDABC &tpLine)
{ {
if ((tpPoint1.dX - tpPoint2.dX) < DBL_EPS && (tpPoint1.dY - tpPoint2.dY) < DBL_EPS) if (std::abs(tpPoint1.dX - tpPoint2.dX) < DBL_EPS && std::abs(tpPoint1.dY - tpPoint2.dY) < DBL_EPS) {
{
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
} }
tpLine.dA = 2 * (tpPoint2.dX - tpPoint1.dX); tpLine.dA = 2.0 * (tpPoint2.dX - tpPoint1.dX);
tpLine.dB = 2 * (tpPoint2.dY - tpPoint1.dY); tpLine.dB = 2.0 * (tpPoint2.dY - tpPoint1.dY);
tpLine.dC = pow(tpPoint1.dX, 2) - pow(tpPoint2.dX, 2) + pow(tpPoint1.dY, 2) - pow(tpPoint2.dY, 2); tpLine.dC = pow(tpPoint1.dX, 2) - pow(tpPoint2.dX, 2) + pow(tpPoint1.dY, 2) - pow(tpPoint2.dY, 2);
return FUNC_OK; return FUNC_OK;
} }
...@@ -38,8 +36,7 @@ int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, ...@@ -38,8 +36,7 @@ int eyemClp2dMidperpendicularTwoPoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2,
int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, EyemOcsDABC &tpVertical) int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, EyemOcsDABC &tpVertical)
{ {
double v = std::sqrt(std::pow(tpLine.dB, 2) + std::pow(-tpLine.dA, 2)); double v = std::sqrt(std::pow(tpLine.dB, 2) + std::pow(-tpLine.dA, 2));
if (v < DBL_EPS) if (v < DBL_EPS) {
{
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
} }
tpVertical.dA = tpLine.dB / v; tpVertical.dA = tpLine.dB / v;
...@@ -50,15 +47,14 @@ int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, Ey ...@@ -50,15 +47,14 @@ int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, Ey
void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &tpLine) void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &tpLine)
{ {
//単位:rad tpLine.dA = -sin(dSlope*PI / 180.0);
tpLine.dA = -sin(dSlope); tpLine.dB = cos(dSlope*PI / 180.0);
tpLine.dB = cos(dSlope);
tpLine.dC = -tpLine.dA*tpPoint.dX - tpLine.dB*tpPoint.dY; tpLine.dC = -tpLine.dA*tpPoint.dX - tpLine.dB*tpPoint.dY;
} }
int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY &tpPoint) int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY &tpPoint)
{ {
if (abs(tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB) < DBL_EPS){ if (abs(tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB) < DBL_EPS) {
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
} }
//计算系数 //计算系数
...@@ -92,7 +88,7 @@ int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double &dpA ...@@ -92,7 +88,7 @@ int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double &dpA
u = sqrt(pow(tpLine1.dA, 2) + pow(tpLine1.dB, 2)); u = sqrt(pow(tpLine1.dA, 2) + pow(tpLine1.dB, 2));
v = sqrt(pow(tpLine2.dA, 2) + pow(tpLine2.dB, 2)); v = sqrt(pow(tpLine2.dA, 2) + pow(tpLine2.dB, 2));
uv = sqrt(pow(tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB, 2)); uv = sqrt(pow(tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB, 2));
dpAngle = asin(uv / u*v); dpAngle = std::asin(uv / u*v)*180.0 / PI;
return FUNC_OK; return FUNC_OK;
} }
...@@ -150,9 +146,20 @@ int eyemClp2dCircleThreePoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcs ...@@ -150,9 +146,20 @@ int eyemClp2dCircleThreePoints(EyemOcsDXY tpPoint1, EyemOcsDXY tpPoint2, EyemOcs
//solve //solve
cv::solve(a, b, x, cv::DECOMP_SVD); cv::solve(a, b, x, cv::DECOMP_SVD);
tpCircle.dX = *x.ptr<double>(0); tpCircle.dX = x.ptr<double>(0)[0];
tpCircle.dY = *x.ptr<double>(1); tpCircle.dY = x.ptr<double>(1)[0];
tpCircle.dR = sqrt(pow(*x.ptr<double>(0), 2) + pow(*x.ptr<double>(1), 2) - (*x.ptr<double>(2))); tpCircle.dR = sqrt(pow(x.ptr<double>(0)[0], 2) + pow(x.ptr<double>(1)[0], 2) - (x.ptr<double>(2)[0]));
return FUNC_OK;
}
int eyemClp2dIntersectionLineAndCircle(EyemOcsDABC tpLine, EyemOcsDXYR tpCircle, EyemOcsDXY &tpPoint1, EyemOcsDXY &tpPoint2)
{
double dist = abs(tpLine.dA*tpCircle.dX + tpLine.dB*tpCircle.dY + tpLine.dC) / sqrt(tpLine.dA*tpLine.dA + tpLine.dB*tpLine.dB);
if (dist > tpCircle.dR) {
return FUNC_CANNOT_CALC;
}
return FUNC_OK; return FUNC_OK;
} }
...@@ -408,7 +408,7 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsD ...@@ -408,7 +408,7 @@ static void fitCircle2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsD
tpCircle.dR = sqrt(pow(x.ptr<double_t>(0)[0], 2) + pow(x.ptr<double_t>(1)[0], 2) - 4.0*(x.ptr<double_t>(2)[0])) / 2.0; tpCircle.dR = sqrt(pow(x.ptr<double_t>(0)[0], 2) + pow(x.ptr<double_t>(1)[0], 2) - 4.0*(x.ptr<double_t>(2)[0])) / 2.0;
} }
int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, int numToIgnore, double &RMS, EyemOcsDXYR &tpCircle) int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, double &RMS, EyemOcsDXYR &tpCircle)
{ {
//初始化参数,或许可用RANSAC算法进一步提高鲁棒性,不过没必要 //初始化参数,或许可用RANSAC算法进一步提高鲁棒性,不过没必要
if (numToIgnore > iPtnNum - 3 || iPtnNum < 3) { if (numToIgnore > iPtnNum - 3 || iPtnNum < 3) {
......
...@@ -433,7 +433,7 @@ extern "C" { ...@@ -433,7 +433,7 @@ extern "C" {
EXPORTS int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, EyemOcsDABC &tpLine); EXPORTS int eyemFitLine(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, EyemOcsDABC &tpLine);
EXPORTS int eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABC &tpLine); EXPORTS int eyemRobustFitLine(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDABC &tpLine);
EXPORTS int eyemFitPlane(int, EyemOcsDXYZ[], int, double, EyemOcsDABCD *); EXPORTS int eyemFitPlane(int, EyemOcsDXYZ[], int, double, EyemOcsDABCD *);
EXPORTS int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, int numToIgnore, double &RMS, EyemOcsDXYR &tpCircle); EXPORTS int eyemFitCircle(int iPtnNum, EyemOcsDXY *taPoint, int numToIgnore, double &RMS, EyemOcsDXYR &tpCircle);
EXPORTS int eyemFitEllipse(int, EyemOcsDXY[], int, double, EyemOcsDXYLSQ *); EXPORTS int eyemFitEllipse(int, EyemOcsDXY[], int, double, EyemOcsDXYLSQ *);
EXPORTS int eyemFitEllipseC(int, EyemOcsDXY[], int, double, double[]); EXPORTS int eyemFitEllipseC(int, EyemOcsDXY[], int, double, double[]);
EXPORTS int eyemFitConics(int, EyemOcsDXY[], int, double, double[]); EXPORTS int eyemFitConics(int, EyemOcsDXY[], int, double, double[]);
......
...@@ -6474,7 +6474,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl ...@@ -6474,7 +6474,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
} }
double min_err; double min_err;
EyemOcsDXYR _tpCircle; EyemOcsDXYR _tpCircle;
eyemFitCircle((int)taPoints.size(), &taPoints[0], 0, 15, min_err, _tpCircle); eyemFitCircle((int)taPoints.size(), &taPoints[0], 15, min_err, _tpCircle);
afas.push_back(AFA(min_err, _tpCircle)); afas.push_back(AFA(min_err, _tpCircle));
} }
...@@ -6538,16 +6538,6 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou ...@@ -6538,16 +6538,6 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
for (auto contourIdx = 0; contourIdx < contours.size(); contourIdx++) { for (auto contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
cv::drawContours(mask, contours, contourIdx, cv::Scalar(255), -1); cv::drawContours(mask, contours, contourIdx, cv::Scalar(255), -1);
} }
//连通域距离变换
//cv::Mat distMap;
//cv::distanceTransform(mask, distMap, cv::DIST_L2, 3);
//cv::normalize(distMap, distMap, 0, 255, cv::NORM_MINMAX);
//distMap.convertTo(distMap, CV_8UC1);
//二值化
//cv::threshold(distMap, binary, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
//计算最大连通域 //计算最大连通域
cv::Mat labels, stats, centroids; cv::Mat labels, stats, centroids;
int nccomps = cv::connectedComponentsWithStats(mask, labels, stats, centroids); int nccomps = cv::connectedComponentsWithStats(mask, labels, stats, centroids);
...@@ -6593,7 +6583,7 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou ...@@ -6593,7 +6583,7 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
double min_err; double min_err;
EyemOcsDXYR _tpCircle; EyemOcsDXYR _tpCircle;
eyemFitCircle((int)taPoints.size(), &taPoints[0], 0, iNumToIgnore, min_err, _tpCircle); eyemFitCircle((int)taPoints.size(), &taPoints[0], iNumToIgnore, min_err, _tpCircle);
//画图 //画图
cv::Mat showMat; cv::Mat showMat;
...@@ -6604,6 +6594,23 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou ...@@ -6604,6 +6594,23 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
tpCircle->fX = (float)_tpCircle.dX + (float)tpRoi.iXs; tpCircle->fX = (float)_tpCircle.dX + (float)tpRoi.iXs;
tpCircle->fY = (float)_tpCircle.dY + (float)tpRoi.iYs; tpCircle->fY = (float)_tpCircle.dY + (float)tpRoi.iYs;
tpCircle->fR = (float)_tpCircle.dR; tpCircle->fR = (float)_tpCircle.dR;
///<输出结果图像
{
tpDstImg->iWidth = mask.cols; tpDstImg->iHeight = mask.rows; tpDstImg->iDepth = mask.depth(); tpDstImg->iChannels = mask.channels();
//内存尺寸
int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据
memcpy(tpDstImg->vpImage, mask.data, _Size);
}
} }
else if (strcmp(funcName, "__func2") == 0) { else if (strcmp(funcName, "__func2") == 0) {
...@@ -6617,6 +6624,8 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou ...@@ -6617,6 +6624,8 @@ int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, dou
int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg) int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
{ {
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) if (image.empty())
...@@ -6628,6 +6637,14 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg) ...@@ -6628,6 +6637,14 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
cv::cvtColor(image, image, cv::COLOR_BGRA2BGR); cv::cvtColor(image, image, cv::COLOR_BGRA2BGR);
} }
cv::cvtColor(image, image, cv::COLOR_BGR2GRAY);
cv::Mat mask;
cv::threshold(image, mask, 0, 255, cv::THRESH_BINARY_INV | cv::THRESH_OTSU);
cv::Mat judgeMat;
judgeMat = image(cv::Rect(500, 160, 120, 120));
#pragma region resize img #pragma region resize img
//const int minInputSize = 832; //const int minInputSize = 832;
......
...@@ -2,36 +2,36 @@ ...@@ -2,36 +2,36 @@
int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg) int eyemSmoothMean(EyemImage tpImage, int kSizew, int kSizeh, EyemImage *tpDstImg)
{ {
cv::Mat image(tpImage.iHeight, tpImage.iWidth, CV_8UC1, tpImage.vpImage); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
cv::Mat dstImage; cv::Mat dst;
cv::blur(image, dstImage, cv::Size(kSizew, kSizeh)); cv::blur(image, dst, cv::Size(kSizew, kSizeh));
return FUNC_OK; return FUNC_OK;
} }
int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg) int eyemSmoothGaussian(EyemImage tpImage, int kSizew, int kSizeh, double dSigmaX, double dSigmaY, EyemImage *tpDstImg)
{ {
cv::Mat image(tpImage.iHeight, tpImage.iWidth, CV_8UC1, tpImage.vpImage); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
cv::Mat dstImage; cv::Mat dst;
cv::GaussianBlur(image, dstImage, cv::Size(kSizew, kSizeh), dSigmaX, dSigmaY); cv::GaussianBlur(image, dst, cv::Size(kSizew, kSizeh), dSigmaX, dSigmaY);
return FUNC_OK; return FUNC_OK;
} }
int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg) int eyemSmoothMedian(EyemImage tpImage, int kSize, EyemImage *tpDstImg)
{ {
cv::Mat image(tpImage.iHeight, tpImage.iWidth, CV_8UC1, tpImage.vpImage); cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
cv::Mat dstImage; cv::Mat dst;
cv::medianBlur(image, dstImage, kSize); cv::medianBlur(image, dst, kSize);
return FUNC_OK; return FUNC_OK;
} }
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!