Commit a2f38dd2 张士柳

1 个父辈 56be4c30
...@@ -755,6 +755,12 @@ namespace eyemLib_Sharp ...@@ -755,6 +755,12 @@ namespace eyemLib_Sharp
//通过名称获取模板 //通过名称获取模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)] [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
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)]
private static extern int eyemInsertModel(ref IntPtr hModelID, string ccTplName);
//通过名称移除模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemRemoveModelByName(ref 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);
...@@ -973,16 +979,30 @@ namespace eyemLib_Sharp ...@@ -973,16 +979,30 @@ namespace eyemLib_Sharp
//flag = eyemCreateTemplateModel(tpDstImg, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl")); //flag = eyemCreateTemplateModel(tpDstImg, tpRoi2, matchDeg, "D:\\模板文件\\" + file.Replace(".png", ".tpl"));
//加载模板到内存 //加载模板到内存
IntPtr hModelIDs = IntPtr.Zero; IntPtr hModelID = IntPtr.Zero;
flag = eyemInitModel("D:\\模板文件", out hModelIDs); flag = eyemInitModel("D:\\模板文件", out hModelID);
string selectModel = ""; string selectModel = "";
flag = eyemMatchTemplateModel(tpDstImg, hModelIDs, ref selectModel); flag = eyemMatchTemplateModel(tpDstImg, hModelID, ref selectModel);
//插入模板
flag = eyemInsertModel(ref hModelID, "D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl");
//根据名称获取模板 //根据名称获取模板
EyemModelID tpModelID = new EyemModelID(); EyemModelID tpModelID = new EyemModelID();
eyemAchvModelByName(selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelIDs, ref tpModelID); eyemAchvModelByName(selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref tpModelID);
//EyemImage tpModeImg = new EyemImage();
//tpModeImg.iChannels = 1; tpModeImg.iDepth = 0;
//tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.vpImage = tpModelID.vpImage;
//Bitmap bitmap = eyemCvtToBitmap(tpModeImg);
//if (bitmap != null)
//{
// bitmap.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
//最好释放掉,如果对象供其他接口使用要先释放 //最好释放掉,如果对象供其他接口使用要先释放
eyemImageFree(ref tpDstImg); eyemImageFree(ref tpDstImg);
...@@ -991,9 +1011,12 @@ namespace eyemLib_Sharp ...@@ -991,9 +1011,12 @@ namespace eyemLib_Sharp
//eyemCountObject(image, tpRoi, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg); //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); //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); //eyemCountObjectE(image, tpRoi, fileName, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelIDs, ref pNumObj, out tpDstImg); eyemCountObjectIrregularPartsE(image, tpRoi, file.Replace(".png", ""), selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, 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); //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");
//Bitmap bitmap = eyemCvtToBitmap(tpDstImg); //Bitmap bitmap = eyemCvtToBitmap(tpDstImg);
//if (bitmap != null) //if (bitmap != null)
...@@ -1016,7 +1039,7 @@ namespace eyemLib_Sharp ...@@ -1016,7 +1039,7 @@ namespace eyemLib_Sharp
Console.WriteLine("耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj); Console.WriteLine("耗时:" + sw.ElapsedMilliseconds.ToString() + ",结果:" + pNumObj);
//在关闭程序时释放 //在关闭程序时释放
eyemReleaseModel(ref hModelIDs); eyemReleaseModel(ref hModelID);
//free image //free image
eyemImageFree(ref tpDstImg); eyemImageFree(ref tpDstImg);
eyemImageFree(ref image); eyemImageFree(ref image);
...@@ -1049,6 +1072,13 @@ namespace eyemLib_Sharp ...@@ -1049,6 +1072,13 @@ 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");
////测试获取模板
//EyemModelID tpModelID0 = new EyemModelID();
//eyemAchvModelByName("D:\\模板文件及图像\\df871193-6632-48f9-abfe-540c3fc49c3f.tpl", hModelID, ref tpModelID0);
string selectModel = ""; string selectModel = "";
flag = eyemMatchTemplateModel(tpDstImg, hModelID, ref selectModel); flag = eyemMatchTemplateModel(tpDstImg, hModelID, ref selectModel);
...@@ -1056,11 +1086,13 @@ namespace eyemLib_Sharp ...@@ -1056,11 +1086,13 @@ namespace eyemLib_Sharp
EyemModelID tpModelID = new EyemModelID(); EyemModelID tpModelID = new EyemModelID();
eyemAchvModelByName(selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref tpModelID); eyemAchvModelByName(selectModel.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)[0], hModelID, ref tpModelID);
//EyemImage tpModeImg = new EyemImage(); EyemImage tpModeImg = new EyemImage();
//tpModeImg.iChannels = 1; tpModeImg.iDepth = 0; tpModeImg.iChannels = 1; tpModeImg.iDepth = 0;
//tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.vpImage = tpModelID.vpImage; tpModeImg.iWidth = tpModelID.iWidth; tpModeImg.iHeight = tpModelID.iHeight; tpModeImg.vpImage = tpModelID.vpImage;
//Bitmap bitmap = eyemCvtToBitmap(tpModeImg); string str = Marshal.PtrToStringAnsi(tpModelID.lpszName);
Bitmap bitmap = eyemCvtToBitmap(tpModeImg);
//if (bitmap != null) //if (bitmap != null)
//{ //{
...@@ -1073,6 +1105,9 @@ namespace eyemLib_Sharp ...@@ -1073,6 +1105,9 @@ 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");
//free image //free image
eyemImageFree(ref tpDstImg); eyemImageFree(ref tpDstImg);
eyemImageFree(ref image); eyemImageFree(ref image);
......
...@@ -23,19 +23,33 @@ namespace eyemLib_Sharp ...@@ -23,19 +23,33 @@ namespace eyemLib_Sharp
//} //}
//EyemLib.eyemTest2(fileNames); //EyemLib.eyemTest2(fileNames);
//foreach (var item in fileNames)
//{
// EyemLib.eyemReadImageTool(item);
//}
//for (int i = 0; i < 1; i++) //for (int i = 0; i < 1; i++)
//{ //{
// EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\WeChat2.mp4"); // EyemLib.eyemTestVideoCapture("D:\\插件完成检测\\视频\\WeChat2.mp4");
//} //}
IntPtr hModelID; IntPtr hModelID;
EyemLib.eyemInitModelE(out hModelID); EyemLib.eyemInitModelE(out hModelID);
for (int i = 0; i < 5000; i++) for (int i = 0; i < 5000; i++)
{ {
for (int j = 0; j < fileNames.Length; j++) //for (int j = 0; j < fileNames.Length; j++)
//{
// EyemLib.eyemReadImageToolE(fileNames[j], hModelID);
//}
//并行测试
ParallelOptions po = new ParallelOptions();
po.MaxDegreeOfParallelism = 3;
Parallel.ForEach(fileNames, po, fn =>
{ {
EyemLib.eyemReadImageToolE(fileNames[j], hModelID); EyemLib.eyemReadImageToolE(fn, hModelID);
} });
} }
EyemLib.eyemReleaseModelE(ref hModelID); EyemLib.eyemReleaseModelE(ref hModelID);
......
...@@ -1225,6 +1225,7 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam ...@@ -1225,6 +1225,7 @@ int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, const char *ccFileNam
bool eyemDetectAndDecodeFree(IntPtr hObject) bool eyemDetectAndDecodeFree(IntPtr hObject)
{ {
std::vector<EyemBarCode> *tpResults = reinterpret_cast<std::vector<EyemBarCode>*>(hObject); std::vector<EyemBarCode> *tpResults = reinterpret_cast<std::vector<EyemBarCode>*>(hObject);
//清空容器 //清空容器
tpResults->clear(); tpResults->clear();
......
...@@ -894,9 +894,13 @@ bool eyemVideoCaptureFree(IntPtr hObject) ...@@ -894,9 +894,13 @@ bool eyemVideoCaptureFree(IntPtr hObject)
for (std::vector<EyemImage>::iterator it = tpImages->begin(); it != tpImages->end(); ++it) for (std::vector<EyemImage>::iterator it = tpImages->begin(); it != tpImages->end(); ++it)
{ {
(*it).iWidth = (*it).iHeight = (*it).iDepth = (*it).iChannels = 0; EyemImage *tpImage = &(*it);
free((*it).vpImage), (*it).vpImage = NULL; tpImage->iWidth = tpImage->iHeight = tpImage->iDepth = tpImage->iChannels = 0;
free(tpImage->vpImage), tpImage->vpImage = NULL;
} }
//清空
tpImages->clear();
//释放 //释放
delete tpImages; delete tpImages;
tpImages = NULL; tpImages = NULL;
......
...@@ -853,8 +853,8 @@ extern "C" { ...@@ -853,8 +853,8 @@ 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(const char *ccTplName, IntPtr hModelID, EyemModelID &tpModelID); EXPORTS int eyemInsertModel(IntPtr &hModelID, const char *ccTplName);
EXPORTS int eyemInsertModel(const char *ccTplName, IntPtr hModelID, EyemModelID &tpModelID); 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);
EXPORTS int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum); EXPORTS int eyemAOIForTSAV(EyemImage tpRefImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum);
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
constexpr double c = PI / 180.; constexpr double c = PI / 180.;
//std::mutex mtx; std::mutex mtx;
#endif/* __EYEM_MISC_H */ #endif/* __EYEM_MISC_H */
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!