Commit 53a9dc28 张士柳

1 个父辈 a2f38dd2
...@@ -757,10 +757,10 @@ namespace eyemLib_Sharp ...@@ -757,10 +757,10 @@ namespace eyemLib_Sharp
private static extern int eyemAchvModelByName(string ccTplName, IntPtr hModelID, ref EyemModelID tpModelID); private static extern int eyemAchvModelByName(string ccTplName, IntPtr hModelID, ref EyemModelID tpModelID);
//插入模板 //插入模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemInsertModel(ref IntPtr hModelID, string ccTplName); private static extern int eyemInsertModel(IntPtr hModelID, string ccTplName);
//通过名称移除模板 //通过名称移除模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRemoveModelByName(ref IntPtr hModelID, string ccTplName); private static extern int eyemRemoveModelByName(IntPtr hModelID, string ccTplName);
//释放模板内存 //释放模板内存
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemReleaseModel(ref IntPtr hModelID); private static extern int eyemReleaseModel(ref IntPtr hModelID);
...@@ -772,7 +772,7 @@ namespace eyemLib_Sharp ...@@ -772,7 +772,7 @@ namespace eyemLib_Sharp
private static extern bool eyemDetectAndDecodeFree(IntPtr hObject); private static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
//背景变化跟踪 //背景变化跟踪
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize, IntPtr ipResults); private static extern int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize, IntPtr ipResults, out EyemImage tpDstImg);
//插件机 //插件机
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize); private static extern int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize);
...@@ -975,8 +975,8 @@ namespace eyemLib_Sharp ...@@ -975,8 +975,8 @@ namespace eyemLib_Sharp
tpRoi2.iWidth = 28; tpRoi2.iWidth = 28;
tpRoi2.iHeight = 9; tpRoi2.iHeight = 9;
//double matchDeg = 0.80; double matchDeg = 0.80;
//flag = eyemCreateTemplateModel(tpDstImg, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl")); flag = eyemCreateTemplateModel(tpDstImg, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl"));
//加载模板到内存 //加载模板到内存
IntPtr hModelID = IntPtr.Zero; IntPtr hModelID = IntPtr.Zero;
...@@ -987,7 +987,7 @@ namespace eyemLib_Sharp ...@@ -987,7 +987,7 @@ namespace eyemLib_Sharp
flag = eyemMatchTemplateModel(tpDstImg, hModelID, ref selectModel); flag = eyemMatchTemplateModel(tpDstImg, hModelID, ref selectModel);
//插入模板 //插入模板
flag = eyemInsertModel(ref hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl"); flag = eyemInsertModel(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//根据名称获取模板 //根据名称获取模板
EyemModelID tpModelID = new EyemModelID(); EyemModelID tpModelID = new EyemModelID();
...@@ -1015,7 +1015,7 @@ namespace eyemLib_Sharp ...@@ -1015,7 +1015,7 @@ namespace eyemLib_Sharp
//eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), "D:\\模板文件\\" + /*file.Replace(".png", ".tpl")*/"74d571ed-9fd4-4959-85dd-3195261e4b48.tpl", 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);
//移除模板 //移除模板
flag = eyemRemoveModelByName(ref 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);
...@@ -1073,7 +1073,7 @@ namespace eyemLib_Sharp ...@@ -1073,7 +1073,7 @@ namespace eyemLib_Sharp
flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg); flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//测试插入模板 //测试插入模板
//eyemInsertModel(ref hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl"); //eyemInsertModel(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
////测试获取模板 ////测试获取模板
//EyemModelID tpModelID0 = new EyemModelID(); //EyemModelID tpModelID0 = new EyemModelID();
...@@ -1094,6 +1094,8 @@ namespace eyemLib_Sharp ...@@ -1094,6 +1094,8 @@ namespace eyemLib_Sharp
Bitmap bitmap = eyemCvtToBitmap(tpModeImg); Bitmap bitmap = eyemCvtToBitmap(tpModeImg);
bitmap.Dispose();
//if (bitmap != null) //if (bitmap != null)
//{ //{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file); // bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
...@@ -1106,14 +1108,48 @@ namespace eyemLib_Sharp ...@@ -1106,14 +1108,48 @@ namespace eyemLib_Sharp
eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref pNumObj, out tpDstImg); eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref pNumObj, out tpDstImg);
//测试移除模板 //测试移除模板
//eyemRemoveModelByName(ref hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl"); //eyemRemoveModelByName(hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//free image //free image
eyemImageFree(ref tpDstImg); eyemImageFree(ref tpDstImg);
eyemImageFree(ref image); eyemImageFree(ref image);
sw.Stop(); sw.Stop();
Console.WriteLine("耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj); Console.WriteLine("耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj + ",所用模板:" + str);
}
public static void eyemReadProcssedImage(string fileName)
{
EyemImage image;
EyemImage tpDstImg = new EyemImage();
int flag = eyemImageRead(fileName, -1, out image);
if (flag != 0)
{
Console.WriteLine("读图失败!");
return;
}
EyemRect tpRoi = new EyemRect();
tpRoi.iXs = 200; tpRoi.iYs = 200;
tpRoi.iWidth = image.iWidth - 400;
tpRoi.iHeight = image.iHeight - 400;
//
string file = fileName.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries)[2];
//获取用于制作模板的图像
flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
if (bitmap != null)
{
bitmap.Save("D:\\ResOut\\" + file);
}
//建议释放掉
bitmap.Dispose();
} }
public static int eyemInitModelE(out IntPtr hModelID) public static int eyemInitModelE(out IntPtr hModelID)
...@@ -1158,9 +1194,11 @@ namespace eyemLib_Sharp ...@@ -1158,9 +1194,11 @@ namespace eyemLib_Sharp
//类似于实时采集的图像 //类似于实时采集的图像
for (int i = 1; i < ipNum; i++) for (int i = 1; i < ipNum; i++)
{ {
EyemImage tpDstImg;
//存放结果 //存放结果
int[] iArrRes = new int[tpRois.Count]; int[] iArrRes = new int[tpRois.Count];
int iRet = eyemAOIForTSAV(tpImages[0], tpImages[i], hGlobal, tpRois.Count); //int iRet = eyemAOIForTSAV(tpImages[0], tpImages[i], hGlobal, tpRois.Count);
int iRet = eyemTrackFeature(tpImages[0], tpImages[i], hGlobal, tpRois.Count, Marshal.UnsafeAddrOfPinnedArrayElement(iArrRes, 0), out tpDstImg);
//过滤出有效信号(连续存在数帧以上才算,防止误触发),或者直接用iArrRes的值作为信号 //过滤出有效信号(连续存在数帧以上才算,防止误触发),或者直接用iArrRes的值作为信号
//toSingleFilter(iArrRes, ref bitSingle); //toSingleFilter(iArrRes, ref bitSingle);
//for (int j = 0; j < bitSingle.Length; j++) //for (int j = 0; j < bitSingle.Length; j++)
...@@ -1172,6 +1210,7 @@ namespace eyemLib_Sharp ...@@ -1172,6 +1210,7 @@ namespace eyemLib_Sharp
// Console.WriteLine("检测到:" + j + "处有信号"); // Console.WriteLine("检测到:" + j + "处有信号");
// } // }
//} //}
eyemImageFree(ref tpDstImg);
System.Threading.Thread.Sleep(80); System.Threading.Thread.Sleep(80);
} }
//释放资源 //释放资源
......
...@@ -28,31 +28,38 @@ namespace eyemLib_Sharp ...@@ -28,31 +28,38 @@ namespace eyemLib_Sharp
// EyemLib.eyemReadImageTool(item); // EyemLib.eyemReadImageTool(item);
//} //}
//for (int i = 0; i < 1; i++) for (int i = 0; i < 1; i++)
//{
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\WeChat2.mp4");
//}
IntPtr hModelID;
EyemLib.eyemInitModelE(out hModelID);
for (int i = 0; i < 5000; i++)
{ {
//for (int j = 0; j < fileNames.Length; j++) EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\cap5.mp4");
//{
// EyemLib.eyemReadImageToolE(fileNames[j], hModelID);
//}
//并行测试
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = 3;
Parallel.ForEach(fileNames, po, fn =>
{
EyemLib.eyemReadImageToolE(fn, hModelID);
});
} }
EyemLib.eyemReleaseModelE(ref hModelID); //IntPtr hModelID;
//EyemLib.eyemInitModelE(out hModelID);
//int sum = 0;
//for (int i = 0; i < 5000; i++)
//{
// //for (int j = 0; j < fileNames.Length; j++)
// //{
// // EyemLib.eyemReadImageToolE(fileNames[j], hModelID);
// //}
// sum++;
// //并行测试
// ParallelOptions po = new ParallelOptions();
// po.MaxDegreeOfParallelism = 3;
// Parallel.ForEach(fileNames, po, fn =>
// {
// EyemLib.eyemReadImageToolE(fn, hModelID);
// });
// if (sum > 50)
// {
// sum = 0;
// Console.Clear();
// }
//}
//EyemLib.eyemReleaseModelE(ref hModelID);
Console.Write("请按任意键继续。。。"); Console.Write("请按任意键继续。。。");
Console.ReadKey(); Console.ReadKey();
......
...@@ -853,10 +853,10 @@ extern "C" { ...@@ -853,10 +853,10 @@ extern "C" {
EXPORTS int eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelID, LPSTR *lpszTplName); EXPORTS int eyemMatchTemplateModel(EyemImage tpImage, IntPtr hModelID, LPSTR *lpszTplName);
EXPORTS int eyemInitModel(const char *ccTplName, IntPtr *hModelID); EXPORTS int eyemInitModel(const char *ccTplName, IntPtr *hModelID);
EXPORTS int eyemAchvModelByName(const char *ccTplName, IntPtr hModelID, EyemModelID &tpModelID); EXPORTS int eyemAchvModelByName(const char *ccTplName, IntPtr hModelID, EyemModelID &tpModelID);
EXPORTS int eyemInsertModel(IntPtr &hModelID, const char *ccTplName); EXPORTS int eyemInsertModel(IntPtr hModelID, const char *ccTplName);
EXPORTS int eyemRemoveModelByName(IntPtr &hModelID, const char *ccTplName); EXPORTS int eyemRemoveModelByName(IntPtr hModelID, const char *ccTplName);
EXPORTS int eyemReleaseModel(IntPtr &hModelID); EXPORTS int eyemReleaseModel(IntPtr &hModelID);
EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults); 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 eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
constexpr double c = PI / 180.; constexpr double c = PI / 180.;
std::mutex mtx; std::mutex mtx_misc;
#endif/* __EYEM_MISC_H */ #endif/* __EYEM_MISC_H */
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!