Commit 8123f16e 张士柳

1 个父辈 6b03fe92
......@@ -636,6 +636,13 @@ namespace eyemLib_Sharp
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImageFree(ref EyemImage tpImage);
//测试用
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemOpenWindow(string winname);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemCloseWindow(string winname);
#endregion
#region 2 blob 分析
......@@ -738,6 +745,9 @@ namespace eyemLib_Sharp
//背景变化跟踪
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize, IntPtr ipResults);
//插件机
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize);
#endregion
public static void eyemReadImageTool(string fileName)
......@@ -912,45 +922,45 @@ namespace eyemLib_Sharp
EyemRect tpRoi = new EyemRect();
tpRoi.iXs = 20; tpRoi.iYs = 20;
tpRoi.iWidth = image.iWidth - 40;
tpRoi.iHeight = image.iHeight - 40;
tpRoi.iXs = 50; tpRoi.iYs = 50;
tpRoi.iWidth = image.iWidth - 100;
tpRoi.iHeight = image.iHeight - 100;
//
string pNumObj = "";
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//获取用于制作模板的图像
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//Bitmap bmp = eyemCvtToBitmap(tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bmp != null)
//if (bitmap != null)
//{
// bmp.Save("D:\\模板文件原图\\" + file);
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//创建模板匹配模型
EyemRect tpRoi2 = new EyemRect();
tpRoi2.iXs = 0; tpRoi2.iYs = 0;
tpRoi2.iWidth = image.iWidth;
tpRoi2.iHeight = image.iHeight;
tpRoi2.iXs = 1553; tpRoi2.iYs = 733;
tpRoi2.iWidth = 28;
tpRoi2.iHeight = 9;
double matchDeg = 0.75;
//flag = eyemCreateTemplateModel(image, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl"));
//double matchDeg = 0.80;
//flag = eyemCreateTemplateModel(tpDstImg, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl"));
//string selectModel = "";
//flag = eyemMatchTemplateModel(tpDstImg, "D:\\模板文件", ref selectModel);
string selectModel = "";
flag = eyemMatchTemplateModel(tpDstImg, "D:\\模板文件", ref selectModel);
//最好释放掉
//eyemImageFree(ref tpDstImg);
eyemImageFree(ref tpDstImg);
//"IP_SMALL_PARTS","IP_LARGE_PARTS","IP_LONG_PARTS",""
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, tpRoi, file.Replace(".png", ""), 0.1, "IP_LARGE_PARTS", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectE(image, tpRoi, fileName, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + file.Replace(".png", ".tpl"), ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", ref pNumObj, out tpDstImg);
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
......@@ -1004,33 +1014,27 @@ namespace eyemLib_Sharp
//信号值,用于后续处理
int[] bitSingle = new int[tpRois.Count];
//测试用
EyemImage tpRefImg, tpNextImg;
eyemImageRead("D:\\x.bmp", -1, out tpRefImg);
eyemImageRead("D:\\y.bmp", -1, out tpNextImg);
int iRets = eyemTrackFeature(tpRefImg, tpNextImg, hGlobal, tpRois.Count, Marshal.UnsafeAddrOfPinnedArrayElement(bitSingle, 0)/* new IntPtr((void*)ipResults)*/);
//
eyemOpenWindow("eyemLib");
//类似于实时采集的图像
for (int i = 1; i < ipNum; i++)
{
//存放结果
int[] iArrRes = new int[tpRois.Count];
//fixed (int* ipResults = &iArrRes[0])
int iRet = eyemAOIForTSAV(tpImages[0], tpImages[i], hGlobal, tpRois.Count);
//过滤出有效信号(连续存在数帧以上才算,防止误触发),或者直接用iArrRes的值作为信号
//toSingleFilter(iArrRes, ref bitSingle);
//for (int j = 0; j < bitSingle.Length; j++)
//{
int iRet = eyemTrackFeature(tpImages[0], tpImages[i], hGlobal, tpRois.Count, Marshal.UnsafeAddrOfPinnedArrayElement(iArrRes, 0)/* new IntPtr((void*)ipResults)*/);
// //设定信号持续帧数阈值
// if (bitSingle[j] > 15)
// {
// //检测到信号
// Console.WriteLine("检测到:" + j + "处有信号");
// }
//}
//过滤出有效信号(连续存在数帧以上才算,防止误触发),或者直接用iArrRes的值作为信号
toSingleFilter(iArrRes, ref bitSingle);
for (int j = 0; j < bitSingle.Length; j++)
{
//设定信号持续帧数阈值
if (bitSingle[j] > 15)
{
//检测到信号
Console.WriteLine("检测到:" + j + "处有信号");
}
}
System.Threading.Thread.Sleep(80);
}
//释放资源
Marshal.FreeHGlobal(hGlobal);
......@@ -1101,11 +1105,8 @@ namespace eyemLib_Sharp
#region EyemImage转换成Bitmap
public static Bitmap eyemCvtToBitmap(EyemImage tpImage)
{
if (tpImage.vpImage == IntPtr.Zero)
throw new ArgumentNullException("图像不存在");
if (tpImage.iDepth != 0)
throw new ArgumentException("图像必须是8位无符号整型");
if (tpImage.vpImage == IntPtr.Zero || tpImage.iDepth != 0)
return null;
PixelFormat format;
......
......@@ -23,7 +23,7 @@ namespace eyemLib_Sharp
//}
//EyemLib.eyemTest2(fileNames);
for (int i = 0; i < 10000; i++)
for (int i = 0; i < 1000; i++)
{
foreach (var item in fileNames)
{
......@@ -31,10 +31,9 @@ namespace eyemLib_Sharp
}
}
//for (int i = 0; i < 1; i++)
//{
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\WeChat2.mp4");
//}
//for (int i = 0; i < 5000; i++)
......
......@@ -861,6 +861,21 @@ int eyemImageAbs(EyemImage tpImage, EyemImage &tpDstImg)
return FUNC_OK;
}
void eyemOpenWindow(const char *winname)
{
cv::namedWindow("eyemLib", cv::WINDOW_AUTOSIZE);
}
void eyemCloseWindow(const char *winname)
{
cv::destroyAllWindows();
}
//void eyemImageDisplay(const char *winname,)
//{
//
//}
void eyemImageFree(EyemImage &tpImage)
{
tpImage.iWidth = tpImage.iHeight = tpImage.iDepth = tpImage.iChannels = 0;
......
......@@ -805,6 +805,8 @@ extern "C" {
EXPORTS int eyemImageSub(EyemImage tpImageMinuend, EyemImage tpImageSubtrahend, EyemImage &tpDstImg);
EXPORTS int eyemImageDiv(EyemImage tpImage1, EyemImage tpImage2, EyemImage &tpDstImg);
EXPORTS int eyemImageAbs(EyemImage tpImage, EyemImage &tpDstImg);
EXPORTS void eyemOpenWindow(const char *winname);
EXPORTS void eyemCloseWindow(const char *winname);
EXPORTS void eyemImageFree(EyemImage &ipImage);
EXPORTS bool eyemVideoCaptureFree(IntPtr hObject);
......
此文件类型无法预览
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!