Commit c7efc275 张士柳

1 个父辈 79de92b9
......@@ -441,7 +441,6 @@ namespace eyemLib_Sharp
#endregion
#region 通用
/// <summary>
/// Win32 memory copy function
/// </summary>
......@@ -452,6 +451,13 @@ namespace eyemLib_Sharp
[DllImport("ntdll.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern byte* memcpy(byte* dst, byte* src, int count);
/// <summary>
/// 动态加载dll
/// </summary>
/// <param name="lpLibFileName">dll文件名</param>
/// <returns></returns>
[DllImport("kernel32.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr LoadLibrary(string lpLibFileName);
/// <summary>
/// 从进程中的非托管内存分配指定长度的内存
/// </summary>
/// <param name="cb">长度</param>
......@@ -699,6 +705,9 @@ namespace eyemLib_Sharp
//图像反转
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemBitwiseNot(ref EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, out EyemImage tpDstImg);
#endregion
#region 一维边缘测量
......@@ -1054,6 +1063,9 @@ namespace eyemLib_Sharp
//异型器件(新版本模板匹配)
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, string fileName, string ccTplName, IntPtr hModelID, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
//多选项异型件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int[] iOptions, [MarshalAs(UnmanagedType.LPArray)]int[] ipReelNum, out EyemImage tpDstImg);
//匹配元件
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
......@@ -1119,6 +1131,8 @@ namespace eyemLib_Sharp
private static extern void loadImage2Mem(string key, EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setProcessLevel(double pl);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int setFineTuning(double ft);
/// <summary>
/// 对图像进行采样生成训练样本
/// </summary>
......@@ -1260,45 +1274,50 @@ namespace eyemLib_Sharp
//tpHsvModel.dpRangeL = new double[] { 0, 43, 46 }; tpHsvModel.dpRangeU = new double[] { 10, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 156, 43, 46 }; tpHsvModel.dpRangeUExt = new double[] { 180, 255, 255 };
//绿色分割模型
EyemHSVModel tpHsvModel = new EyemHSVModel();
tpHsvModel.dpRangeL = new double[] { 55, 10, 35 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
////绿色分割模型
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 55, 10, 35 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
EyemRect tpRoi0 = new EyemRect();
tpRoi0.iXs = 0; tpRoi0.iYs = 0;
tpRoi0.iWidth = image.iWidth;
tpRoi0.iHeight = image.iHeight;
////绿色分割模型
//EyemHSVModel tpHsvModel = new EyemHSVModel();
//tpHsvModel.dpRangeL = new double[] { 55, 10, 35 }; tpHsvModel.dpRangeU = new double[] { 100, 255, 255 };
//tpHsvModel.dpRangeLExt = new double[] { 0, 0, 0 }; tpHsvModel.dpRangeUExt = new double[] { 0, 0, 0 };
sw.Restart();
//EyemRect tpRoi0 = new EyemRect();
//tpRoi0.iXs = 0; tpRoi0.iYs = 0;
//tpRoi0.iWidth = image.iWidth;
//tpRoi0.iHeight = image.iHeight;
////sw.Restart();
List<EyemRect> tpRois = new List<EyemRect>();
EyemRect roi1 = new EyemRect();
roi1.iXs = 533; roi1.iYs = 187; roi1.iWidth = 345; roi1.iHeight = 310;
EyemRect roi2 = new EyemRect();
roi2.iXs = 900; roi2.iYs = 137; roi2.iWidth = 240; roi2.iHeight = 197;
//List<EyemRect> tpRois = new List<EyemRect>();
//EyemRect roi1 = new EyemRect();
//roi1.iXs = 470; roi1.iYs = 143; roi1.iWidth = 411; roi1.iHeight = 387;
//EyemRect roi2 = new EyemRect();
//roi2.iXs = 882; roi2.iYs = 84; roi2.iWidth = 317; roi2.iHeight = 251;
//添加需要监控的位置信息
tpRois.Add(roi1); tpRois.Add(roi2);
////添加需要监控的位置信息
//tpRois.Add(roi1); tpRois.Add(roi2);
//结构体转内存指针
IntPtr hGlobal = eyemStructArray2IntPtr(tpRois.ToArray());
////结构体转内存指针
//IntPtr hGlobal = eyemStructArray2IntPtr(tpRois.ToArray());
//加载mask
EyemImage mask;
eyemImageRead("mask.png", -1, out mask);
////加载mask
//EyemImage mask;
//eyemImageRead("mask.png", -1, out mask);
//
int[] ipResults = new int[tpRois.Count];
eyemTrackFeature(image, mask, tpRoi0, hGlobal, ipResults.Length, tpHsvModel, ipResults, out tpDstImg);
////
//int[] ipResults = new int[tpRois.Count];
//eyemTrackFeature(image, mask, tpRoi0, hGlobal, ipResults.Length, tpHsvModel, ipResults, out tpDstImg);
for (int i = 0; i < ipResults.Length; i++)
{
if (ipResults[i] == 1)
{
Console.WriteLine("检测到{0}位置有料盘", i);
}
}
//for (int i = 0; i < ipResults.Length; i++)
//{
// if (ipResults[i] == 1)
// {
// Console.WriteLine("检测到{0}位置有料盘", i);
// }
//}
//sw.Stop();
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
////蓝色分割
......@@ -1308,7 +1327,9 @@ namespace eyemLib_Sharp
//分类器
//eyemClassifier(image);
//sw.Restart();
//flag = eyemLibImpl(image, out tpDstImg);
//flag = eyemAffineTransform(image, 2.2965, out tpDstImg);
//sw.Stop();
//Console.WriteLine("时间花费:" + sw.ElapsedMilliseconds.ToString());
//float[] fFeatures = new float[512];
......@@ -1324,19 +1345,19 @@ namespace eyemLib_Sharp
//}
//EyemImage tpMatchImg;
//eyemTrainImageSampler(image, 128, "PID012", "D:\\ResOut", out tpMatchImg, out tpDstImg);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
bitmap.Save("D:\\ResOut\\" + file);
}
//释放资源
Marshal.FreeHGlobal(hGlobal);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save("D:\\ResOut\\" + file);
//}
////释放资源
//Marshal.FreeHGlobal(hGlobal);
//每运行检测一次释放一次
eyemImageFree(ref tpDstImg);
eyemImageFree(ref image);
//mask可以在程序启动与关闭时加载/释放
eyemImageFree(ref mask);
return;
//eyemImageFree(ref tpDstImg);
//eyemImageFree(ref image);
//////mask可以在程序启动与关闭时加载/释放
////eyemImageFree(ref mask);
//return;
//EyemImage templ, search;
//flag = eyemImageRead("D://算法测试图像//fiducial_template.png", -1, out templ);
......@@ -1627,12 +1648,19 @@ namespace eyemLib_Sharp
//如果对象供其他接口使用要先释放
//eyemImageFree(ref tpDstImg);
//点料参数微调
//setProcessLevel(4.0);
//setFineTuning(0.7);
int[] ipReelNum = new int[4];
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",,IP_SQUARE_PARTS
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_SQUARE_PARTS","IP_DYNAMIC_PARTS","","IP_DYNAMIC_SP1","IP_DYNAMIC_SP2"
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "", ipReelNum, out tpDstImg);
//eyemCountObjectE(image, tpRoi, file.Replace(".png", ""), ipReelNum, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), "IP_LARGE_PARTS", 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);
//算法选项
//std::string sOptions[8] = { "IP_DEFAULT_PARTS","IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS","IP_SQUARE_PARTS","","IP_DYNAMIC_SP1","IP_DYNAMIC_SP2" };
//eyemCountObjectIrregularPartsMultiopt(image, tpRoi, new int[] { 2, 2, 2, 2 }, ipReelNum, out tpDstImg);
//移除模板
//flag = eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
......@@ -1662,11 +1690,11 @@ namespace eyemLib_Sharp
}
sw.Stop();
Console.WriteLine(file + "--->" + "耗时:" + sw.ElapsedMilliseconds.ToString() + "ms" + ",结果:" + strReelNum);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null)
//{
// bitmap.Save("D:\\ResOut\\" + file);
//}
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
bitmap.Save("D:\\ResOut\\" + file);
}
//for (int i = 0; i < ipNum; i++)
//{
// Console.WriteLine("类型:" + Marshal.PtrToStringAnsi(tpResults[i].hType) + ";坐标" + "[" + tpResults[i].iCenterX.ToString() + "," + tpResults[i].iCenterY.ToString() + "]" + ";角度:" + tpResults[i].dAngle.ToString("F4") + "," + ";内容:" + Marshal.PtrToStringAnsi(tpResults[i].hText) + "");
......
......@@ -6,11 +6,11 @@ using System.Runtime.InteropServices;
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("eyemLib-Sharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("eyemLib调试")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("上海挚锦科技有限公司")]
[assembly: AssemblyProduct("eyemLib-Sharp")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyCopyright("Copyright 2020 © NeoTel. All Rights Reserved")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
......
......@@ -61,7 +61,7 @@ namespace eyemLib_Sharp
{
// dispose managed resources
}
//这里特别修改了eyemCvtToEyemImage的内存分配,因此皆可以由此接口释放
//这里特别修改了eyemCvtToEyemImage的内存分配,因此皆可以由此接口释放
eyemImageFree(ref image);
}
......
......@@ -229,3 +229,18 @@ int eyemClp2dTangentPointToCircle(EyemOcsDXY tpPoint, EyemOcsDXYR tpCircle, Eyem
tpPoint.dX*tpContact2.dY;
return FUNC_OK;
}
int eyemClp2dIntersectionLineAndConvexPolygon()
{
return FUNC_OK;
}
int eyemClp2dAreaOfPolygon()
{
return FUNC_OK;
}
int eyemClp2dPointInPolygon()
{
return FUNC_OK;
}
\ No newline at end of file
......@@ -279,7 +279,6 @@ static void fitLine2D_wods(int iPtnNum, const EyemOcsDXY2D *taPoints, EyemOcsDAB
}
cv::Vec4f linebuf;
cv::fitLine(points, linebuf, cv::DIST_HUBER, .0, 1e-2, 1e-2);
double px = linebuf[2], py = linebuf[3];
double nx = linebuf[1], ny = -linebuf[0];
//直线一般式
......@@ -757,7 +756,7 @@ static void fitEllipse_wods(int iPtnNum, const EyemOcsDXY *taPoints, float *weig
linebuf[0] = rbox.center.x; linebuf[1] = rbox.center.y; linebuf[2] = cv::max(rbox.size.width / 2.0f, rbox.size.height / 2.0f); linebuf[3] = cv::min(rbox.size.width / 2.0f, rbox.size.height / 2.0f); linebuf[4] = rbox.angle*(float)PI / 180.0f;
}
int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY * taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYLSQ & tpEllipse)
int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemOcsDXYLSQ &tpEllipse)
{
float linebuf[5] = { .0f };
memset(linebuf, 0, 5 * sizeof(float));
......@@ -779,3 +778,12 @@ int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY * taPoint, int iCalcMode, doubl
return FUNC_OK;
}
int eyemRobustFitRectangle(int iPtnNum, EyemOcsDXY *taPoint, int iCalcMode, double dRobustCoef, EyemRotateRect &tpRect)
{
//先计算最小外包,然后计算各点到矩形的最小平方差和
//cv::minAreaRect();
return FUNC_OK;
}
......@@ -31,6 +31,12 @@ void setProcessLevel(double processLevel_)
processLevel = processLevel_;
}
double fineTuning = 0.7;
void setFineTuning(double fineTuning_)
{
fineTuning = fineTuning_;
}
std::map<std::string, EyemImage> imageMap;
void loadImage2Mem(const char *key, EyemImage tpImage)
{
......
......@@ -7,6 +7,18 @@
#include <opencv.hpp>
#ifndef FILEVERSION
#define FILEVERSION "2.4.8.2"
#endif
#ifndef COPYRIGHT
#define COPYRIGHT "Copyright (C) 2020-2022 NeoTel. All Rights Reserved"
#endif
#ifndef ORIGINALFILENAME
#define ORIGINALFILENAME "eyemLib.dll"
#endif
#ifndef EXPORTS
#define EXPORTS __declspec(dllexport)
#endif
......@@ -189,14 +201,6 @@ typedef struct {
double dVar; // 可能会使用的值
} EyemRect3;
//// 旋转矩形定义
//typedef struct {
// double dWidth; // 旋转矩形宽度
// double dHeight; // 旋转矩形高度
// double dAngle; // 旋转矩形角度(-90==>90)
// EyemOcsDXY tC; // 旋转矩形中心
//} EyemRotateRect;
///////////////////////////////////////////////////////////////////////////////
// Orthogonal Coordinate System
......@@ -371,6 +375,13 @@ typedef struct {
} EyemHSVModel; // 用于HSV颜色模型分割(H(0-180)、S(0-255)、V(0-255))
typedef struct {
EyemOcsDXY tC; // 旋转矩形中心
double dWidth; // 旋转矩形宽度
double dHeight; // 旋转矩形高度
double dAngle; // 旋转矩形角度
} EyemRotateRect; // 旋转矩形定义
/********************************************************************************************/
/* 每个特定于源的标头 */
/********************************************************************************************/
......@@ -916,6 +927,7 @@ extern "C" {
EXPORTS int eyemCountObjectE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char * ccSubType, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsE(EyemImage tpImage, EyemRect tpRoi, const char *fileName, const char *ccTplName, IntPtr hModelID, int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsMultiopt(EyemImage tpImage, EyemRect tpRoi, int iOptions[4], int *ipReelNum, EyemImage *tpDstImg);
EXPORTS int eyemAchvMatchMat(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char *ccTplName);
......@@ -935,6 +947,8 @@ extern "C" {
EXPORTS int eyemDrawCircle(EyemImage tpImage, EyemOcsDXYR tpCircle);
EXPORTS int eyemDrawRectangle(EyemImage tpImag, EyemRect tpRect);
EXPORTS int eyemTrainImageSampler(EyemImage tpImage, int iSize, const char *ccClassName, const char *ccToPath, EyemImage *tpMatchImg, EyemImage *tpDstImg);
EXPORTS int eyemAffineTransform(EyemImage tpImage, double tAngle, EyemOcsDXY tpCenter, EyemImage *tpDstImg);
#ifdef __cplusplus
}
......@@ -946,6 +960,9 @@ extern "C" __declspec(dllexport) void setSkipProcessID(int pid);
// 设置全局参数
extern "C" __declspec(dllexport) void setProcessLevel(double pl);
// 设置A算法全局参数
extern "C" __declspec(dllexport) void setFineTuning(double ft);
// 加载图像到内存
extern "C" __declspec(dllexport) void loadImage2Mem(const char *key, EyemImage tpImage);
......
此文件类型无法预览
......@@ -704,3 +704,37 @@ int eyemWarpShiftSubpix(EyemImage tpImage, double dShiftX, double dShiftY, EyemI
cv::warpAffine(image, imageShift, matM, image.size(), iInterMethod, 0);
return FUNC_OK;
}
bool eyemCheckBinary(EyemImage tpImage)
{
CV_Assert(NULL != tpImage.vpImage);
cv::Mat image = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (image.empty())
return false;
int X = image.cols, Y = image.rows;
int incn = image.channels();
if (incn != 1) {
return false;
}
int bs = 16, b = (X*incn) / bs, stride = (int)image.step;
for (int y = 0; y < Y; y++)
{
unsigned char *LinePS = image.data + y * stride;
for (int x = 0; x < b * bs; x += bs) {
__m128i SrcV = _mm_loadu_si128((__m128i *)(LinePS + x));
__m128i MaskW = _mm_cmpeq_epi8(SrcV, _mm_set1_epi8(255));
__m128i MaskB = _mm_cmpeq_epi8(SrcV, _mm_setzero_si128());
__m128i Mask = _mm_or_si128(MaskW, MaskB);
if (_mm_movemask_epi8(Mask) != 65535) {
return false;
}
}
for (int x = b * bs; x < X * incn; x++) {
if ((LinePS[x] != 255) && (LinePS[x] != 0)) {
return false;
}
}
}
return true;
}
\ No newline at end of file
此文件的差异太大,无法显示。
......@@ -14,6 +14,7 @@ constexpr double c = PI / 180.;
extern Logger logger;
extern int killProcessID;
extern double processLevel;
extern double fineTuning;
extern std::map<std::string, EyemImage> imageMap;
#endif/* __EYEM_MISC_H */
......@@ -380,7 +380,7 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do
return FUNC_IMAGE_NOT_EXIST;
}
cv::Mat dest;
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(3, 3), 5.0, -1, 0);
return FUNC_OK;
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!