Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张士柳
/
eyemLib
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
图表
网络
创建新的问题
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 96811a3b
由
张士柳
编写于
2021-06-08 17:18:30 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
无
1 个父辈
9387d067
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
86 行增加
和
300 行删除
eyemLib-Sharp/EyemLib.cs
eyemLib-Sharp/Program.cs
eyemLib/eyemDataCode.cpp
eyemLib/eyemGeneric.cpp
eyemLib/eyemLib.h
eyemLib/eyemMisc.cpp
eyemLib-Sharp/EyemLib.cs
查看文件 @
96811a3
此文件的差异被折叠,
点击展开。
eyemLib-Sharp/Program.cs
查看文件 @
96811a3
...
@@ -19,7 +19,7 @@ namespace eyemLib_Sharp
...
@@ -19,7 +19,7 @@ namespace eyemLib_Sharp
//初始化
//初始化
EyemLib
.
Init
();
EyemLib
.
Init
();
string
[]
fileNames
=
Directory
.
GetFiles
(
@"D:\
批量测试图像\
", "
*.*
", SearchOption.AllDirectories);
string
[]
fileNames
=
Directory
.
GetFiles
(
@"D:\
Temp
"
,
"*.*"
,
SearchOption
.
AllDirectories
);
//int iter = 0;
//int iter = 0;
//for (int i = 0; i < 10000; i++)
//for (int i = 0; i < 10000; i++)
...
...
eyemLib/eyemDataCode.cpp
查看文件 @
96811a3
...
@@ -18,196 +18,6 @@ static void split(const std::string &cStrText, const std::string &cStrDelim, std
...
@@ -18,196 +18,6 @@ static void split(const std::string &cStrText, const std::string &cStrDelim, std
cpStr
=
NULL
;
cpStr
=
NULL
;
}
}
//static void filterByApriltag(cv::Mat &binary, cv::Mat &labels, std::vector<tMap> &vPts, std::vector<uchar> &colors, int nccomps, double dToleErr = 0.5)
//{
// //图像尺寸
// int X = binary.cols, Y = binary.rows;
// //背景
// colors[0] = 255;
// std::vector<tMap> temp;
// //水平扫描
// for (int c = 0; c < (int)vPts.size(); c++)
// {
// const uint8_t *ptrRow = binary.ptr<uint8_t>(vPts[c].Pt.y);
//
// //当前可能不是二维码区域
// if (ptrRow[vPts[c].Pt.x] == 0 || ptrRow[std::min(vPts[c].Pt.x + 1, X)] == 0 || ptrRow[std::max(vPts[c].Pt.x - 1, 0)] == 0 || \
// binary.ptr<uint8_t>(std::max(vPts[c].Pt.y - 1, 0))[vPts[c].Pt.x] == 0 || binary.ptr<uint8_t>(std::min(vPts[c].Pt.y + 1, Y))[vPts[c].Pt.x] == 0)
// {
// colors[vPts[c].Label] = 0;
// continue;
// }
//
// uint8_t future_pixel_right = 255;
//
// uint8_t next_pixel;
//
// //终止条件
// int flags = 0;
//
// double test_line[6]{ 0 };//0 中间那块;1那两块黑色;2外圈那两块
// //向右扫描
// for (int x = vPts[c].Pt.x + 1; x < X - 1; x++)
// {
// //colors为0的不参与统计
// if ((colors[labels.ptr<int>(vPts[c].Pt.y)[x]] == 0))
// {
// continue;
// }
// next_pixel = ptrRow[x];
// //统计黑白像素
// test_line[flags]++;
// if (next_pixel != future_pixel_right)
// {
// flags++;
// future_pixel_right = 255 - future_pixel_right;
// if (flags == 3) { break; }
// }
// }
// uint8_t future_pixel_left = 255;
//
// //向左扫描
// for (int x = vPts[c].Pt.x - 1; x >= 1; x--)
// {
// //colors为0的不参与统计
// if ((colors[labels.ptr<int>(vPts[c].Pt.y)[x]] == 0))
// {
// continue;
// }
// next_pixel = ptrRow[x];
// //统计黑白像素
// test_line[flags]++;
//
// if (next_pixel != future_pixel_left)
// {
// flags++;
// future_pixel_left = 255 - future_pixel_left;
// if (flags == 6) { break; };
// }
// }
// //判断是否符合条件,[1]/[4]为1:1------[2]/[5]为1:1-----([1]+[4])/([0]+[3])-----约为0.67
// double rate = cv::min(test_line[1], test_line[4]) / cv::max(test_line[1], test_line[4]);
// if ((rate >= (1. - dToleErr) && rate <= (1. + dToleErr)))
// {
// rate = cv::min(test_line[2], test_line[5]) / cv::max(test_line[2], test_line[5]);
// if ((rate >= (1. - dToleErr) && rate <= (1. + dToleErr)))
// {
// rate = (test_line[1] + test_line[4]) / (test_line[0] + test_line[3]);
// //允许50%的误差
// if (rate >= ((2. / 3.)*(1. - dToleErr)) && rate <= ((2. / 3.)*(1. + dToleErr)))
// {
// temp.push_back(vPts[c]);
// }
// else
// {
// colors[vPts[c].Label] = 0;
// }
// }
// else
// {
// colors[vPts[c].Label] = 0;
// }
// }
// else
// {
// colors[vPts[c].Label] = 0;
// }
// }
// //垂直扫描
// for (int c = 0; c < (int)temp.size(); c++)
// {
// uint8_t future_pixel_down = 255;
//
// uint8_t next_pixel;
//
// //终止条件
// int flags = 0;
//
// double test_line[6]{ 0 };
// //向下扫描
// for (int y = temp[c].Pt.y + 1; y < Y - 1; y++)
// {
// //colors为0的不参与统计
// if ((colors[labels.ptr<int>(y)[temp[c].Pt.x]] == 0))
// {
// continue;
// }
// next_pixel = binary.ptr<uint8_t>(y)[temp[c].Pt.x];
// //统计黑白像素
// test_line[flags]++;
// if (next_pixel != future_pixel_down)
// {
// flags++;
// future_pixel_down = 255 - future_pixel_down;
// if (flags == 3) { break; };
// }
// }
//
// uint8_t future_pixel_up = 255;
//
// //向下扫描
// for (int y = temp[c].Pt.y - 1; y >= 1; y--)
// {
// //colors为0的不参与统计
// if ((colors[labels.ptr<int>(y)[temp[c].Pt.x]] == 0))
// {
// continue;
// }
// next_pixel = binary.ptr<uint8_t>(y)[temp[c].Pt.x];
// //统计黑白像素
// test_line[flags]++;
//
// if (next_pixel != future_pixel_up)
// {
// flags++;
// future_pixel_up = 255 - future_pixel_up;
// if (flags == 6) { break; };
// }
// }
// //判断是否符合条件,[1]/[4]为1:1------[2]/[5]为1:1-----([1]+[4])/([0]+[3])-----约为0.67
// double rate = cv::min(test_line[1], test_line[4]) / cv::max(test_line[1], test_line[4]);
// if (rate >= (1. - dToleErr) && rate <= (1 + dToleErr))
// {
// rate = cv::min(test_line[2], test_line[5]) / cv::max(test_line[2], test_line[5]);
// if (rate >= (1. - dToleErr) && rate <= (1 + dToleErr))
// {
// rate = (test_line[1] + test_line[4]) / (test_line[0] + test_line[3]);
// //允许50%的误差
// if (rate >= ((2. / 3.)*(1. - dToleErr)) && rate <= ((2. / 3.)*(1. + dToleErr)))
// {
// //大部分条件均满足,进入候选点
// }
// else
// {
// colors[temp[c].Label] = 0;
// }
// }
// else
// {
// colors[temp[c].Label] = 0;
// }
// }
// else
// {
// colors[temp[c].Label] = 0;
// }
// }
// colors[0] = 0;
// //过滤
// cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range& range)->void {
// for (int y = range.start; y < range.end; y++)
// {
// uint8_t *ptrRow = binary.ptr<uint8_t>(y);
// for (int x = 0; x < X; x++)
// {
// int label = labels.ptr<int>(y)[x];
// CV_Assert(0 <= label && label <= nccomps);
// ptrRow[x] = colors[label];
// }
// }
// });
//}
static
double
getThreshVal_Otsu_8u
(
const
cv
::
Mat
&
_src
)
static
double
getThreshVal_Otsu_8u
(
const
cv
::
Mat
&
_src
)
{
{
cv
::
Size
size
=
_src
.
size
();
cv
::
Size
size
=
_src
.
size
();
...
...
eyemLib/eyemGeneric.cpp
查看文件 @
96811a3
...
@@ -7,70 +7,74 @@ int eyemImageRead(const char *fileName, int iFlag, EyemImage *tpImage)
...
@@ -7,70 +7,74 @@ int eyemImageRead(const char *fileName, int iFlag, EyemImage *tpImage)
if
(
_src
.
empty
())
if
(
_src
.
empty
())
return
FUNC_IMAGE_NOT_EXIST
;
return
FUNC_IMAGE_NOT_EXIST
;
//在这里重新创建
if
(
NULL
!=
tpImage
->
vpImage
)
{
tpImage
->
iWidth
=
tpImage
->
iHeight
=
tpImage
->
iDepth
=
tpImage
->
iChannels
=
0
;
free
(
tpImage
->
vpImage
);
tpImage
->
vpImage
=
NULL
;
}
//图像信息
//图像信息
tpImage
->
iWidth
=
_src
.
cols
;
tpImage
->
iHeight
=
_src
.
rows
;
tpImage
->
iDepth
=
_src
.
depth
();
tpImage
->
iChannels
=
_src
.
channels
();
tpImage
->
iWidth
=
_src
.
cols
;
tpImage
->
iHeight
=
_src
.
rows
;
tpImage
->
iDepth
=
_src
.
depth
();
tpImage
->
iChannels
=
_src
.
channels
();
//内存尺寸
//内存尺寸
int
_Size
=
tpImage
->
iWidth
*
tpImage
->
iHeight
*
tpImage
->
iChannels
;
int
_Size
=
tpImage
->
iWidth
*
tpImage
->
iHeight
*
tpImage
->
iChannels
;
//判断是否需要重新申请内存
//申请内存
if
(
NULL
==
tpImage
->
vpImage
)
{
switch
(
tpImage
->
iDepth
)
//需要申请内存
{
switch
(
tpImage
->
iDepth
)
case
CV_8U
:
{
_Size
*=
sizeof
(
uint8_t
);
case
CV_8U
:
tpImage
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
uint8_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
case
CV_8S
:
break
;
_Size
*=
sizeof
(
int8_t
);
case
CV_8S
:
tpImage
->
vpImage
=
(
int8_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
int8_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
int8_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
case
CV_16U
:
break
;
_Size
*=
sizeof
(
uint16_t
);
case
CV_16U
:
tpImage
->
vpImage
=
(
uint16_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
uint16_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
uint16_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
case
CV_16S
:
break
;
_Size
*=
sizeof
(
int16_t
);
case
CV_16S
:
tpImage
->
vpImage
=
(
int16_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
int16_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
int16_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
case
CV_32S
:
break
;
_Size
*=
sizeof
(
int32_t
);
case
CV_32S
:
tpImage
->
vpImage
=
(
int32_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
int32_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
int32_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
case
CV_32F
:
break
;
_Size
*=
sizeof
(
float_t
);
case
CV_32F
:
tpImage
->
vpImage
=
(
float_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
float_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
float_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
case
CV_64F
:
break
;
_Size
*=
sizeof
(
double_t
);
case
CV_64F
:
tpImage
->
vpImage
=
(
double_t
*
)
malloc
(
_Size
);
_Size
*=
sizeof
(
double_t
);
if
(
NULL
==
tpImage
->
vpImage
)
tpImage
->
vpImage
=
(
double_t
*
)
malloc
(
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
if
(
NULL
==
tpImage
->
vpImage
)
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
return
FUNC_NOT_ENOUGH_MEM
;
break
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
default:
break
;
//no support format
default:
return
FUNC_CANNOT_USE
;
//no support format
return
FUNC_CANNOT_USE
;
}
}
}
//拷贝数据
//拷贝数据
memcpy
(
tpImage
->
vpImage
,
_src
.
data
,
_Size
);
memcpy
(
tpImage
->
vpImage
,
_src
.
data
,
_Size
);
...
@@ -117,13 +121,31 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
...
@@ -117,13 +121,31 @@ int eyemImageReadRaw(const char *filename, int iWidth, int iHeight, int iDepth,
return
FUNC_OK
;
return
FUNC_OK
;
}
}
int
eyemImage
Write
(
const
char
*
fileName
,
EyemImage
tpImage
)
int
eyemImage
FromBitmap
(
void
*
vpScan0
,
int
iWidth
,
int
iHeight
,
int
iDepth
,
int
iChannels
,
EyemImage
*
tpImage
)
{
{
CV_Assert
((
NULL
!=
tpImage
.
vpImage
));
cv
::
Mat
image
=
cv
::
Mat
(
iHeight
,
iWidth
,
MAKETYPE
(
iDepth
,
iChannels
),
vpScan0
).
clone
();
//在这里重新创建
if
(
NULL
!=
tpImage
->
vpImage
)
{
tpImage
->
iWidth
=
tpImage
->
iHeight
=
tpImage
->
iDepth
=
tpImage
->
iChannels
=
0
;
free
(
tpImage
->
vpImage
);
tpImage
->
vpImage
=
NULL
;
}
//图像信息
tpImage
->
iWidth
=
image
.
cols
;
tpImage
->
iHeight
=
image
.
rows
;
tpImage
->
iDepth
=
image
.
depth
();
tpImage
->
iChannels
=
image
.
channels
();
//内存尺寸
int
_Size
=
tpImage
->
iWidth
*
tpImage
->
iHeight
*
tpImage
->
iChannels
*
sizeof
(
uint8_t
);
cv
::
Mat
_src
=
cv
::
Mat
(
tpImage
.
iHeight
,
tpImage
.
iWidth
,
MAKETYPE
(
tpImage
.
iDepth
,
tpImage
.
iChannels
),
tpImage
.
vpImage
);
//分配内存
tpImage
->
vpImage
=
(
uint8_t
*
)
malloc
(
_Size
);
if
(
NULL
==
tpImage
->
vpImage
)
return
FUNC_NOT_ENOUGH_MEM
;
memset
(
tpImage
->
vpImage
,
0
,
_Size
);
cv
::
imwrite
(
fileName
,
_src
);
//拷贝信息
memcpy
(
tpImage
->
vpImage
,
vpScan0
,
_Size
);
return
FUNC_OK
;
return
FUNC_OK
;
}
}
...
...
eyemLib/eyemLib.h
查看文件 @
96811a3
...
@@ -796,7 +796,7 @@ extern "C" {
...
@@ -796,7 +796,7 @@ extern "C" {
// 函数接口
// 函数接口
EXPORTS
int
eyemImageRead
(
const
char
*
filename
,
int
iFalgs
,
EyemImage
*
ucpImage
);
EXPORTS
int
eyemImageRead
(
const
char
*
filename
,
int
iFalgs
,
EyemImage
*
ucpImage
);
EXPORTS
int
eyemImageReadRaw
(
const
char
*
filename
,
int
iWidth
,
int
iHeight
,
int
iDepth
,
EyemImage
*
tpImage
);
EXPORTS
int
eyemImageReadRaw
(
const
char
*
filename
,
int
iWidth
,
int
iHeight
,
int
iDepth
,
EyemImage
*
tpImage
);
EXPORTS
int
eyemImageWrite
(
const
char
*
fileName
,
EyemImage
tpImage
);
EXPORTS
int
eyemImageFromBitmap
(
void
*
vpScan0
,
int
iWidth
,
int
iHeight
,
int
iDepth
,
int
iChannels
,
EyemImage
*
tpImage
);
EXPORTS
int
eyemVideoCapture
(
const
char
*
fileName
,
IntPtr
*
hObject
,
EyemImage
**
tpImages
,
int
*
ipNum
);
EXPORTS
int
eyemVideoCapture
(
const
char
*
fileName
,
IntPtr
*
hObject
,
EyemImage
**
tpImages
,
int
*
ipNum
);
EXPORTS
bool
eyemVideoCaptureFree
(
IntPtr
hObject
);
EXPORTS
bool
eyemVideoCaptureFree
(
IntPtr
hObject
);
EXPORTS
void
eyemImageFree
(
EyemImage
&
ipImage
);
EXPORTS
void
eyemImageFree
(
EyemImage
&
ipImage
);
...
...
eyemLib/eyemMisc.cpp
查看文件 @
96811a3
...
@@ -6627,53 +6627,7 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
...
@@ -6627,53 +6627,7 @@ int eyemLibImpl(EyemImage tpImage, EyemImage *tpDstImg)
if
(
image
.
channels
()
>
3
)
{
if
(
image
.
channels
()
>
3
)
{
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_BGRA2BGR
);
cv
::
cvtColor
(
image
,
image
,
cv
::
COLOR_BGRA2BGR
);
}
}
//原图备份
cv
::
Mat
backup
;
backup
=
image
.
clone
();
//转float类型
cv
::
Mat
imageF
;
image
.
convertTo
(
imageF
,
CV_32F
);
//归一化
cv
::
parallel_for_
(
cv
::
Range
(
0
,
Y
),
[
&
](
const
cv
::
Range
range
)
->
void
{
for
(
int
y
=
range
.
start
;
y
<
range
.
end
;
y
++
)
{
for
(
int
x
=
0
;
x
<
X
;
x
++
)
{
float
b
,
g
,
r
,
bgr
;
bgr
=
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
][
0
]
+
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
][
1
]
+
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
][
2
];
bgr
=
bgr
==
0
?
1
:
bgr
;
b
=
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
][
0
]
/
bgr
;
g
=
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
][
1
]
/
bgr
;
r
=
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
][
2
]
/
bgr
;
imageF
.
ptr
<
cv
::
Vec3f
>
(
y
)[
x
]
=
cv
::
Vec3f
(
b
,
g
,
r
);
}
}
});
//转int8类型
imageF
.
convertTo
(
image
,
CV_8U
,
255
);
////转hsv空间
//cv::cvtColor(backup, imageF, cv::COLOR_BGR2HSV);
cv
::
Mat
mask
;
//cv::inRange(imageF, cv::Scalar(166, 100, 100), cv::Scalar(186, 255, 255), mask);
//cv::parallel_for_(cv::Range(0, Y), [&](const cv::Range range)->void {
// for (int y = range.start; y < range.end; y++) {
// for (int x = 0; x < X; x++) {
// float h, s, v;
// h = imageF.ptr<cv::Vec3b>(y)[x][0];
// if (!((h > 0 && h < 20) || (h > 150 && h < 255))) {
// imageF.ptr<cv::Vec3b>(y)[x][0] = 0;
// imageF.ptr<cv::Vec3b>(y)[x][1] = 0;
// imageF.ptr<cv::Vec3b>(y)[x][2] = 0;
// }
// }
// }
//});
std
::
vector
<
cv
::
Mat
>
mv
;
cv
::
split
(
image
,
mv
);
cv
::
threshold
(
mv
[
2
],
mask
,
130
,
255
,
cv
::
THRESH_BINARY
);
cv
::
morphologyEx
(
mask
,
mask
,
cv
::
MORPH_OPEN
,
cv
::
getStructuringElement
(
cv
::
MORPH_RECT
,
cv
::
Size
(
7
,
7
)));
#pragma region resize img
#pragma region resize img
//const int minInputSize = 832;
//const int minInputSize = 832;
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论