Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
7e943808
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7e943808
编写于
7月 23, 2020
作者:
S
Suleyman TURKMEN
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update train_HOG.cpp
上级
5bfa43f7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
13 addition
and
13 deletion
+13
-13
samples/cpp/train_HOG.cpp
samples/cpp/train_HOG.cpp
+13
-13
未找到文件。
samples/cpp/train_HOG.cpp
浏览文件 @
7e943808
...
@@ -74,9 +74,9 @@ void load_images( const String & dirname, vector< Mat > & img_lst, bool showImag
...
@@ -74,9 +74,9 @@ void load_images( const String & dirname, vector< Mat > & img_lst, bool showImag
for
(
size_t
i
=
0
;
i
<
files
.
size
();
++
i
)
for
(
size_t
i
=
0
;
i
<
files
.
size
();
++
i
)
{
{
Mat
img
=
imread
(
files
[
i
]
);
// load the image
Mat
img
=
imread
(
files
[
i
]
);
// load the image
if
(
img
.
empty
()
)
// invalid image, skip it.
if
(
img
.
empty
()
)
{
{
cout
<<
files
[
i
]
<<
" is invalid!"
<<
endl
;
cout
<<
files
[
i
]
<<
" is invalid!"
<<
endl
;
// invalid image, skip it.
continue
;
continue
;
}
}
...
@@ -95,16 +95,13 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co
...
@@ -95,16 +95,13 @@ void sample_neg( const vector< Mat > & full_neg_lst, vector< Mat > & neg_lst, co
box
.
width
=
size
.
width
;
box
.
width
=
size
.
width
;
box
.
height
=
size
.
height
;
box
.
height
=
size
.
height
;
const
int
size_x
=
box
.
width
;
const
int
size_y
=
box
.
height
;
srand
(
(
unsigned
int
)
time
(
NULL
)
);
srand
(
(
unsigned
int
)
time
(
NULL
)
);
for
(
size_t
i
=
0
;
i
<
full_neg_lst
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
full_neg_lst
.
size
();
i
++
)
if
(
full_neg_lst
[
i
].
cols
>
box
.
width
&&
full_neg_lst
[
i
].
rows
>
box
.
height
)
if
(
full_neg_lst
[
i
].
cols
>
box
.
width
&&
full_neg_lst
[
i
].
rows
>
box
.
height
)
{
{
box
.
x
=
rand
()
%
(
full_neg_lst
[
i
].
cols
-
size_x
);
box
.
x
=
rand
()
%
(
full_neg_lst
[
i
].
cols
-
box
.
width
);
box
.
y
=
rand
()
%
(
full_neg_lst
[
i
].
rows
-
size_y
);
box
.
y
=
rand
()
%
(
full_neg_lst
[
i
].
rows
-
box
.
height
);
Mat
roi
=
full_neg_lst
[
i
](
box
);
Mat
roi
=
full_neg_lst
[
i
](
box
);
neg_lst
.
push_back
(
roi
.
clone
()
);
neg_lst
.
push_back
(
roi
.
clone
()
);
}
}
...
@@ -259,7 +256,7 @@ int main( int argc, char** argv )
...
@@ -259,7 +256,7 @@ int main( int argc, char** argv )
load_images
(
pos_dir
,
pos_lst
,
visualization
);
load_images
(
pos_dir
,
pos_lst
,
visualization
);
if
(
pos_lst
.
size
()
>
0
)
if
(
pos_lst
.
size
()
>
0
)
{
{
clog
<<
"...[done]"
<<
endl
;
clog
<<
"...[done]
"
<<
pos_lst
.
size
()
<<
" files.
"
<<
endl
;
}
}
else
else
{
{
...
@@ -287,22 +284,25 @@ int main( int argc, char** argv )
...
@@ -287,22 +284,25 @@ int main( int argc, char** argv )
}
}
clog
<<
"Negative images are being loaded..."
;
clog
<<
"Negative images are being loaded..."
;
load_images
(
neg_dir
,
full_neg_lst
,
false
);
load_images
(
neg_dir
,
full_neg_lst
,
visualization
);
clog
<<
"...[done] "
<<
full_neg_lst
.
size
()
<<
" files."
<<
endl
;
clog
<<
"Negative images are being processed..."
;
sample_neg
(
full_neg_lst
,
neg_lst
,
pos_image_size
);
sample_neg
(
full_neg_lst
,
neg_lst
,
pos_image_size
);
clog
<<
"...[done]"
<<
endl
;
clog
<<
"...[done]
"
<<
neg_lst
.
size
()
<<
" files.
"
<<
endl
;
clog
<<
"Histogram of Gradients are being calculated for positive images..."
;
clog
<<
"Histogram of Gradients are being calculated for positive images..."
;
computeHOGs
(
pos_image_size
,
pos_lst
,
gradient_lst
,
flip_samples
);
computeHOGs
(
pos_image_size
,
pos_lst
,
gradient_lst
,
flip_samples
);
size_t
positive_count
=
gradient_lst
.
size
();
size_t
positive_count
=
gradient_lst
.
size
();
labels
.
assign
(
positive_count
,
+
1
);
labels
.
assign
(
positive_count
,
+
1
);
clog
<<
"...[done] ( positive count : "
<<
positive_count
<<
" )"
<<
endl
;
clog
<<
"...[done] ( positive
images
count : "
<<
positive_count
<<
" )"
<<
endl
;
clog
<<
"Histogram of Gradients are being calculated for negative images..."
;
clog
<<
"Histogram of Gradients are being calculated for negative images..."
;
computeHOGs
(
pos_image_size
,
neg_lst
,
gradient_lst
,
flip_samples
);
computeHOGs
(
pos_image_size
,
neg_lst
,
gradient_lst
,
flip_samples
);
size_t
negative_count
=
gradient_lst
.
size
()
-
positive_count
;
size_t
negative_count
=
gradient_lst
.
size
()
-
positive_count
;
labels
.
insert
(
labels
.
end
(),
negative_count
,
-
1
);
labels
.
insert
(
labels
.
end
(),
negative_count
,
-
1
);
CV_Assert
(
positive_count
<
labels
.
size
()
);
CV_Assert
(
positive_count
<
labels
.
size
()
);
clog
<<
"...[done] ( negative count : "
<<
negative_count
<<
" )"
<<
endl
;
clog
<<
"...[done] ( negative
images
count : "
<<
negative_count
<<
" )"
<<
endl
;
Mat
train_data
;
Mat
train_data
;
convert_to_ml
(
gradient_lst
,
train_data
);
convert_to_ml
(
gradient_lst
,
train_data
);
...
@@ -324,7 +324,7 @@ int main( int argc, char** argv )
...
@@ -324,7 +324,7 @@ int main( int argc, char** argv )
if
(
train_twice
)
if
(
train_twice
)
{
{
clog
<<
"Testing trained detector on negative images. This m
ay
take a few minutes..."
;
clog
<<
"Testing trained detector on negative images. This m
ight
take a few minutes..."
;
HOGDescriptor
my_hog
;
HOGDescriptor
my_hog
;
my_hog
.
winSize
=
pos_image_size
;
my_hog
.
winSize
=
pos_image_size
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录