Commit 94b11f53 张士柳

1 个父辈 e9d5142d
...@@ -305,6 +305,7 @@ namespace eyemLib_Sharp ...@@ -305,6 +305,7 @@ namespace eyemLib_Sharp
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public struct EyemBlobParams public struct EyemBlobParams
{ {
// public bool isLight;
public bool filterByArea; //斑点大小限制 public bool filterByArea; //斑点大小限制
public int minArea, maxArea; //最小面积/最大面积 public int minArea, maxArea; //最小面积/最大面积
public bool filterByCircularity; //斑点圆度限制 public bool filterByCircularity; //斑点圆度限制
...@@ -694,13 +695,15 @@ namespace eyemLib_Sharp ...@@ -694,13 +695,15 @@ namespace eyemLib_Sharp
/// <returns></returns> /// <returns></returns>
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatDiv(EyemImage tpImage1, EyemImage tpImage2, ref EyemImage tpDstImg); private static extern int eyemMatDiv(EyemImage tpImage1, EyemImage tpImage2, ref EyemImage tpDstImg);
//图像归一化 //图像归一化
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemNormalize(ref EyemImage tpImage); private static extern int eyemNormalize(ref EyemImage tpImage);
//通道分离 //通道分离
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDecompose(EyemImage tpImage, out EyemImage tpDstImgR, out EyemImage tpDstImgG, out EyemImage tpDstImgB); private static extern int eyemDecompose(EyemImage tpImage, out EyemImage tpDstImgR, out EyemImage tpDstImgG, out EyemImage tpDstImgB);
//图像反转
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBitwiseNot(ref EyemImage tpImage);
#endregion #endregion
#region 一维边缘测量 #region 一维边缘测量
...@@ -1225,31 +1228,32 @@ namespace eyemLib_Sharp ...@@ -1225,31 +1228,32 @@ namespace eyemLib_Sharp
//return; //return;
#region Test Blob #region Test Blob
sw.Restart(); //sw.Restart();
EyemBlobParams tpParams = new EyemBlobParams(); //EyemBlobParams tpParams = new EyemBlobParams();
tpParams.filterByArea = true; tpParams.minArea = 25; tpParams.maxArea = int.MaxValue; ////tpParams.isLight = true;
tpParams.filterByCircularity = false; tpParams.minCircularity = 0.8F; tpParams.maxCircularity = float.MaxValue; //tpParams.filterByArea = true; tpParams.minArea = 25; tpParams.maxArea = int.MaxValue;
tpParams.filterByConvexity = false; tpParams.minConvexity = 0.95F; tpParams.maxConvexity = float.MaxValue; //tpParams.filterByCircularity = false; tpParams.minCircularity = 0.8F; tpParams.maxCircularity = float.MaxValue;
tpParams.filterByInertia = false; tpParams.minInertiaRatio = 0.8F; tpParams.maxInertiaRatio = float.MaxValue; //tpParams.filterByConvexity = false; tpParams.minConvexity = 0.95F; tpParams.maxConvexity = float.MaxValue;
int ipNum; //tpParams.filterByInertia = false; tpParams.minInertiaRatio = 0.8F; tpParams.maxInertiaRatio = float.MaxValue;
BlobHandle hObject; //int ipNum;
EyemBinBlob* tpResults; //BlobHandle hObject;
eyemBinBlob(image, out hObject, tpParams, out tpResults, out ipNum, out tpDstImg); //EyemBinBlob* tpResults;
sw.Stop(); //eyemBinBlob(image, out hObject, tpParams, out tpResults, out ipNum, out tpDstImg);
for (int i = 0; i < ipNum; i++) //sw.Stop();
{ //for (int i = 0; i < ipNum; i++)
Console.WriteLine(tpResults[i].iArea); //{
} // Console.WriteLine(tpResults[i].iArea);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg); //}
if (bitmap != null) //Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
{ //if (bitmap != null)
bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file); //{
} // bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
hObject.Dispose(); //}
eyemImageFree(ref tpDstImg); //hObject.Dispose();
eyemImageFree(ref image); //eyemImageFree(ref tpDstImg);
Console.WriteLine("时间-:" + sw.ElapsedMilliseconds.ToString()); //eyemImageFree(ref image);
return; //Console.WriteLine("时间-:" + sw.ElapsedMilliseconds.ToString());
//return;
#endregion #endregion
#region Test 1DEdge #region Test 1DEdge
...@@ -1457,20 +1461,20 @@ namespace eyemLib_Sharp ...@@ -1457,20 +1461,20 @@ namespace eyemLib_Sharp
//如果对象供其他接口使用要先释放 //如果对象供其他接口使用要先释放
//eyemImageFree(ref tpDstImg); //eyemImageFree(ref tpDstImg);
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_LOWCONTRAST_PARTS",IP_SQUARE_PARTS //"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",,IP_SQUARE_PARTS
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg); //eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARGE_PARTS", ipReelNum, out tpDstImg); eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_SQUARE_PARTS", ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg); //eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg); //eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + "20210825095751-1.tpl", hModelID, ipReelNum, out tpDstImg);
//移除模板 //移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl"); //flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg); Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null) if (bitmap != null)
//{ {
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file); bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//} }
//< 解码测试 //< 解码测试
//int ipNum; EyemBarCode* tpResults; //int ipNum; EyemBarCode* tpResults;
......
...@@ -1320,9 +1320,7 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst ...@@ -1320,9 +1320,7 @@ int eyemBinClosing(EyemImage tpSrcImg, int iBinLevel, int iNum, EyemImage *tpDst
int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg) int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, EyemBinBlob **tpResult, int *ipNum, EyemImage *tpDstImg)
{ {
CV_Assert(tpImage.vpImage != NULL); CV_Assert(tpImage.vpImage != NULL);
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()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
...@@ -1330,8 +1328,10 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye ...@@ -1330,8 +1328,10 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
if (image.type() != CV_8UC1 || image.channels() != 1) { if (image.type() != CV_8UC1 || image.channels() != 1) {
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
} }
cv::threshold(image, image, 0, 255, cv::THRESH_BINARY_INV | cv::THRESH_OTSU); ////判断提取明暗部分
//if (!tpParams.isLight) {
// cv::bitwise_not(image, image);
//}
//显示图像 //显示图像
cv::Mat showMat; cv::Mat showMat;
cv::cvtColor(image, showMat, cv::COLOR_GRAY2RGB); cv::cvtColor(image, showMat, cv::COLOR_GRAY2RGB);
...@@ -1457,12 +1457,20 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye ...@@ -1457,12 +1457,20 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
} }
}); });
EyemBinBlob blob; EyemBinBlob blob; int idx = 0;
std::vector<EyemBinBlob> * tpResults = new std::vector<EyemBinBlob>(); std::vector<EyemBinBlob> * tpResults = new std::vector<EyemBinBlob>();
for (int i = 1; i < nccomps; i++) { for (int i = 1; i < nccomps; i++) {
if (colors[i]) { if (colors[i]) {
cv::rectangle(showMat, cv::Rect(stats.ptr<int>(i)[cv::CC_STAT_LEFT], stats.ptr<int>(i)[cv::CC_STAT_TOP], std::string label = "";
stats.ptr<int>(i)[cv::CC_STAT_WIDTH], stats.ptr<int>(i)[cv::CC_STAT_HEIGHT]), cv::Scalar(0, 0, 255)); label += std::to_string(idx);
cv::Rect bound(stats.ptr<int>(i)[cv::CC_STAT_LEFT], stats.ptr<int>(i)[cv::CC_STAT_TOP],
stats.ptr<int>(i)[cv::CC_STAT_WIDTH], stats.ptr<int>(i)[cv::CC_STAT_HEIGHT]);
int baseLine;
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
//cv::rectangle(showMat, cv::Point(bound.tl().x, bound.tl().y - 2 * baseLine - round(1.5*labelSize.height) - 1), cv::Point(bound.tl().x + round(1.5*labelSize.width) + baseLine + 1, bound.tl().y - 1), cv::Scalar(255, 255, 255), cv::FILLED);
//cv::putText(showMat, label, cv::Point(bound.tl().x, bound.tl().y - baseLine - 2), cv::FONT_HERSHEY_COMPLEX, 0.75, cv::Scalar(0, 0, 0), 1);
cv::rectangle(showMat, bound, cv::Scalar(0, 0, 255));
cv::drawMarker(showMat, cv::Point((int)centroids.ptr<double>(i)[0], (int)centroids.ptr<double>(i)[1]), cv::Scalar(255, 0, 0), cv::MARKER_CROSS, 6); cv::drawMarker(showMat, cv::Point((int)centroids.ptr<double>(i)[0], (int)centroids.ptr<double>(i)[1]), cv::Scalar(255, 0, 0), cv::MARKER_CROSS, 6);
double x1, y1, x2, y2; double x1, y1, x2, y2;
...@@ -1484,6 +1492,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye ...@@ -1484,6 +1492,7 @@ int eyemBinBlob(EyemImage tpImage, IntPtr *hObject, EyemBlobParams tpParams, Eye
blob.iArea = stats.ptr<int>(i)[cv::CC_STAT_AREA]; blob.iArea = stats.ptr<int>(i)[cv::CC_STAT_AREA];
blob.dTheta = mOrientation.ptr<float>(i)[0]; blob.dTheta = mOrientation.ptr<float>(i)[0];
tpResults->push_back(blob); tpResults->push_back(blob);
idx++;
} }
} }
//<输出结果图像 //<输出结果图像
...@@ -1511,4 +1520,3 @@ bool eyemBinFree(IntPtr hObject) ...@@ -1511,4 +1520,3 @@ bool eyemBinFree(IntPtr hObject)
tpResult = NULL; tpResult = NULL;
return true; return true;
} }
...@@ -445,6 +445,7 @@ extern "C" { ...@@ -445,6 +445,7 @@ extern "C" {
EXPORTS int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage &vpC); EXPORTS int eyemMatAdd(EyemImage vpA, EyemImage vpB, EyemImage &vpC);
EXPORTS int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage &tpDstImg); EXPORTS int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage &tpDstImg);
EXPORTS int eyemMatAbs(EyemImage &tpImage); EXPORTS int eyemMatAbs(EyemImage &tpImage);
EXPORTS int eyemBitwiseNot(EyemImage &tpImage);
EXPORTS int eyemNormalize(EyemImage &tpImage); EXPORTS int eyemNormalize(EyemImage &tpImage);
EXPORTS int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG, EyemImage *tpDstImgB); EXPORTS int eyemDecompose(EyemImage tpImage, EyemImage *tpDstImgR, EyemImage *tpDstImgG, EyemImage *tpDstImgB);
EXPORTS int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg); EXPORTS int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg);
......
此文件类型无法预览
...@@ -330,21 +330,15 @@ int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage ...@@ -330,21 +330,15 @@ int eyemMatSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage
int eyemMatAbs(EyemImage &tpImage) int eyemMatAbs(EyemImage &tpImage)
{ {
CV_Assert(NULL != tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
//释放内存 //释放内存
_free(tpImage); _free(tpImage);
//运算 //运算
cv::Mat _dst = cv::abs(_src); cv::Mat _dst = cv::abs(_src);
//内存尺寸 //内存尺寸
int _Size = _dst.cols *_dst.rows *_dst.channels(); int _Size = _dst.cols *_dst.rows *_dst.channels();
//图像信息 //图像信息
tpImage.iWidth = _dst.cols, tpImage.iHeight = _dst.rows, tpImage.iDepth = _dst.depth(), tpImage.iChannels = _dst.channels(); tpImage.iWidth = _dst.cols, tpImage.iHeight = _dst.rows, tpImage.iDepth = _dst.depth(), tpImage.iChannels = _dst.channels();
switch (_dst.depth()) switch (_dst.depth())
{ {
case CV_8U: case CV_8U:
...@@ -405,6 +399,14 @@ int eyemMatAbs(EyemImage &tpImage) ...@@ -405,6 +399,14 @@ int eyemMatAbs(EyemImage &tpImage)
return FUNC_OK; return FUNC_OK;
} }
int eyemBitwiseNot(EyemImage &tpImage)
{
CV_Assert(NULL != tpImage.vpImage&&tpImage.iDepth == 0);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage);
cv::bitwise_not(_src, _src, cv::noArray());
return FUNC_OK;
}
int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg) int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg)
{ {
CV_Assert(NULL != tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage);
......
...@@ -672,33 +672,24 @@ int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int ...@@ -672,33 +672,24 @@ int eyemCountObject(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int
//转单通道 //转单通道
if (src.channels() != 1) if (src.channels() != 1)
cv::cvtColor(src, src, cv::COLOR_BGR2GRAY); cv::cvtColor(src, src, cv::COLOR_BGR2GRAY);
//跳过执行 //跳过执行
if (killProcessID == 0) { if (killProcessID == 0) {
logger.t("eyemCountObjectIrregularPartsE 初始阶段被跳过执行..."); logger.t("eyemCountObjectIrregularPartsE 初始阶段被跳过执行...");
return FUNC_CANNOT_CALC; return FUNC_CANNOT_CALC;
} }
//图像裁剪 //图像裁剪
src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone(); src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone();
//image size //image size
int X = src.cols, Y = src.rows; int X = src.cols, Y = src.rows;
//测试用,用于去除黑色坏点干扰
cv::Mat medBlur;
cv::medianBlur(src, medBlur, 3);
//去除局部量斑影响(默认亮斑尺寸不会大于15个像素) //去除局部量斑影响(默认亮斑尺寸不会大于15个像素)
cv::Mat srcTmp; cv::morphologyEx(medBlur, medBlur, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
cv::morphologyEx(src, srcTmp, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
//去除黑斑影响
int m = cvRound(cv::mean(src)[0]);
srcTmp.forEach<uint16_t>([&](uint16_t& pixel, const int *pos)->void {
pixel = pixel == 0 ? m : pixel;
});
//image enhancement //image enhancement
double min, max; double min, max;
cv::Point maxId; cv::Point maxId;
cv::minMaxLoc(srcTmp, &min, &max, NULL, &maxId); cv::minMaxLoc(medBlur, &min, &max, NULL, &maxId);
src.convertTo(src, CV_64FC1); src.convertTo(src, CV_64FC1);
src -= min; src -= min;
...@@ -1672,23 +1663,17 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -1672,23 +1663,17 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
} }
//图像裁剪 //图像裁剪
src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone(); src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone();
//图像尺寸 //图像尺寸
int X = src.cols, Y = src.rows; int X = src.cols, Y = src.rows;
//测试用,用于去除黑色坏点干扰
//去除局部亮斑与黑斑影响(默认亮斑尺寸不会大于15个像素) cv::Mat medBlur;
cv::Mat srcTmp, srcTmp2; cv::medianBlur(src, medBlur, 3);
cv::morphologyEx(src, srcTmp, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15))); //去除局部亮斑(默认亮斑尺寸不会大于15个像素)
cv::Mat srcTmp;
//去除黑斑影响 cv::morphologyEx(medBlur, medBlur, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
int m = cvRound(cv::mean(src)[0]);
srcTmp.forEach<uint16_t>([&](uint16_t& pixel, const int *pos)->void {
pixel = pixel == 0 ? m : pixel;
});
//图像增强 //图像增强
double min, max; double min, max;
cv::minMaxLoc(srcTmp, &min, &max); cv::minMaxLoc(medBlur, &min, &max);
src.convertTo(src, CV_64FC1); src.convertTo(src, CV_64FC1);
src -= min; src -= min;
src /= (max - min); src /= (max - min);
...@@ -1727,7 +1712,6 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -1727,7 +1712,6 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
} }
} }
}); });
//增强到目标亮度方便显示 //增强到目标亮度方便显示
cc += cv::Scalar((162 - backThresh), (162 - backThresh), (162 - backThresh)); cc += cv::Scalar((162 - backThresh), (162 - backThresh), (162 - backThresh));
//去掉干扰 //去掉干扰
...@@ -2008,7 +1992,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -2008,7 +1992,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
binary = filtermap; binary = filtermap;
//释放资源 //释放资源
free((void *)pLabelImg); free((void *)pLabelImg);
} }//
else if (strcmp(ccSubType, "IP_LARGE_PARTS") == 0) else if (strcmp(ccSubType, "IP_LARGE_PARTS") == 0)
{ {
//二值化 //二值化
...@@ -2694,7 +2678,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -2694,7 +2678,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
//当作一种辅助手段,无需设置太严格 //当作一种辅助手段,无需设置太严格
double dmax; double dmax;
cv::minMaxLoc(traceMat(tRec_).clone(), NULL, &dmax); cv::minMaxLoc(traceMat(tRec_).clone(), NULL, &dmax);
if (dmax < 0.7*taMaxGray) { if (dmax < 0.6*taMaxGray) {
trayEnd = true; trayEnd = true;
} }
} }
...@@ -3031,7 +3015,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -3031,7 +3015,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
//当作一种辅助手段,无需设置太严格 //当作一种辅助手段,无需设置太严格
double dmax; double dmax;
cv::minMaxLoc(traceMat(tRec_).clone(), NULL, &dmax); cv::minMaxLoc(traceMat(tRec_).clone(), NULL, &dmax);
if (dmax < 0.7*taMaxGray) { if (dmax < 0.6*taMaxGray) {
trayEnd = true; trayEnd = true;
} }
} }
...@@ -4477,7 +4461,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -4477,7 +4461,7 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
{ {
//面积过滤 //面积过滤
if (stats.ptr<int>(j)[cv::CC_STAT_AREA] > 2) { if (stats.ptr<int>(j)[cv::CC_STAT_AREA] > 2) {
cv::circle(cc, cv::Point(cvRound((float)dpCent[(0) + (j)* 2]), cvRound((float)dpCent[(1) + (j)* 2])), 1, cv::Scalar(0, 255, 0)); cv::circle(cc, cv::Point(cvRound((float)dpCent[(0) + (j)* 2]), cvRound((float)dpCent[(1) + (j)* 2])), 1, cv::Scalar(0, 255, 0, 255));
binary.at<uchar>(cv::Point(cvRound((float)dpCent[(0) + (j)* 2]), cvRound((float)dpCent[(1) + (j)* 2]))) = 255; binary.at<uchar>(cv::Point(cvRound((float)dpCent[(0) + (j)* 2]), cvRound((float)dpCent[(1) + (j)* 2]))) = 255;
} }
} }
...@@ -4495,23 +4479,17 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -4495,23 +4479,17 @@ int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char
const int SizeConst = 4; const int SizeConst = 4;
//<输出计数结果标记图像 //<输出计数结果标记图像
memset(ipReelNum, 0, SizeConst); memset(ipReelNum, 0, SizeConst);
ipReelNum[0] = trayNum; ipReelNum[0] = trayNum;
tpDstImg->iWidth = cc.cols; tpDstImg->iHeight = cc.rows; tpDstImg->iDepth = cc.depth(); tpDstImg->iChannels = cc.channels(); 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); int _Size = tpDstImg->iWidth*tpDstImg->iHeight*tpDstImg->iChannels * sizeof(uint8_t);
//分配/初始化内存 //分配/初始化内存
tpDstImg->vpImage = (uint8_t *)malloc(_Size); tpDstImg->vpImage = (uint8_t *)malloc(_Size);
if (NULL == tpDstImg->vpImage) if (NULL == tpDstImg->vpImage)
return FUNC_NOT_ENOUGH_MEM; return FUNC_NOT_ENOUGH_MEM;
memset(tpDstImg->vpImage, 0, _Size); memset(tpDstImg->vpImage, 0, _Size);
//拷贝数据 //拷贝数据
memcpy(tpDstImg->vpImage, cc.data, _Size); memcpy(tpDstImg->vpImage, cc.data, _Size);
return FUNC_OK; return FUNC_OK;
} }
...@@ -4534,20 +4512,15 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in ...@@ -4534,20 +4512,15 @@ int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, in
src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone(); src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone();
//image size //image size
int X = src.cols, Y = src.rows; int X = src.cols, Y = src.rows;
//测试用,用于去除黑色坏点干扰
cv::Mat medBlur;
cv::medianBlur(src, medBlur, 3);
//去除局部量斑影响(默认亮斑尺寸不会大于15个像素) //去除局部量斑影响(默认亮斑尺寸不会大于15个像素)
cv::Mat srcTmp; cv::morphologyEx(medBlur, medBlur, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
cv::morphologyEx(src, srcTmp, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
//去除黑斑影响
int m = cvRound(cv::mean(src)[0]);
srcTmp.forEach<uint16_t>([&](uint16_t& pixel, const int *pos)->void {
pixel = pixel == 0 ? m : pixel;
});
//图像增强 //图像增强
double min, max; double min, max;
cv::Point maxId; cv::Point maxId;
cv::minMaxLoc(srcTmp, &min, &max, NULL, &maxId); cv::minMaxLoc(medBlur, &min, &max, NULL, &maxId);
src.convertTo(src, CV_64FC1); src.convertTo(src, CV_64FC1);
src -= min; src -= min;
...@@ -5967,13 +5940,10 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -5967,13 +5940,10 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char
//转单通道图像 //转单通道图像
if (src.channels() != 1) if (src.channels() != 1)
cv::cvtColor(src, src, cv::COLOR_BGR2GRAY); cv::cvtColor(src, src, cv::COLOR_BGR2GRAY);
//图像裁剪 //图像裁剪
src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone(); src = src(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)).clone();
//图像尺寸 //图像尺寸
int X = src.cols, Y = src.rows; int X = src.cols, Y = src.rows;
//加载模板 //加载模板
std::vector<EyemModelID> *tpModelIDs = reinterpret_cast<std::vector<EyemModelID>*>(hModelID); std::vector<EyemModelID> *tpModelIDs = reinterpret_cast<std::vector<EyemModelID>*>(hModelID);
...@@ -6002,19 +5972,16 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char ...@@ -6002,19 +5972,16 @@ int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char
int tplWidth, tplHeight; int tplWidth, tplHeight;
tplWidth = tplMat.cols, tplHeight = tplMat.rows; tplWidth = tplMat.cols, tplHeight = tplMat.rows;
//去除局部量斑影响(默认亮斑尺寸不会大于15个像素) //测试用,用于去除黑色坏点干扰
cv::Mat srcTmp; cv::Mat medBlur;
cv::morphologyEx(src, srcTmp, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15))); cv::medianBlur(src, medBlur, 3);
//去除黑斑影响 //去除局部量斑影响(默认亮斑尺寸不会大于15个像素)
int m = cvRound(cv::mean(src)[0]); cv::morphologyEx(medBlur, medBlur, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
srcTmp.forEach<uint16_t>([&](uint16_t& pixel, const int *pos)->void {
pixel = pixel == 0 ? m : pixel;
});
//图像增强 //图像增强
double min, max; double min, max;
cv::minMaxLoc(srcTmp, &min, &max); cv::minMaxLoc(medBlur, &min, &max);
src.convertTo(src, CV_64FC1); src.convertTo(src, CV_64FC1);
src -= min; src -= min;
...@@ -7028,7 +6995,6 @@ int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg) ...@@ -7028,7 +6995,6 @@ int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg)
int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg) int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg)
{ {
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())
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
...@@ -7039,23 +7005,16 @@ int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg ...@@ -7039,23 +7005,16 @@ int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg
//范围 //范围
image = image(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight)); image = image(cv::Rect(tpRoi.iXs, tpRoi.iYs, tpRoi.iWidth, tpRoi.iHeight));
//图像尺寸 //图像尺寸
int X = image.cols, Y = image.rows; int X = image.cols, Y = image.rows;
//测试用,用于去除黑色坏点干扰
cv::Mat medBlur;
cv::medianBlur(image, medBlur, 3);
//去除局部量斑影响(默认亮斑尺寸不会大于15个像素) //去除局部量斑影响(默认亮斑尺寸不会大于15个像素)
cv::Mat srcTmp; cv::morphologyEx(medBlur, medBlur, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
cv::morphologyEx(image, srcTmp, cv::MORPH_ERODE, cv::getStructuringElement(cv::MORPH_RECT, cv::Size(15, 15)));
//去除局部黑斑影响
int m = cvRound(cv::mean(image)[0]);
srcTmp.forEach<uint16_t>([&](uint16_t& pixel, const int *pos)->void {
pixel = pixel == 0 ? m : pixel;
});
//图像增强 //图像增强
double min, max; double min, max;
cv::minMaxLoc(srcTmp, &min, &max); cv::minMaxLoc(medBlur, &min, &max);
image.convertTo(image, CV_64FC1); image.convertTo(image, CV_64FC1);
image -= min; image -= min;
...@@ -7066,7 +7025,6 @@ int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg ...@@ -7066,7 +7025,6 @@ int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg
//转8位灰度图 //转8位灰度图
cv::Mat srcPrev; cv::Mat srcPrev;
image.convertTo(srcPrev, CV_8UC1, 1 / 255.); image.convertTo(srcPrev, CV_8UC1, 1 / 255.);
//设定bin数目 //设定bin数目
const int histSize = 17; const int histSize = 17;
//设定取值范围 //设定取值范围
......
...@@ -380,6 +380,8 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do ...@@ -380,6 +380,8 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
//std::vector<cv::Mat> mvs(3); //std::vector<cv::Mat> mvs(3);
//cv::split(image, mvs); //cv::split(image, mvs);
//mvs[0] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_b.png", cv::IMREAD_GRAYSCALE); //mvs[0] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_b.png", cv::IMREAD_GRAYSCALE);
...@@ -391,12 +393,12 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do ...@@ -391,12 +393,12 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do
//cv::merge(mvs, dest); //cv::merge(mvs, dest);
//for (int i = 0; i < 10; i++) //for (int i = 0; i < 10; i++)
//{ //{
//nonLocalMeansFilter_SSE(image, dest, cv::Size(3, 3), cv::Size(5, 5), 10.0, -1, 0); //nonLocalMeansFilter_SSE(image, dest, cv::Size(3, 3), cv::Size(5, 5), 10.0, -1, 0);
//image = dest; //image = dest;
//} //}
dest = image < 220;
//cv::imwrite("Portada_paper5.png", dest); cv::imwrite("Portada_paper5.png", dest);
return FUNC_OK; return FUNC_OK;
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!