Commit 71f29f62 张士柳

1 个父辈 9e0af8f7
......@@ -722,7 +722,13 @@ namespace eyemLib_Sharp
private static extern int eyemCountObjectIrregularPartsE(EyemImage tpImage, string fileName, string ccTplName, double dMinScore, ref string pNumObj, out EyemImage tpDstImg);
//创建模板匹配模型
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, string ccTplName);
private static extern int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, string ccTplName);
//获取模板图像
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, out EyemImage tpDstImg);
//选取模板
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemMatchTemplateModel(EyemImage tpImage, string ccTplNames, ref string lpszTplName);
//读码程序
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
......@@ -904,18 +910,24 @@ namespace eyemLib_Sharp
//eyemEdgesPixel(ucpImage, 15);
#endregion
////EyemRect tpRoi = new EyemRect();
////tpRoi.iXs = 1231; tpRoi.iYs = 433;
////tpRoi.iWidth = 41;
////tpRoi.iHeight = 14;
EyemRect tpRoi = new EyemRect();
tpRoi.iXs = 0; tpRoi.iYs = 0;
tpRoi.iWidth = image.iWidth;
tpRoi.iHeight = image.iHeight;
tpRoi.iXs = 1026; tpRoi.iYs = 513;
tpRoi.iWidth = 82;
tpRoi.iHeight = 60;
//EyemRect tpRoi = new EyemRect();
//tpRoi.iXs = 200; tpRoi.iYs = 200;
//tpRoi.iWidth = image.iWidth - 400;
//tpRoi.iHeight = image.iHeight - 400;
//创建模板匹配模型
//flag = eyemCreateTemplateModel(image, tpRoi, "D://批量测试图像2//template.tpl");
double dMinScore = 0.75;
flag = eyemCreateTemplateModel(image, tpRoi, dMinScore, "D://模板文件//template.tpl");
string selectModel = "";
flag = eyemMatchTemplateModel(image, "D:\\模板文件", ref selectModel);
//flag = eyemAchvTemplateImage(image, tpRoi, out tpDstImg);
//
string pNumObj = "";
......@@ -924,14 +936,14 @@ namespace eyemLib_Sharp
//eyemCountObject(image, file.Replace(".png", ""), 35, 0, 100, 5, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularParts(image, file.Replace(".png", ""), 0.1, "IP_LARGE_PARTS", 100, 7, ref pNumObj, out tpDstImg);
//eyemCountObjectE(image, fileName, ref pNumObj, out tpDstImg);
eyemCountObjectIrregularPartsE(image, file.Replace(".png", ""), "D://批量测试图像模板文件//" + file.Replace(".png", "") + "_tpl.png", 0.75, ref pNumObj, out tpDstImg);
//eyemCountObjectIrregularPartsE(image, file.Replace(".png", ""), "D://批量测试图像模板文件//" + file.Replace(".png", "") + "_tpl.png", 0.75, ref pNumObj, out tpDstImg);
Bitmap bmp = eyemCvtToBitmap(tpDstImg);
//Bitmap bmp = eyemCvtToBitmap(tpDstImg);
if (bmp != null)
{
bmp.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
}
//if (bmp != null)
//{
// bmp.Save(System.Windows.Forms.Application.StartupPath + "\\ResOut\\" + file);
//}
////<解码测试
//int ipNum; EyemBarCode* tpResults;
......@@ -952,7 +964,6 @@ namespace eyemLib_Sharp
}
public static void eyemTestVideoCapture(string fileName)
{
List<EyemRect3> tpRois = new List<EyemRect3>();
......@@ -979,6 +990,13 @@ 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)*/);
//类似于实时采集的图像
for (int i = 1; i < ipNum; i++)
{
......@@ -1070,6 +1088,12 @@ 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位无符号整型");
PixelFormat format;
switch (tpImage.iChannels)
......@@ -1086,9 +1110,10 @@ namespace eyemLib_Sharp
default:
return null;
}
//所有算法输出结果图均为8位
Bitmap bitmap = new Bitmap(tpImage.iWidth, tpImage.iHeight, tpImage.iWidth * tpImage.iChannels, format, tpImage.vpImage);
Bitmap bitmap = new Bitmap(tpImage.iWidth, tpImage.iHeight, format);
//对于输出灰度图像
if (format == PixelFormat.Format8bppIndexed)
{
ColorPalette palette = bitmap.Palette;
......@@ -1099,6 +1124,29 @@ namespace eyemLib_Sharp
bitmap.Palette = palette;
}
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, tpImage.iWidth, tpImage.iHeight),
ImageLockMode.WriteOnly, format);
int srcStep = tpImage.iWidth * tpImage.iChannels;
int dstStep = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
try
{
for (int y = 0; y < tpImage.iHeight; y++)
{
long offsetSrc = (y * srcStep);
long offsetDst = (y * dstStep);
Buffer.MemoryCopy((byte*)(tpImage.vpImage.ToPointer()) + offsetSrc, (byte*)(bd.Scan0.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
}
}
finally
{
bitmap.UnlockBits(bd);
}
return bitmap;
}
#endregion
......
......@@ -836,7 +836,7 @@ extern "C" {
EXPORTS int eyemCountObjectE(EyemImage tpImage, const char *fileName, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularParts(EyemImage tpImage, const char *fileName, double dOffset, const char * ccSubType, int iMaxArea, int iWinSize, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemCountObjectIrregularPartsE(EyemImage tpImage, const char *fileName, const char *ccTplName, double dMinScore, LPSTR *lpszNumObj, EyemImage *tpDstImg);
EXPORTS int eyemCalcTemplateImage(EyemImage tpImage, EyemImage *tpDstImg);
EXPORTS int eyemAchvTemplateImage(EyemImage tpImage, EyemRect tpRoi, EyemImage *tpDstImg);
EXPORTS int eyemCreateTemplateModel(EyemImage tpImage, EyemRect tpRoi, double dMinScore, const char *ccTplName);
EXPORTS int eyemMatchTemplateModel(EyemImage tpImage, const char *ccTplNames, LPSTR *lpszTplName);
EXPORTS int eyemTrackFeature(EyemImage tpPrevImg, EyemImage tpNextImg, EyemRect3 *tpRois, int iRoiNum, int *ipResults);
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!