Commit 79de92b9 张士柳

1 个父辈 37ea7eac
...@@ -7,36 +7,42 @@ namespace eyemLib_Sharp ...@@ -7,36 +7,42 @@ namespace eyemLib_Sharp
{ {
public unsafe class UnmanagedBitmap : IDisposable public unsafe class UnmanagedBitmap : IDisposable
{ {
#region 接口
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemImageRead(string filename, int iFalgs, out EyemImage tpImage);
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemImageFree(ref EyemImage tpImage);
#endregion
private EyemImage image; private EyemImage image;
public EyemImage Image public EyemImage Image
{ {
get { return image; } get { return image; }
} }
/// <summary>
/// 初始化新实例
/// </summary>
public UnmanagedBitmap() public UnmanagedBitmap()
{ {
image = new EyemImage(); image = new EyemImage();
} }
/// <summary>
/// 从指定文件初始化UnmanagedBitmap的新实例(支持BMP、DIB、PNG、PBM、PGM、PPM、EXR、JPEG、JPG、JPE、TIF等格式图像)
/// </summary>
/// <param name="fileName">文件名</param>
public UnmanagedBitmap(string fileName) public UnmanagedBitmap(string fileName)
{ {
eyemImageRead(fileName, -1, out image); eyemImageRead(fileName, -1, out image);
} }
/// <summary>
/// 从Bitmap初始化Unmanaged新实例(GDI不支持除8位以外深度的图像;若要加载不同深度图像请使用从文件名加载)
/// </summary>
/// <param name="bitmap"></param>
public UnmanagedBitmap(Bitmap bitmap) public UnmanagedBitmap(Bitmap bitmap)
{ {
mustbeDispose = true;
image = eyemCvtToEyemImage(bitmap); image = eyemCvtToEyemImage(bitmap);
} }
/// <summary>
private bool mustbeDispose = false; /// 隐式转换成EyemImage
/// </summary>
/// <param name="operand"></param>
public static implicit operator EyemImage(UnmanagedBitmap operand)
{
return operand.Image;
}
~UnmanagedBitmap() ~UnmanagedBitmap()
{ {
...@@ -55,86 +61,39 @@ namespace eyemLib_Sharp ...@@ -55,86 +61,39 @@ namespace eyemLib_Sharp
{ {
// dispose managed resources // dispose managed resources
} }
if (mustbeDispose) //这里特别修改了eyemCvtToEyemImage的内存分配,因此皆可以由此接口释放
{
image.iChannels = image.iDepth = image.iHeight = image.iWidth = 0;
Marshal.FreeHGlobal(image.vpImage);
image.vpImage = IntPtr.Zero;
}
else
{
eyemImageFree(ref image); eyemImageFree(ref image);
} }
}
#region EyemImageBitmap相互转换
public static Bitmap eyemCvtToBitmap(EyemImage tpImage)
{
if (tpImage.vpImage == IntPtr.Zero || tpImage.iDepth != 0)
return null;
PixelFormat format;
switch (tpImage.iChannels)
{
case 1:
format = PixelFormat.Format8bppIndexed;
break;
case 3:
format = PixelFormat.Format24bppRgb;
break;
case 4:
format = PixelFormat.Format32bppArgb;
break;
default:
return null;
}
Bitmap bitmap = new Bitmap(tpImage.iWidth, tpImage.iHeight, format);
//对于输出灰度图像
if (format == PixelFormat.Format8bppIndexed)
{
ColorPalette palette = bitmap.Palette;
for (int i = 0; i < 256; i++)
{
palette.Entries[i] = Color.FromArgb(i, i, i);
}
bitmap.Palette = palette;
}
//锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, tpImage.iWidth, tpImage.iHeight),
ImageLockMode.WriteOnly, format);
try
{
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels; #region 接口
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
for (int y = 0; y < tpImage.iHeight; y++) private static extern int eyemImageRead(string filename, int iFalgs, out EyemImage tpImage);
{ [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
long offsetSrc = (y * tpImage.iWidth * tpImage.iChannels); private static extern void eyemImageFree(ref EyemImage tpImage);
long offsetDst = (y * pd); [DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemCvtImageType(EyemImage tpImage, string ccSubType, double alpha, double beta, ref EyemImage tpDstImg);
Buffer.MemoryCopy((byte*)(tpImage.vpImage.ToPointer()) + offsetSrc, (byte*)(bd.Scan0.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy); /// <summary>
} /// 从进程中的非托管内存分配指定长度的内存
} /// </summary>
finally /// <param name="cb">长度</param>
{ /// <returns>地址</returns>
bitmap.UnlockBits(bd); [DllImport("eyemLib.dll", CallingConvention = CallingConvention.Cdecl)]
} private static extern IntPtr eyemMallocMemBlock(int cb);
return bitmap; /// <summary>
} /// 释放从非托管内存中分配的内存
/// </summary>
/// <param name="block">地址</param>
[DllImport("eyemLib.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern void eyemFreeMemBlock(IntPtr block);
#endregion
#region EyemImageBitmap相互转换
public static EyemImage eyemCvtToEyemImage(Bitmap bitmap) public static EyemImage eyemCvtToEyemImage(Bitmap bitmap)
{ {
EyemImage tpImage = new EyemImage(); EyemImage tpImage = new EyemImage();
//锁定数据区 //锁定数据区
BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly, bitmap.PixelFormat); ImageLockMode.ReadOnly, bitmap.PixelFormat);
switch (bitmap.PixelFormat) switch (bitmap.PixelFormat)
{ {
case PixelFormat.Format8bppIndexed: case PixelFormat.Format8bppIndexed:
...@@ -153,19 +112,16 @@ namespace eyemLib_Sharp ...@@ -153,19 +112,16 @@ namespace eyemLib_Sharp
tpImage.iDepth = 0; tpImage.iDepth = 0;
//图像尺寸 //图像尺寸
tpImage.iWidth = bitmap.Width; tpImage.iHeight = bitmap.Height; tpImage.iWidth = bitmap.Width; tpImage.iHeight = bitmap.Height;
//分配内存(释放不是用eyemImageFree,用Marshal.FreeHGlobal(tpImage.vpImage)) //分配内存(此函数分配的内存可由默认接口释放)
tpImage.vpImage = Marshal.AllocHGlobal(bd.Stride * bd.Height); tpImage.vpImage = eyemMallocMemBlock(bd.Stride * bd.Height);
try try
{ {
int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4; int pd = ((tpImage.iWidth * tpImage.iChannels) + 3) / 4 * 4;
long bytesToCopy = tpImage.iWidth * tpImage.iChannels; long bytesToCopy = tpImage.iWidth * tpImage.iChannels;
for (int y = 0; y < tpImage.iHeight; y++) for (int y = 0; y < tpImage.iHeight; y++)
{ {
long offsetSrc = y * pd; long offsetSrc = y * pd;
long offsetDst = y * tpImage.iWidth * tpImage.iChannels; long offsetDst = y * tpImage.iWidth * tpImage.iChannels;
Buffer.MemoryCopy((byte*)(bd.Scan0.ToPointer()) + offsetSrc, (byte*)(tpImage.vpImage.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy); Buffer.MemoryCopy((byte*)(bd.Scan0.ToPointer()) + offsetSrc, (byte*)(tpImage.vpImage.ToPointer()) + offsetDst, bytesToCopy, bytesToCopy);
} }
} }
......
...@@ -141,7 +141,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine ...@@ -141,7 +141,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
std::vector<EyemOcsDXY> *tpResults = new std::vector<EyemOcsDXY>(); std::vector<EyemOcsDXY> *tpResults = new std::vector<EyemOcsDXY>();
for (int n = 1; n <= nCalipers; n++) for (int n = 1; n <= nCalipers; n++)
{ {
float *pMag = new float[szMap.width*szMap.height * sizeof(float_t)]; float *pMag = new float[szMap.width*szMap.height];
for (int m = 0; m <= iCapWidth; m++) for (int m = 0; m <= iCapWidth; m++)
{ {
float plusX, plusY; float plusX, plusY;
...@@ -204,7 +204,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine ...@@ -204,7 +204,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
cv::Mat projectedMap; cv::Mat projectedMap;
cv::reduce(interMap, projectedMap, 0, cv::REDUCE_AVG, CV_32F); cv::reduce(interMap, projectedMap, 0, cv::REDUCE_AVG, CV_32F);
//差分过滤(TODO:加高斯滤波) //差分过滤(TODO:加高斯滤波)
float *pFilteredMap = new float[szMap.width * sizeof(float_t)]; float *pFilteredMap = new float[szMap.width];
cv::Mat filteredMap(cv::Size(szMap.width, 1), CV_32FC1, pFilteredMap); cv::Mat filteredMap(cv::Size(szMap.width, 1), CV_32FC1, pFilteredMap);
cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, cv::Mat::ones(1, 1, CV_32F)); cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, cv::Mat::ones(1, 1, CV_32F));
//投影峰值查找 //投影峰值查找
...@@ -307,6 +307,11 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine ...@@ -307,6 +307,11 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
} }
} }
#endif #endif
//遍历结果
//for (auto it = tpResults->begin(); it != tpResults->end(); ++it)
//{
// it->dX; it->dY;
//}
//释放资源(Tips:当存在越界时候在用free释放时会报错) //释放资源(Tips:当存在越界时候在用free释放时会报错)
delete[] filterK; delete[] filterK;
filterK = NULL; filterK = NULL;
...@@ -366,7 +371,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int ...@@ -366,7 +371,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
float x = float(tpPoint.dX + (float)iRadius*cos(t)); float x = float(tpPoint.dX + (float)iRadius*cos(t));
float y = float(tpPoint.dY + (float)iRadius*sin(t)); float y = float(tpPoint.dY + (float)iRadius*sin(t));
//采样图像 //采样图像
float *pMag = new float[szMap.width*szMap.height * sizeof(float_t)]; float *pMag = new float[szMap.width*szMap.height];
for (float n = -(float)iCapWidth / 2.0f; n <= (float)iCapWidth / 2.0f; n += 1.0f, m++) for (float n = -(float)iCapWidth / 2.0f; n <= (float)iCapWidth / 2.0f; n += 1.0f, m++)
{ {
for (int iR = -iCapLength; iR <= iCapLength; iR++) { for (int iR = -iCapLength; iR <= iCapLength; iR++) {
...@@ -402,7 +407,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int ...@@ -402,7 +407,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
cv::Mat projectedMap; cv::Mat projectedMap;
cv::reduce(interMap, projectedMap, 0, cv::REDUCE_AVG, CV_32F); cv::reduce(interMap, projectedMap, 0, cv::REDUCE_AVG, CV_32F);
//差分过滤(TODO:加高斯滤波) //差分过滤(TODO:加高斯滤波)
float *pFilteredMap = new float[szMap.width * sizeof(float_t)]; float *pFilteredMap = new float[szMap.width];
cv::Mat filteredMap(cv::Size(szMap.width, 1), CV_32FC1, pFilteredMap); cv::Mat filteredMap(cv::Size(szMap.width, 1), CV_32FC1, pFilteredMap);
cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, cv::Mat::ones(1, 1, CV_32F)); cv::sepFilter2D(projectedMap, filteredMap, CV_32F, whalf, cv::Mat::ones(1, 1, CV_32F));
//投影峰值查找 //投影峰值查找
...@@ -581,7 +586,7 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap ...@@ -581,7 +586,7 @@ int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSap
return FUNC_OK; return FUNC_OK;
} }
bool eyemEdge1dGenMeasureFree(IntPtr hObject) bool eyemEdge1dGenFree(IntPtr hObject)
{ {
std::vector<EyemOcsDXY> *tpEdges = reinterpret_cast<std::vector<EyemOcsDXY>*>(hObject); std::vector<EyemOcsDXY> *tpEdges = reinterpret_cast<std::vector<EyemOcsDXY>*>(hObject);
delete tpEdges; delete tpEdges;
......
...@@ -779,6 +779,3 @@ int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY * taPoint, int iCalcMode, doubl ...@@ -779,6 +779,3 @@ int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY * taPoint, int iCalcMode, doubl
return FUNC_OK; return FUNC_OK;
} }
...@@ -91,7 +91,8 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, ...@@ -91,7 +91,8 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
{ {
if (std::strlen(filename) == 0) if (std::strlen(filename) == 0)
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
//
//tpImage->iChannels = 1; tpImage->iDepth = 2; tpImage->iWidth = iWidth; tpImage->iHeight = iHeight;
FILE *fp = fopen(filename, "rb+"); FILE *fp = fopen(filename, "rb+");
if (NULL != fp) if (NULL != fp)
{ {
...@@ -118,7 +119,6 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth, ...@@ -118,7 +119,6 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
} }
else else
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
//关闭文件 //关闭文件
fclose(fp); fclose(fp);
return FUNC_OK; return FUNC_OK;
...@@ -262,11 +262,9 @@ bool eyemVideoCaptureFree(IntPtr hObject) ...@@ -262,11 +262,9 @@ bool eyemVideoCaptureFree(IntPtr hObject)
} }
//清空 //清空
tpImages->clear(); tpImages->clear();
//释放 //释放
delete tpImages; delete tpImages;
tpImages = NULL; tpImages = NULL;
return true; return true;
} }
......
...@@ -688,7 +688,7 @@ extern "C" { ...@@ -688,7 +688,7 @@ extern "C" {
EXPORTS int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject); EXPORTS int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int iCapLength, int iCapWidth, int nCalipers, int nFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int iFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject); EXPORTS int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLineEd, int iCapLength, int iCapWidth, int nCalipers, int iFilterSize, int iSearchDirec, double dAmpThreshold, const char *ccTransition, IntPtr *hObject);
EXPORTS int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSapWidth); EXPORTS int eyemPolarTrans(EyemImage tpImage, EyemOcsDXY tpCenter, int iRadius, int iSapWidth);
EXPORTS bool eyemEdge1dGenMeasureFree(IntPtr hObject); EXPORTS bool eyemEdge1dGenFree(IntPtr hObject);
#ifdef __cplusplus #ifdef __cplusplus
} }
...@@ -925,7 +925,7 @@ extern "C" { ...@@ -925,7 +925,7 @@ extern "C" {
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, EyemImage *tpDstImg); EXPORTS int eyemTrackFeature(EyemImage tpImage, EyemImage tpMask, EyemRect tpRoi, EyemRect *tpRois, int iRoiNum, EyemHSVModel tpHSVModel, 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);
EXPORTS int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy = false); EXPORTS int eyemMarkerTracing(EyemImage tpImage, EyemHSVModel tpHSVModel, EyemOcsFXYR *tpCircle, EyemImage *tpDstImg, bool bHighAccuracy = false);
EXPORTS int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, EyemOcsDXYR *tpCircle, EyemImage *tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false); EXPORTS int eyemDetectCircleUseHough(EyemImage tpImage, EyemRect tpRoi, EyemRect limRoi, EyemOcsDXYR *tpCircle, EyemImage *tpDstImg, double dp, double dMinDist, double dParam1, double dParam2, double dMinRadius, double dMaxRadius, int iMethod = 3, bool useValLimit = false);
......
此文件类型无法预览
...@@ -74,8 +74,8 @@ ...@@ -74,8 +74,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental> <LinkIncremental>true</LinkIncremental>
<IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;D:\darknet\include;D:\3rdparty\pthreads\include;$(IncludePath)</IncludePath> <IncludePath>D:\opencv420\build\include;D:\opencv420\build\include\opencv2;D:\tbb2017_20170604oss\include;D:\zxing-cpp-master\core\src;D:\zxing-cpp-master\opencv\src;$(IncludePath)</IncludePath>
<LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;D:\darknet\lib;D:\3rdparty\pthreads\lib;$(LibraryPath)</LibraryPath> <LibraryPath>D:\opencv420\build\x64\vc14\lib;D:\tbb2017_20170604oss\lib\intel64\vc14;D:\zxing-cpp-master\build\Debug;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt> <TargetExt>.dll</TargetExt>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
<Link> <Link>
<SubSystem>Console</SubSystem> <SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;darknetd.lib;pthreadVC2.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>libdmtx.lib;libzxing-debug.lib;libdecoded.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
......
...@@ -410,14 +410,11 @@ int eyemBitwiseNot(EyemImage &tpImage) ...@@ -410,14 +410,11 @@ int eyemBitwiseNot(EyemImage &tpImage)
int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg) int eyemCvtImageType(EyemImage tpImage, const char *ccSubType, double alpha, double beta, EyemImage &tpDstImg)
{ {
CV_Assert(NULL != tpImage.vpImage); CV_Assert(NULL != tpImage.vpImage);
cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); cv::Mat _src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
//在这里重新创建 //在这里重新创建
if (NULL != tpDstImg.vpImage) { if (NULL != tpDstImg.vpImage) {
_free(tpDstImg); _free(tpDstImg);
} }
//内存尺寸(图像数据类型转换不涉及通道、尺寸) //内存尺寸(图像数据类型转换不涉及通道、尺寸)
int _Size = tpImage.iWidth*tpImage.iHeight*tpImage.iChannels; int _Size = tpImage.iWidth*tpImage.iHeight*tpImage.iChannels;
......
...@@ -139,8 +139,6 @@ double shape_based_matching::find_shape_model(cv::Mat tpImage, double minScore, ...@@ -139,8 +139,6 @@ double shape_based_matching::find_shape_model(cv::Mat tpImage, double minScore,
} }
draw_match_shapes(showMat, resultPoint, cv::Scalar(151, 243, 121), 1); draw_match_shapes(showMat, resultPoint, cv::Scalar(151, 243, 121), 1);
} }
cv::imwrite("result.png", showMat);
return 0; return 0;
} }
...@@ -154,8 +152,11 @@ void shape_based_matching::draw_match_shapes(cv::Mat &showMat, cv::Point cog, cv ...@@ -154,8 +152,11 @@ void shape_based_matching::draw_match_shapes(cv::Mat &showMat, cv::Point cog, cv
contours.push_back(results[i].Offset + cv::Point2d(cog)); contours.push_back(results[i].Offset + cv::Point2d(cog));
} }
for (auto&point : contours) { for (auto&point : contours) {
if (point.x > 0 && point.x < showMat.cols&&point.y>0 && point.y < showMat.rows)
{
showMat.at<cv::Vec3b>(point) = cv::Vec3b((uchar)color[0], (uchar)color[1], (uchar)color[2]); showMat.at<cv::Vec3b>(point) = cv::Vec3b((uchar)color[0], (uchar)color[1], (uchar)color[2]);
} }
}
} }
int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize, bool bL2gradient) int eyemMakeShapeModel(EyemImage tpImage, double dContrast, double dMinContrast, int iApertureSize, bool bL2gradient)
......
...@@ -122,40 +122,40 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, Eyem ...@@ -122,40 +122,40 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, Eyem
} }
#ifdef _DEBUG #ifdef _DEBUG
int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype) //int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype)
{ //{
try { // try {
pClassifier = cv::makePtr<YoloDarknet>(classifierConfigPath, classifierModelPath, ntype); // pClassifier = cv::makePtr<YoloDarknet>(classifierConfigPath, classifierModelPath, ntype);
} // }
catch (const std::exception& e) { // catch (const std::exception& e) {
std::cout << e.what() << std::endl; // std::cout << e.what() << std::endl;
return FUNC_CANNOT_CALC; // return FUNC_CANNOT_CALC;
} // }
return FUNC_OK; // return FUNC_OK;
} //}
//
int eyemClassifier(EyemImage tpImage) //int eyemClassifier(EyemImage tpImage)
{ //{
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone(); // cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
if (src.empty()) { // if (src.empty()) {
return FUNC_IMAGE_NOT_EXIST; // return FUNC_IMAGE_NOT_EXIST;
} // }
cv::Mat input; // cv::Mat input;
int incn = src.channels(); // int incn = src.channels();
if (incn == 4) { // if (incn == 4) {
cv::cvtColor(src, input, cv::COLOR_BGRA2BGR); // cv::cvtColor(src, input, cv::COLOR_BGRA2BGR);
} // }
else if (incn == 1) { // else if (incn == 1) {
cv::cvtColor(src, input, cv::COLOR_GRAY2BGR);//根据配置支持三通道图像 // cv::cvtColor(src, input, cv::COLOR_GRAY2BGR);//根据配置支持三通道图像
} // }
else { // else {
input = src; // input = src;
} // }
pClassifier->setInput(input, 0.4, 5); // pClassifier->setInput(input, 0.4, 5);
auto predict = std::vector<int>(); auto confidence = std::vector<float>(); auto bbox = std::vector<cv::Rect>(); // auto predict = std::vector<int>(); auto confidence = std::vector<float>(); auto bbox = std::vector<cv::Rect>();
pClassifier->forward(predict, confidence, bbox); // pClassifier->forward(predict, confidence, bbox);
std::cout << "run_end!" << std::endl; // std::cout << "run_end!" << std::endl;
return FUNC_OK; // return FUNC_OK;
} //}
#endif #endif
\ No newline at end of file \ No newline at end of file
...@@ -25,7 +25,7 @@ protected: ...@@ -25,7 +25,7 @@ protected:
cv::Ptr<NNDetector> pNNDetector; cv::Ptr<NNDetector> pNNDetector;
#ifdef _DEBUG #ifdef _DEBUG
cv::Ptr<YoloDarknet> pClassifier; //cv::Ptr<YoloDarknet> pClassifier;
#endif #endif
#endif/* __EYEMNNDETECTOR_H */ #endif/* __EYEMNNDETECTOR_H */
\ No newline at end of file \ No newline at end of file
...@@ -200,8 +200,8 @@ public: ...@@ -200,8 +200,8 @@ public:
const __m128i mask2 = _mm_setr_epi8(5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10); const __m128i mask2 = _mm_setr_epi8(5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15, 10);
const __m128i mask3 = _mm_setr_epi8(10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15); const __m128i mask3 = _mm_setr_epi8(10, 5, 0, 11, 6, 1, 12, 7, 2, 13, 8, 3, 14, 9, 4, 15);
const __m128i bmask1 = _mm_setr_epi8(0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0); const __m128i bmask1 = _mm_setr_epi8(0, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, -1, 0);//原255
const __m128i bmask2 = _mm_setr_epi8(255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255, 0, 255); const __m128i bmask2 = _mm_setr_epi8(-1, -1, 0, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1, -1, 0, -1);
a = _mm_shuffle_epi8(a, mask1); a = _mm_shuffle_epi8(a, mask1);
b = _mm_shuffle_epi8(b, mask2); b = _mm_shuffle_epi8(b, mask2);
...@@ -379,27 +379,8 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do ...@@ -379,27 +379,8 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do
if (image.empty()) { if (image.empty()) {
return FUNC_IMAGE_NOT_EXIST; return FUNC_IMAGE_NOT_EXIST;
} }
//std::vector<cv::Mat> mvs(3);
//cv::split(image, mvs);
//mvs[0] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_b.png", cv::IMREAD_GRAYSCALE);
//mvs[1] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_g.png", 0);
//mvs[2] = cv::imread("C:\\Users\\nzslw\\OneDrive\\程序\\VSProject\\eyemLib\\x64\\Debug\\Portada_paper_r.png", 0);
cv::Mat dest; cv::Mat dest;
//cv::blur(image, dest, cv::Size(3, 3)); nonLocalMeansFilter_SSE(image, dest, cv::Size(3, 3), cv::Size(5, 5), 10.0, -1, 0);
//cv::merge(mvs, dest);
//for (int i = 0; i < 10; i++)
//{
//nonLocalMeansFilter_SSE(image, dest, cv::Size(3, 3), cv::Size(5, 5), 10.0, -1, 0);
//image = dest;
//}
dest = image < 220;
cv::imwrite("Portada_paper5.png", dest);
return FUNC_OK; return FUNC_OK;
} }
......
...@@ -83,41 +83,41 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) { ...@@ -83,41 +83,41 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
#ifdef _DEBUG #ifdef _DEBUG
class YoloDarknet::Impl { //class YoloDarknet::Impl {
public: //public:
Impl() {} // Impl() {}
~Impl() {} // ~Impl() {}
//
std::shared_ptr<DarkNet> net_; // std::shared_ptr<DarkNet> net_;
}; //};
//
YoloDarknet::YoloDarknet(const std::string& config_path, const std::string& model_path, const int ntype) //YoloDarknet::YoloDarknet(const std::string& config_path, const std::string& model_path, const int ntype)
{ //{
p = cv::makePtr<YoloDarknet::Impl>(); // p = cv::makePtr<YoloDarknet::Impl>();
if (!config_path.empty() && !model_path.empty()) { // if (!config_path.empty() && !model_path.empty()) {
p->net_ = std::make_shared<DarkNet>(); // p->net_ = std::make_shared<DarkNet>();
p->net_->init(config_path, model_path, ntype); // p->net_->init(config_path, model_path, ntype);
} // }
else { // else {
p->net_ = NULL; // p->net_ = NULL;
} // }
} //}
//
void YoloDarknet::setInput(cv::Mat& img, float threshold, int topk) { //void YoloDarknet::setInput(cv::Mat& img, float threshold, int topk) {
topk_ = topk; // topk_ = topk;
p->net_->setPreferableParams(threshold, topk); // p->net_->setPreferableParams(threshold, topk);
p->net_->forward(img); // p->net_->forward(img);
} //}
//
void YoloDarknet::forward(std::vector<int> &outputPredict, std::vector<float> &outputConfidence, std::vector<cv::Rect> &outputBoxes) //void YoloDarknet::forward(std::vector<int> &outputPredict, std::vector<float> &outputConfidence, std::vector<cv::Rect> &outputBoxes)
{ //{
auto bbox = std::vector<cv::Rect>(); // auto bbox = std::vector<cv::Rect>();
int *predicts = new int[topk_]; float *confidence = new float[topk_]; // int *predicts = new int[topk_]; float *confidence = new float[topk_];
p->net_->getResult(predicts, confidence, &bbox); // p->net_->getResult(predicts, confidence, &bbox);
for (int top = 0; top < topk_; top++) outputPredict.push_back(predicts[top]), outputConfidence.push_back(confidence[top]); // for (int top = 0; top < topk_; top++) outputPredict.push_back(predicts[top]), outputConfidence.push_back(confidence[top]);
for (auto&box : bbox) { // for (auto&box : bbox) {
outputBoxes.push_back(box); // outputBoxes.push_back(box);
} // }
delete[] predicts; predicts = NULL; delete[] confidence; confidence = NULL; // delete[] predicts; predicts = NULL; delete[] confidence; confidence = NULL;
} //}
#endif #endif
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "opencv2/imgproc.hpp" #include "opencv2/imgproc.hpp"
#ifdef _DEBUG #ifdef _DEBUG
#include <darknet.h> //#include <darknet.h>
#include <yolo_class.h> //#include <yolo_class.h>
#endif #endif
class YoloWrapper class YoloWrapper
...@@ -27,20 +27,20 @@ private: ...@@ -27,20 +27,20 @@ private:
}; };
#ifdef _DEBUG #ifdef _DEBUG
class YoloDarknet //class YoloDarknet
{ //{
public: //public:
YoloDarknet(const std::string& config_path = "", const std::string& model_path = "", const int ntype = 0); // YoloDarknet(const std::string& config_path = "", const std::string& model_path = "", const int ntype = 0);
YoloDarknet() {}; // YoloDarknet() {};
//
void setInput(cv::Mat& img, float threshold, int topk = 2); // void setInput(cv::Mat& img, float threshold, int topk = 2);
void forward(std::vector<int> &outputPredict, std::vector<float> &outputConfidence, std::vector<cv::Rect> &outputBoxes); // void forward(std::vector<int> &outputPredict, std::vector<float> &outputConfidence, std::vector<cv::Rect> &outputBoxes);
private: //private:
int topk_ = 0; // int topk_ = 0;
protected: //protected:
class Impl; // class Impl;
cv::Ptr<Impl> p; // cv::Ptr<Impl> p;
}; //};
#endif #endif
#endif/* __YOLOWRAPPER_H */ #endif/* __YOLOWRAPPER_H */
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!