Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 79de92b9
由
张士柳
编写于
2022-01-27 16:16:48 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
37ea7eac
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
158 行增加
和
223 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/UnmanagedBitmap.cs
eyemLib/eyemEdge1d.cpp
eyemLib/eyemFit.cpp
eyemLib/eyemGeneric.cpp
eyemLib/eyemLib.h
eyemLib/eyemLib.rc
eyemLib/eyemLib.vcxproj
eyemLib/eyemMat.cpp
eyemLib/eyemMatchShapes.cpp
eyemLib/eyemMisc.cpp
eyemLib/eyemNNDetector.cpp
eyemLib/eyemNNDetector.h
eyemLib/eyemSmooth.cpp
eyemLib/yoloWrapper.cpp
eyemLib/yoloWrapper.h
eyemLib-Sharp/EyemLib.cs
查看文件 @
79de92b
此文件的差异被折叠,
点击展开。
eyemLib-Sharp/UnmanagedBitmap.cs
查看文件 @
79de92b
...
...
@@ -7,36 +7,42 @@ namespace eyemLib_Sharp
{
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
;
public
EyemImage
Image
{
get
{
return
image
;
}
}
/// <summary>
/// 初始化新实例
/// </summary>
public
UnmanagedBitmap
()
{
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
)
{
eyemImageRead
(
fileName
,
-
1
,
out
image
);
}
/// <summary>
/// 从Bitmap初始化Unmanaged新实例(GDI不支持除8位以外深度的图像;若要加载不同深度图像请使用从文件名加载)
/// </summary>
/// <param name="bitmap"></param>
public
UnmanagedBitmap
(
Bitmap
bitmap
)
{
mustbeDispose
=
true
;
image
=
eyemCvtToEyemImage
(
bitmap
);
}
private
bool
mustbeDispose
=
false
;
/// <summary>
/// 隐式转换成EyemImage
/// </summary>
/// <param name="operand"></param>
public
static
implicit
operator
EyemImage
(
UnmanagedBitmap
operand
)
{
return
operand
.
Image
;
}
~
UnmanagedBitmap
()
{
...
...
@@ -55,86 +61,39 @@ namespace eyemLib_Sharp
{
// dispose managed resources
}
if
(
mustbeDispose
)
{
image
.
iChannels
=
image
.
iDepth
=
image
.
iHeight
=
image
.
iWidth
=
0
;
Marshal
.
FreeHGlobal
(
image
.
vpImage
);
image
.
vpImage
=
IntPtr
.
Zero
;
}
else
{
eyemImageFree
(
ref
image
);
}
//这里特别修改了eyemCvtToEyemImage的内存分配,因此皆可以由此接口释放
eyemImageFree
(
ref
image
);
}
#
region
EyemImage
与
Bitmap
相互转换
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
;
for
(
int
y
=
0
;
y
<
tpImage
.
iHeight
;
y
++)
{
long
offsetSrc
=
(
y
*
tpImage
.
iWidth
*
tpImage
.
iChannels
);
long
offsetDst
=
(
y
*
pd
);
Buffer
.
MemoryCopy
((
byte
*)(
tpImage
.
vpImage
.
ToPointer
())
+
offsetSrc
,
(
byte
*)(
bd
.
Scan0
.
ToPointer
())
+
offsetDst
,
bytesToCopy
,
bytesToCopy
);
}
}
finally
{
bitmap
.
UnlockBits
(
bd
);
}
return
bitmap
;
}
#
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
);
[
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
);
/// <summary>
/// 从进程中的非托管内存分配指定长度的内存
/// </summary>
/// <param name="cb">长度</param>
/// <returns>地址</returns>
[
DllImport
(
"eyemLib.dll"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
IntPtr
eyemMallocMemBlock
(
int
cb
);
/// <summary>
/// 释放从非托管内存中分配的内存
/// </summary>
/// <param name="block">地址</param>
[
DllImport
(
"eyemLib.dll"
,
CallingConvention
=
CallingConvention
.
Cdecl
)]
private
static
extern
void
eyemFreeMemBlock
(
IntPtr
block
);
#
endregion
#
region
EyemImage
与
Bitmap
相互转换
public
static
EyemImage
eyemCvtToEyemImage
(
Bitmap
bitmap
)
{
EyemImage
tpImage
=
new
EyemImage
();
//锁定数据区
BitmapData
bd
=
bitmap
.
LockBits
(
new
Rectangle
(
0
,
0
,
bitmap
.
Width
,
bitmap
.
Height
),
ImageLockMode
.
ReadOnly
,
bitmap
.
PixelFormat
);
switch
(
bitmap
.
PixelFormat
)
{
case
PixelFormat
.
Format8bppIndexed
:
...
...
@@ -153,19 +112,16 @@ namespace eyemLib_Sharp
tpImage
.
iDepth
=
0
;
//图像尺寸
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
{
int
pd
=
((
tpImage
.
iWidth
*
tpImage
.
iChannels
)
+
3
)
/
4
*
4
;
long
bytesToCopy
=
tpImage
.
iWidth
*
tpImage
.
iChannels
;
for
(
int
y
=
0
;
y
<
tpImage
.
iHeight
;
y
++)
{
long
offsetSrc
=
y
*
pd
;
long
offsetDst
=
y
*
tpImage
.
iWidth
*
tpImage
.
iChannels
;
Buffer
.
MemoryCopy
((
byte
*)(
bd
.
Scan0
.
ToPointer
())
+
offsetSrc
,
(
byte
*)(
tpImage
.
vpImage
.
ToPointer
())
+
offsetDst
,
bytesToCopy
,
bytesToCopy
);
}
}
...
...
eyemLib/eyemEdge1d.cpp
查看文件 @
79de92b
...
...
@@ -141,7 +141,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
std
::
vector
<
EyemOcsDXY
>
*
tpResults
=
new
std
::
vector
<
EyemOcsDXY
>
();
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
++
)
{
float
plusX
,
plusY
;
...
...
@@ -204,7 +204,7 @@ int eyemEdge1dFindLine(EyemImage tpImage, EyemOcsDXY tpLineSt, EyemOcsDXY tpLine
cv
::
Mat
projectedMap
;
cv
::
reduce
(
interMap
,
projectedMap
,
0
,
cv
::
REDUCE_AVG
,
CV_32F
);
//差分过滤(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
::
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
}
}
#endif
//遍历结果
//for (auto it = tpResults->begin(); it != tpResults->end(); ++it)
//{
// it->dX; it->dY;
//}
//释放资源(Tips:当存在越界时候在用free释放时会报错)
delete
[]
filterK
;
filterK
=
NULL
;
...
...
@@ -366,7 +371,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
float
x
=
float
(
tpPoint
.
dX
+
(
float
)
iRadius
*
cos
(
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.0
f
;
n
<=
(
float
)
iCapWidth
/
2.0
f
;
n
+=
1.0
f
,
m
++
)
{
for
(
int
iR
=
-
iCapLength
;
iR
<=
iCapLength
;
iR
++
)
{
...
...
@@ -402,7 +407,7 @@ int eyemEdge1dFindCircle(EyemImage tpImage, EyemOcsDXY tpPoint, int iRadius, int
cv
::
Mat
projectedMap
;
cv
::
reduce
(
interMap
,
projectedMap
,
0
,
cv
::
REDUCE_AVG
,
CV_32F
);
//差分过滤(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
::
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
return
FUNC_OK
;
}
bool
eyemEdge1dGen
Measure
Free
(
IntPtr
hObject
)
bool
eyemEdge1dGenFree
(
IntPtr
hObject
)
{
std
::
vector
<
EyemOcsDXY
>
*
tpEdges
=
reinterpret_cast
<
std
::
vector
<
EyemOcsDXY
>*>
(
hObject
);
delete
tpEdges
;
...
...
eyemLib/eyemFit.cpp
查看文件 @
79de92b
...
...
@@ -779,6 +779,3 @@ int eyemRobustFitEllipse(int iPtnNum, EyemOcsDXY * taPoint, int iCalcMode, doubl
return
FUNC_OK
;
}
eyemLib/eyemGeneric.cpp
查看文件 @
79de92b
...
...
@@ -91,7 +91,8 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
{
if
(
std
::
strlen
(
filename
)
==
0
)
return
FUNC_IMAGE_NOT_EXIST
;
//
//tpImage->iChannels = 1; tpImage->iDepth = 2; tpImage->iWidth = iWidth; tpImage->iHeight = iHeight;
FILE
*
fp
=
fopen
(
filename
,
"rb+"
);
if
(
NULL
!=
fp
)
{
...
...
@@ -118,7 +119,6 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
}
else
return
FUNC_IMAGE_NOT_EXIST
;
//关闭文件
fclose
(
fp
);
return
FUNC_OK
;
...
...
@@ -262,11 +262,9 @@ bool eyemVideoCaptureFree(IntPtr hObject)
}
//清空
tpImages
->
clear
();
//释放
delete
tpImages
;
tpImages
=
NULL
;
return
true
;
}
...
...
eyemLib/eyemLib.h
查看文件 @
79de92b
...
...
@@ -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
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
bool
eyemEdge1dGen
Measure
Free
(
IntPtr
hObject
);
EXPORTS
bool
eyemEdge1dGenFree
(
IntPtr
hObject
);
#ifdef __cplusplus
}
...
...
@@ -925,7 +925,7 @@ extern "C" {
EXPORTS
int
eyemInsertModel
(
IntPtr
hModelID
,
const
char
*
ccTplName
);
EXPORTS
int
eyemRemoveModelByName
(
IntPtr
hModelID
,
const
char
*
ccTplName
);
EXPORTS
int
eyemReleaseModel
(
IntPtr
&
hModelID
);
EXPORTS
int
eyemTrackFeature
(
EyemImage
tp
PrevImg
,
EyemImage
tpNextImg
,
EyemRect3
*
tpRois
,
int
iRoiNum
,
int
*
ipResults
,
EyemImage
*
tpDstImg
);
EXPORTS
int
eyemTrackFeature
(
EyemImage
tp
Image
,
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
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
);
...
...
eyemLib/eyemLib.rc
查看文件 @
79de92b
此文件类型无法预览
eyemLib/eyemLib.vcxproj
查看文件 @
79de92b
...
...
@@ -74,8 +74,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<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>
<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>
<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;$(LibraryPath)</LibraryPath>
<TargetExt>.dll</TargetExt>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...
...
@@ -119,7 +119,7 @@
<Link>
<SubSystem>Console</SubSystem>
<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>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
...
...
eyemLib/eyemMat.cpp
查看文件 @
79de92b
...
...
@@ -410,14 +410,11 @@ int eyemBitwiseNot(EyemImage &tpImage)
int
eyemCvtImageType
(
EyemImage
tpImage
,
const
char
*
ccSubType
,
double
alpha
,
double
beta
,
EyemImage
&
tpDstImg
)
{
CV_Assert
(
NULL
!=
tpImage
.
vpImage
);
cv
::
Mat
_src
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
//在这里重新创建
if
(
NULL
!=
tpDstImg
.
vpImage
)
{
_free
(
tpDstImg
);
}
//内存尺寸(图像数据类型转换不涉及通道、尺寸)
int
_Size
=
tpImage
.
iWidth
*
tpImage
.
iHeight
*
tpImage
.
iChannels
;
...
...
eyemLib/eyemMatchShapes.cpp
查看文件 @
79de92b
...
...
@@ -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
);
}
cv
::
imwrite
(
"result.png"
,
showMat
);
return
0
;
}
...
...
@@ -154,7 +152,10 @@ void shape_based_matching::draw_match_shapes(cv::Mat &showMat, cv::Point cog, cv
contours
.
push_back
(
results
[
i
].
Offset
+
cv
::
Point2d
(
cog
));
}
for
(
auto
&
point
:
contours
)
{
showMat
.
at
<
cv
::
Vec3b
>
(
point
)
=
cv
::
Vec3b
((
uchar
)
color
[
0
],
(
uchar
)
color
[
1
],
(
uchar
)
color
[
2
]);
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
]);
}
}
}
...
...
eyemLib/eyemMisc.cpp
查看文件 @
79de92b
此文件的差异被折叠,
点击展开。
eyemLib/eyemNNDetector.cpp
查看文件 @
79de92b
...
...
@@ -122,40 +122,40 @@ int eyemNNDetector(EyemImage tpImage, int *ipNum, BboxContainer &container, Eyem
}
#ifdef _DEBUG
int
eyemInitClassifier
(
const
char
*
classifierConfigPath
,
const
char
*
classifierModelPath
,
int
ntype
)
{
try
{
pClassifier
=
cv
::
makePtr
<
YoloDarknet
>
(
classifierConfigPath
,
classifierModelPath
,
ntype
);
}
catch
(
const
std
::
exception
&
e
)
{
std
::
cout
<<
e
.
what
()
<<
std
::
endl
;
return
FUNC_CANNOT_CALC
;
}
return
FUNC_OK
;
}
int
eyemClassifier
(
EyemImage
tpImage
)
{
cv
::
Mat
src
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
).
clone
();
if
(
src
.
empty
())
{
return
FUNC_IMAGE_NOT_EXIST
;
}
cv
::
Mat
input
;
int
incn
=
src
.
channels
();
if
(
incn
==
4
)
{
cv
::
cvtColor
(
src
,
input
,
cv
::
COLOR_BGRA2BGR
);
}
else
if
(
incn
==
1
)
{
cv
::
cvtColor
(
src
,
input
,
cv
::
COLOR_GRAY2BGR
);
//根据配置支持三通道图像
}
else
{
input
=
src
;
}
pClassifier
->
setInput
(
input
,
0.4
,
5
);
auto
predict
=
std
::
vector
<
int
>
();
auto
confidence
=
std
::
vector
<
float
>
();
auto
bbox
=
std
::
vector
<
cv
::
Rect
>
();
pClassifier
->
forward
(
predict
,
confidence
,
bbox
);
std
::
cout
<<
"run_end!"
<<
std
::
endl
;
return
FUNC_OK
;
}
//
int eyemInitClassifier(const char *classifierConfigPath, const char *classifierModelPath, int ntype)
//
{
//
try {
//
pClassifier = cv::makePtr<YoloDarknet>(classifierConfigPath, classifierModelPath, ntype);
//
}
//
catch (const std::exception& e) {
//
std::cout << e.what() << std::endl;
//
return FUNC_CANNOT_CALC;
//
}
//
return FUNC_OK;
//
}
//
//
int eyemClassifier(EyemImage tpImage)
//
{
//
cv::Mat src = cv::Mat(tpImage.iHeight, tpImage.iWidth, MAKETYPE(tpImage.iDepth, tpImage.iChannels), tpImage.vpImage).clone();
//
if (src.empty()) {
//
return FUNC_IMAGE_NOT_EXIST;
//
}
//
cv::Mat input;
//
int incn = src.channels();
//
if (incn == 4) {
//
cv::cvtColor(src, input, cv::COLOR_BGRA2BGR);
//
}
//
else if (incn == 1) {
//
cv::cvtColor(src, input, cv::COLOR_GRAY2BGR);//根据配置支持三通道图像
//
}
//
else {
//
input = src;
//
}
//
pClassifier->setInput(input, 0.4, 5);
//
auto predict = std::vector<int>(); auto confidence = std::vector<float>(); auto bbox = std::vector<cv::Rect>();
//
pClassifier->forward(predict, confidence, bbox);
//
std::cout << "run_end!" << std::endl;
//
return FUNC_OK;
//
}
#endif
\ No newline at end of file
eyemLib/eyemNNDetector.h
查看文件 @
79de92b
...
...
@@ -25,7 +25,7 @@ protected:
cv
::
Ptr
<
NNDetector
>
pNNDetector
;
#ifdef _DEBUG
cv
::
Ptr
<
YoloDarknet
>
pClassifier
;
//
cv::Ptr<YoloDarknet> pClassifier;
#endif
#endif
/* __EYEMNNDETECTOR_H */
\ No newline at end of file
eyemLib/eyemSmooth.cpp
查看文件 @
79de92b
...
...
@@ -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
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
bmask2
=
_mm_setr_epi8
(
255
,
255
,
0
,
255
,
255
,
0
,
255
,
255
,
0
,
255
,
255
,
0
,
255
,
255
,
0
,
255
);
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
(
-
1
,
-
1
,
0
,
-
1
,
-
1
,
0
,
-
1
,
-
1
,
0
,
-
1
,
-
1
,
0
,
-
1
,
-
1
,
0
,
-
1
);
a
=
_mm_shuffle_epi8
(
a
,
mask1
);
b
=
_mm_shuffle_epi8
(
b
,
mask2
);
...
...
@@ -379,27 +379,8 @@ int eyemNonLocalMeansFilter(EyemImage tpImage, int iCMPSize, int iSearchSize, do
if
(
image
.
empty
())
{
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::blur(image, dest, cv::Size(3, 3));
//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
);
nonLocalMeansFilter_SSE
(
image
,
dest
,
cv
::
Size
(
3
,
3
),
cv
::
Size
(
5
,
5
),
10.0
,
-
1
,
0
);
return
FUNC_OK
;
}
...
...
eyemLib/yoloWrapper.cpp
查看文件 @
79de92b
...
...
@@ -83,41 +83,41 @@ std::vector<cv::Rect> YoloWrapper::forward(cv::Mat img) {
#ifdef _DEBUG
class
YoloDarknet
::
Impl
{
public
:
Impl
()
{}
~
Impl
()
{}
std
::
shared_ptr
<
DarkNet
>
net_
;
};
YoloDarknet
::
YoloDarknet
(
const
std
::
string
&
config_path
,
const
std
::
string
&
model_path
,
const
int
ntype
)
{
p
=
cv
::
makePtr
<
YoloDarknet
::
Impl
>
();
if
(
!
config_path
.
empty
()
&&
!
model_path
.
empty
())
{
p
->
net_
=
std
::
make_shared
<
DarkNet
>
();
p
->
net_
->
init
(
config_path
,
model_path
,
ntype
);
}
else
{
p
->
net_
=
NULL
;
}
}
void
YoloDarknet
::
setInput
(
cv
::
Mat
&
img
,
float
threshold
,
int
topk
)
{
topk_
=
topk
;
p
->
net_
->
setPreferableParams
(
threshold
,
topk
);
p
->
net_
->
forward
(
img
);
}
void
YoloDarknet
::
forward
(
std
::
vector
<
int
>
&
outputPredict
,
std
::
vector
<
float
>
&
outputConfidence
,
std
::
vector
<
cv
::
Rect
>
&
outputBoxes
)
{
auto
bbox
=
std
::
vector
<
cv
::
Rect
>
();
int
*
predicts
=
new
int
[
topk_
];
float
*
confidence
=
new
float
[
topk_
];
p
->
net_
->
getResult
(
predicts
,
confidence
,
&
bbox
);
for
(
int
top
=
0
;
top
<
topk_
;
top
++
)
outputPredict
.
push_back
(
predicts
[
top
]),
outputConfidence
.
push_back
(
confidence
[
top
]);
for
(
auto
&
box
:
bbox
)
{
outputBoxes
.
push_back
(
box
);
}
delete
[]
predicts
;
predicts
=
NULL
;
delete
[]
confidence
;
confidence
=
NULL
;
}
//
class YoloDarknet::Impl {
//
public:
//
Impl() {}
//
~Impl() {}
//
//
std::shared_ptr<DarkNet> net_;
//
};
//
//
YoloDarknet::YoloDarknet(const std::string& config_path, const std::string& model_path, const int ntype)
//
{
//
p = cv::makePtr<YoloDarknet::Impl>();
//
if (!config_path.empty() && !model_path.empty()) {
//
p->net_ = std::make_shared<DarkNet>();
//
p->net_->init(config_path, model_path, ntype);
//
}
//
else {
//
p->net_ = NULL;
//
}
//
}
//
//
void YoloDarknet::setInput(cv::Mat& img, float threshold, int topk) {
//
topk_ = topk;
//
p->net_->setPreferableParams(threshold, topk);
//
p->net_->forward(img);
//
}
//
//
void YoloDarknet::forward(std::vector<int> &outputPredict, std::vector<float> &outputConfidence, std::vector<cv::Rect> &outputBoxes)
//
{
//
auto bbox = std::vector<cv::Rect>();
//
int *predicts = new int[topk_]; float *confidence = new float[topk_];
//
p->net_->getResult(predicts, confidence, &bbox);
//
for (int top = 0; top < topk_; top++) outputPredict.push_back(predicts[top]), outputConfidence.push_back(confidence[top]);
//
for (auto&box : bbox) {
//
outputBoxes.push_back(box);
//
}
//
delete[] predicts; predicts = NULL; delete[] confidence; confidence = NULL;
//
}
#endif
eyemLib/yoloWrapper.h
查看文件 @
79de92b
...
...
@@ -9,8 +9,8 @@
#include "opencv2/imgproc.hpp"
#ifdef _DEBUG
#include <darknet.h>
#include <yolo_class.h>
//
#include <darknet.h>
//
#include <yolo_class.h>
#endif
class
YoloWrapper
...
...
@@ -27,20 +27,20 @@ private:
};
#ifdef _DEBUG
class
YoloDarknet
{
public
:
YoloDarknet
(
const
std
::
string
&
config_path
=
""
,
const
std
::
string
&
model_path
=
""
,
const
int
ntype
=
0
);
YoloDarknet
()
{};
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
);
private
:
int
topk_
=
0
;
protected
:
class
Impl
;
cv
::
Ptr
<
Impl
>
p
;
};
//
class YoloDarknet
//
{
//
public:
//
YoloDarknet(const std::string& config_path = "", const std::string& model_path = "", const int ntype = 0);
//
YoloDarknet() {};
//
//
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);
//
private:
//
int topk_ = 0;
//
protected:
//
class Impl;
//
cv::Ptr<Impl> p;
//
};
#endif
#endif
/* __YOLOWRAPPER_H */
\ No newline at end of file
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论