Commit 30d336d2 张士柳

1 个父辈 61eb66e4
......@@ -863,7 +863,7 @@ namespace eyemLib_Sharp
/// <param name="nCalipers">卡尺数量</param>
/// <param name="iSearchDirec">搜索方向(起点到终点方向的垂直方向)</param>
/// <param name="dAmpThreshold">最小边缘幅度</param>
/// <param name="ccTransition">灰度值过渡的类型以确定边缘'first','all', 'negative', 'positive'</param>
/// <param name="ccTransition">灰度值过渡的类型以确定边缘'all', 'negative', 'positive'</param>
/// <param name="hObject">结果</param>
/// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
......@@ -1187,7 +1187,7 @@ namespace eyemLib_Sharp
private static extern int setSkipProcessID(int pid);
//圆形mark点定位
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMarkerTracing(EyemImage tpImage, double dThreshold, ref EyemOcsFXYR tpCircle, bool bHighAccuracy = false);
private static extern int eyemMarkerTracing(EyemImage tpImage, double dThreshold, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg, bool bHighAccuracy = false);
//多功能工具
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, string funcName, double dThreshold, int iNumToIgnore, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg);
......@@ -1249,7 +1249,7 @@ namespace eyemLib_Sharp
{
EyemImage image;
EyemImage tpDstImg = new EyemImage();
//EyemOcsFXYR tpCircle = new EyemOcsFXYR();
EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//int flag = eyemImageReadRaw(fileName, 3072, 3072, 2, out ucpImage);
int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0)
......@@ -1261,6 +1261,8 @@ namespace eyemLib_Sharp
Stopwatch sw = new Stopwatch();
sw.Restart();
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//EyemImage image1 = new EyemImage(); EyemImage image2 = new EyemImage();
//flag = eyemMatMalloc(512, 512, 1, "uint8_t", out image1);
//flag = eyemMatMalloc(512, 512, 1, "uint8_t", out image2);
......@@ -1280,7 +1282,16 @@ namespace eyemLib_Sharp
//flag = eyemLibImpl(image, out tpDstImg);
//flag = eyemMarkerTracing(image, 130, ref tpCircle);
flag = eyemMarkerTracing(image, 120, ref tpCircle, out tpDstImg);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
}
eyemImageFree(ref tpDstImg);
return;
#region Test Blob
......@@ -1296,21 +1307,21 @@ namespace eyemLib_Sharp
#endregion
#region Test 1DEdge
EyemOcsDXY tpLineSt = new EyemOcsDXY();
tpLineSt.dX = 671;
tpLineSt.dY = 718;
EyemOcsDXY tpLineEd = new EyemOcsDXY();
tpLineEd.dX = 858;
tpLineEd.dY = 716;
MeasureHandle hObject;
//eyemEdge1dGenMeasureRect(image, tpLineSt, tpLineEd, 10, "all", 0, 0.9, 30, out hObject);
//eyemEdge1dGenPosRect(image, tpLineSt, tpLineEd, 50, 0, 0.9, 30, out hObject);
sw.Restart();
eyemEdge1dFindLine(image, tpLineSt, tpLineEd, 25, 35, -1, 15, "negative", out hObject);
sw.Stop();
Console.WriteLine("时间:" + sw.ElapsedMilliseconds.ToString());
return;
//EyemOcsDXY tpLineSt = new EyemOcsDXY();
//tpLineSt.dX = 386.5;
//tpLineSt.dY = 136.5;
//EyemOcsDXY tpLineEd = new EyemOcsDXY();
//tpLineEd.dX = 323.5;
//tpLineEd.dY = 40.5;
//MeasureHandle hObject;
////eyemEdge1dGenMeasureRect(image, tpLineSt, tpLineEd, 10, "all", 0, 0.9, 30, out hObject);
////eyemEdge1dGenPosRect(image, tpLineSt, tpLineEd, 50, 0, 0.9, 30, out hObject);
//sw.Restart();
//eyemEdge1dFindLine(image, tpLineSt, tpLineEd, 15, 3500, -1, 15, "all", out hObject);
//sw.Stop();
//Console.WriteLine("时间:" + sw.ElapsedMilliseconds.ToString());
//return;
//hObject.Dispose();
#endregion
......@@ -1506,7 +1517,7 @@ namespace eyemLib_Sharp
//flag = eyemMulFuncTool(image, tpRoi, "__func1", 65, 75, ref tpCircle, out tpDstImg);
int[] ipReelNum = new int[4];
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//获取用于制作模板的图像
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
......@@ -1566,19 +1577,19 @@ namespace eyemLib_Sharp
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_LOWCONTRAST_PARTS"
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARGE_PARTS", ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, fileName, ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), tpModels[0], hModelID, ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
//bitmap.Save("D:\\ResOut\\" + file);
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
}
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// //bitmap.Save("D:\\ResOut\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//< 解码测试
//int ipNum; EyemBarCode* tpResults;
......
......@@ -308,8 +308,9 @@ namespace eyemLib_Sharp
/// <param name="tpCircle">结果</param>
/// <param name="bHighAccuracy">是否是高精度定位</param>
/// <returns></returns>
//圆形mark点定位
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMarkerTracing(EyemImage tpImage, double dThreshold, ref EyemOcsFXYR tpCircle, bool bHighAccuracy = false);
private static extern int eyemMarkerTracing(EyemImage tpImage, double dThreshold, ref EyemOcsFXYR tpCircle, out EyemImage tpDstImg, bool bHighAccuracy = false);
#endregion
#region 通用
......@@ -324,7 +325,7 @@ namespace eyemLib_Sharp
private static extern void setLogCallback(TCallBack cb);
#endregion
// 日志
#region 日志
public delegate void TCallBack(string msg);
public static TCallBack sld = new TCallBack(TLogCallback);
......@@ -353,12 +354,13 @@ namespace eyemLib_Sharp
{
//算法里输出的一切日志都会在这里
}
#endregion
//例程
public static void eyeyTestTemplateModelMethod(string fileName)
{
#region //从本地读图
//EyemImage image;
//EyemImage image, tpDstImg;
//int flag = eyemImageRead(fileName, -1, out image);
//if (flag != 0)
//{
......@@ -367,20 +369,22 @@ namespace eyemLib_Sharp
//}
//EyemOcsFXYR tpCircle = new EyemOcsFXYR();
//flag = eyemMarkerTracing(image, 130, ref tpCircle);
//flag = eyemMarkerTracing(image, 120, ref tpCircle, out tpDstImg);
////free image
//eyemImageFree(ref image);
//eyemImageFree(ref tpDstImg);
#endregion
#region //从内存读图
//image = eyemCvtToEyemImage(bitmap);
//image = eyemCvtToEyemImage(/*Bitmap*/);
//flag = eyemMarkerTracing(image, 130, ref tpCircle);
//flag = eyemMarkerTracing(image, 120, ref tpCircle, out tpDstImg);
////free image
//Marshal.FreeHGlobal(image.vpImage);
//eyemImageFree(ref tpDstImg);
#endregion
}
......
......@@ -77,6 +77,48 @@ int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, Eyem
return FUNC_OK;
}
int eyemClp2dIntersectionLineSegment(EyemOcsDABC tpLine, EyemOcsDXY tpPtSt, EyemOcsDXY tpPtEd, int *ipStatus, EyemOcsDXY &tpPoint)
{
double d1, d2;
d1 = abs(tpLine.dA*tpPtSt.dX + tpLine.dB*tpPtSt.dY + tpLine.dC) / sqrt(tpLine.dA*tpLine.dA + tpLine.dB*tpLine.dB);
if (abs(tpLine.dB) < FLT_EPSILON) {
d1 = tpPtSt.dX < -tpLine.dC / tpLine.dA ? -d1 : d1;
}
else {
d1 = tpPtSt.dY >= ((-tpLine.dA / tpLine.dB)*tpPtSt.dX - tpLine.dC / tpLine.dB) ? d1 : -d1;
}
d2 = abs(tpLine.dA*tpPtEd.dX + tpLine.dB*tpPtEd.dY + tpLine.dC) / sqrt(tpLine.dA*tpLine.dA + tpLine.dB*tpLine.dB);
if (abs(tpLine.dB) < FLT_EPSILON) {
d2 = tpPtEd.dX < -tpLine.dC / tpLine.dA ? -d2 : d2;
}
else {
d2 = tpPtEd.dY >= ((-tpLine.dA / tpLine.dB)*tpPtEd.dX - tpLine.dC / tpLine.dC) ? d2 : -d2;
}
//异号或者为0则交点存在
if (d1*d2 <= 0) {
d1 = abs(d1); d2 = abs(d2);
double k = d1 / (d1 + d2);
if ((d1 + d2 != 0) && ((tpPtSt.dX + k*(tpPtEd.dX - tpPtSt.dX) != tpPtSt.dX) || ((tpPtSt.dY + k*(tpPtEd.dY - tpPtSt.dY)) != tpPtSt.dY))) {
tpPoint.dX = tpPtSt.dX + k*(tpPtEd.dX - tpPtSt.dX); tpPoint.dY = tpPtSt.dY + k*(tpPtEd.dY - tpPtSt.dY);
*ipStatus = EYEM_CG_INTERSECTION;
}
else if (d1 + d2 == 0) {
*ipStatus = EYEM_CG_SEG1_OVERLAP_SGM2;
}
}
else {
*ipStatus = EYEM_CG_NOT_INTERSECTION;
}
return FUNC_OK;
}
int eyemClp2dIntersectionOfTwoSegments(EyemOcsDXY tpPt1St, EyemOcsDXY tpPt1Ed, EyemOcsDXY tpPt2St, EyemOcsDXY tpPt2Ed, int *ipStatus, EyemOcsDXY &tpPoint)
{
return FUNC_OK;
}
int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double &dpAngle)
{
if (abs(tpLine1.dA*tpLine2.dB - tpLine2.dA*tpLine1.dB) < EPS) {
......
......@@ -462,6 +462,8 @@ extern "C" {
EXPORTS int eyemClp2dVerticalLinePointAndLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, EyemOcsDABC &tpVertical);
EXPORTS void eyemClp2dLinePointAndSlope(EyemOcsDXY tpPoint, double dSlope, EyemOcsDABC &tpLine);
EXPORTS int eyemClp2dIntersectionTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDXY &tpPoint);
EXPORTS int eyemClp2dIntersectionLineSegment(EyemOcsDABC tpLine, EyemOcsDXY tpPtSt, EyemOcsDXY tpPtEd, int *ipStatus, EyemOcsDXY &tpPoint);
EXPORTS int eyemClp2dIntersectionOfTwoSegments(EyemOcsDXY tpPt1St, EyemOcsDXY tpPt1Ed, EyemOcsDXY tpPt2St, EyemOcsDXY tpPt2Ed, int *ipStatus, EyemOcsDXY &tpPoint);
EXPORTS int eyemClp2dAngleTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, double &dpAngle);
EXPORTS int eyemClp2dCenterLineOfTwoLines(EyemOcsDABC tpLine1, EyemOcsDABC tpLine2, EyemOcsDABC &tpLineC);
EXPORTS int eyemClp2dDistancePointToLine(EyemOcsDXY tpPoint, EyemOcsDABC tpLine, double &dpDist);
......@@ -514,6 +516,10 @@ extern "C" {
enum {
EYEM_CG_NOT_INTERSECTION, // 未相交
EYEM_CG_INTERSECTION, // 相交(彼此交叉)
EYEM_CG_END1_CONTACT_END2, // 线 1 的端点和线 2 的端点接触(匹配)
EYEM_CG_END1_CONTACT_SGM2, // 与线 1 的端点以外的线接触
EYEM_CG_END2_CONTACT_SGM1, // 线 2 的端点与线 1 的端点以外的接触
EYEM_CG_SEG1_OVERLAP_SGM2 // 线 1 和线 2 重叠(如果两条线位于同一直线上)
};
......@@ -645,7 +651,7 @@ extern "C" {
EXPORTS int eyemEdge1dGenPosRect(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int iTransition, double dSigma, double dAmpThresh, IntPtr *hObject);
EXPORTS int eyemEdge1dFitLine(IntPtr hObject, int iClippingEndPoints, int iMaxIterations, double dRobustCoef, EyemOcsDABC *tpLine);
EXPORTS int eyemEdge1dFitCircle(IntPtr hObject, int iClippingEndPoints, int iMaxIterations, double dRobustCoef, EyemOcsDXYR *tpCircle);
EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iWhRoi, int nCalipers, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int iFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS bool eyemEdge1dGenMeasureFree(IntPtr hObject);
#ifdef __cplusplus
......@@ -857,7 +863,7 @@ extern "C" {
EXPORTS int eyemReleaseModel(IntPtr &hModelID);
EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults, EyemImage *tpDstImg);
EXPORTS int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum);
EXPORTS int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircle, bool bHighAccuracy = false);
EXPORTS int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy = false);
EXPORTS int eyemMulFuncTool(EyemImage tpImage, EyemRect tpRoi, const char *funcName, double dThreshold, int iNumToIgnore, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg);
EXPORTS int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg);
EXPORTS int eyemDrawLine(EyemImage tpImage, EyemOcsDABC tpLine);
......
此文件类型无法预览
......@@ -1727,6 +1727,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
}
}
});
//增强到目标亮度方便显示
cc += cv::Scalar((162 - backThresh), (162 - backThresh), (162 - backThresh));
//去掉干扰
......@@ -7264,7 +7265,7 @@ int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, i
return FUNC_OK;
}
int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircle, bool bHighAccuracy)
int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy)
{
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
......@@ -7281,6 +7282,23 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
cv::cvtColor(image, image, cv::COLOR_GRAY2BGR);
}
//画图
cv::Mat cc = image.clone();
cv::Mat imgGray;
cv::cvtColor(image, imgGray, cv::COLOR_BGR2HSV);
cv::Mat mask1, mask2;
cv::inRange(imgGray, cv::Scalar(0, 50, 20), cv::Scalar(5, 255, 255), mask1);
cv::inRange(imgGray, cv::Scalar(175, 50, 20), cv::Scalar(180, 255, 255), mask2);
cv::Mat maskj, imageR;
cv::bitwise_or(mask1, mask2, maskj);
//膨胀部分区域
cv::bitwise_and(image, image, imageR, maskj);
image = imageR;
//归一化
cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range range)->void {
for (int y = range.start; y < range.end; y++) {
......@@ -7303,7 +7321,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
cv::threshold(mv[2], mask, dThreshold, 255, cv::THRESH_BINARY);
//去掉干扰
cv::morphologyEx(mask, mask, cv::MORPH_OPEN, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(7, 7)));
cv::morphologyEx(mask, mask, cv::MORPH_OPEN, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3)));
std::vector<std::vector<cv::Point>> contours, contourfilter;
cv::findContours(mask, contours, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE);
......@@ -7325,7 +7343,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
}
};
bool typeCircle = false;
bool typeCircle = true;
if (typeCircle) {
//过滤
std::vector<cv::Point> approx;
......@@ -7334,17 +7352,16 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
cv::approxPolyDP(cv::Mat(contour), approx, arcL*0.01, true);
if (approx.size() > 10) {
cv::Rect bbox = cv::boundingRect(contour);
if (MAX(bbox.width, bbox.height) > 20 && ((float)bbox.width / (float)bbox.height) > 0.85 && \
((float)bbox.width / (float)bbox.height) < 1.15) {
if (MIN(bbox.width, bbox.height) > 20 && ((float)bbox.width / (float)bbox.height) > 0.75 && \
((float)bbox.width / (float)bbox.height) < 1.25) {
//圆度
double afa = 4.0f*CV_PI*cv::contourArea(contour, false) / std::pow(arcL, 2);
if (afa > 0.85) {
if (afa > 0.45) {
contourfilter.push_back(contour);
}
}
}
}
std::vector<AFA> afas;
//画图
for (auto&contour : contourfilter) {
......@@ -7357,7 +7374,7 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
}
double min_err;
EyemOcsDXYR _tpCircle;
eyemFitCircle((int)taPoints.size(), &taPoints[0], 15, min_err, _tpCircle);
eyemFitCircle((int)taPoints.size(), &taPoints[0], 10, min_err, _tpCircle);
afas.push_back(AFA(min_err, _tpCircle));
}
......@@ -7370,6 +7387,10 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
tpCircle->fX = (float)afas[0].tpCircle.dX;
tpCircle->fY = (float)afas[0].tpCircle.dY;
tpCircle->fR = (float)afas[0].tpCircle.dR;
//画图
cv::rectangle(cc, cv::Rect(cv::Point2f(tpCircle->fX - 2.0f*tpCircle->fR, tpCircle->fY - 2.0f*tpCircle->fR),
cv::Point2f(tpCircle->fX + 2.0f*tpCircle->fR, tpCircle->fY + 2.0f*tpCircle->fR)), cv::Scalar(0, 255, 255), 4);
cv::drawMarker(cc, cv::Point2f(tpCircle->fX, tpCircle->fY), cv::Scalar(0, 255, 0), cv::MARKER_CROSS, 20, 1);
}
else {
std::vector<AFA> rboxes;
......@@ -7401,6 +7422,21 @@ int eyemMarkerTracing(EyemImage tpImage, double dThreshold, EyemOcsFXYR *tpCircl
tpCircle->fY = (float)rboxes[0].tpCircle.dY;
tpCircle->fR = (float)rboxes[0].tpCircle.dR;
}
//<输出结果图像
tpDstImg->iWidth = cc.cols; tpDstImg->iHeight = cc.rows; tpDstImg->iDepth = cc.depth(); tpDstImg->iChannels = cc.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, cc.data, _Size);
return FUNC_OK;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!