Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
3495c595
O
Opencv
项目概览
Greenplum
/
Opencv
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
3495c595
编写于
1月 31, 2014
作者:
K
Konstantin Matskevich
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes
上级
5c38519c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
61 addition
and
46 deletion
+61
-46
modules/objdetect/include/opencv2/objdetect.hpp
modules/objdetect/include/opencv2/objdetect.hpp
+9
-15
modules/objdetect/perf/opencl/perf_hogdetect.cpp
modules/objdetect/perf/opencl/perf_hogdetect.cpp
+2
-2
modules/objdetect/src/hog.cpp
modules/objdetect/src/hog.cpp
+50
-29
未找到文件。
modules/objdetect/include/opencv2/objdetect.hpp
浏览文件 @
3495c595
...
...
@@ -313,8 +313,6 @@ public:
Size
winStride
=
Size
(),
Size
padding
=
Size
(),
const
std
::
vector
<
Point
>&
locations
=
std
::
vector
<
Point
>
())
const
;
virtual
bool
ocl_compute
(
InputArray
_img
,
Size
win_stride
,
std
::
vector
<
float
>&
descriptors
,
int
descr_format
)
const
;
//with found weights output
CV_WRAP
virtual
void
detect
(
const
Mat
&
img
,
CV_OUT
std
::
vector
<
Point
>&
foundLocations
,
CV_OUT
std
::
vector
<
double
>&
weights
,
...
...
@@ -326,9 +324,7 @@ public:
double
hitThreshold
=
0
,
Size
winStride
=
Size
(),
Size
padding
=
Size
(),
const
std
::
vector
<
Point
>&
searchLocations
=
std
::
vector
<
Point
>
())
const
;
//ocl
virtual
bool
ocl_detect
(
InputArray
img
,
std
::
vector
<
Point
>
&
hits
,
double
hitThreshold
=
0
,
Size
winStride
=
Size
())
const
;
//with result weights output
CV_WRAP
virtual
void
detectMultiScale
(
InputArray
img
,
CV_OUT
std
::
vector
<
Rect
>&
foundLocations
,
CV_OUT
std
::
vector
<
double
>&
foundWeights
,
double
hitThreshold
=
0
,
...
...
@@ -339,9 +335,6 @@ public:
double
hitThreshold
=
0
,
Size
winStride
=
Size
(),
Size
padding
=
Size
(),
double
scale
=
1.05
,
double
finalThreshold
=
2.0
,
bool
useMeanshiftGrouping
=
false
)
const
;
//ocl
virtual
bool
ocl_detectMultiScale
(
InputArray
img
,
std
::
vector
<
Rect
>
&
found_locations
,
std
::
vector
<
double
>&
level_scale
,
double
hit_threshold
,
Size
winStride
,
double
groupThreshold
)
const
;
CV_WRAP
virtual
void
computeGradient
(
const
Mat
&
img
,
CV_OUT
Mat
&
grad
,
CV_OUT
Mat
&
angleOfs
,
Size
paddingTL
=
Size
(),
Size
paddingBR
=
Size
())
const
;
...
...
@@ -361,25 +354,26 @@ public:
CV_PROP
bool
gammaCorrection
;
CV_PROP
std
::
vector
<
float
>
svmDetector
;
UMat
oclSvmDetector
;
float
free_coef
;
CV_PROP
int
nlevels
;
// evaluate specified ROI and return confidence value for each location
virtual
void
detectROI
(
const
cv
::
Mat
&
img
,
const
std
::
vector
<
cv
::
Point
>
&
locations
,
// evaluate specified ROI and return confidence value for each location
virtual
void
detectROI
(
const
cv
::
Mat
&
img
,
const
std
::
vector
<
cv
::
Point
>
&
locations
,
CV_OUT
std
::
vector
<
cv
::
Point
>&
foundLocations
,
CV_OUT
std
::
vector
<
double
>&
confidences
,
double
hitThreshold
=
0
,
cv
::
Size
winStride
=
Size
(),
cv
::
Size
padding
=
Size
())
const
;
// evaluate specified ROI and return confidence value for each location in multiple scales
virtual
void
detectMultiScaleROI
(
const
cv
::
Mat
&
img
,
// evaluate specified ROI and return confidence value for each location in multiple scales
virtual
void
detectMultiScaleROI
(
const
cv
::
Mat
&
img
,
CV_OUT
std
::
vector
<
cv
::
Rect
>&
foundLocations
,
std
::
vector
<
DetectionROI
>&
locations
,
double
hitThreshold
=
0
,
int
groupThreshold
=
0
)
const
;
// read/parse Dalal's alt model file
void
readALTModel
(
String
modelfile
);
void
groupRectangles
(
std
::
vector
<
cv
::
Rect
>&
rectList
,
std
::
vector
<
double
>&
weights
,
int
groupThreshold
,
double
eps
)
const
;
// read/parse Dalal's alt model file
void
readALTModel
(
String
modelfile
);
void
groupRectangles
(
std
::
vector
<
cv
::
Rect
>&
rectList
,
std
::
vector
<
double
>&
weights
,
int
groupThreshold
,
double
eps
)
const
;
};
...
...
modules/objdetect/perf/opencl/perf_hogdetect.cpp
浏览文件 @
3495c595
...
...
@@ -74,10 +74,10 @@ OCL_PERF_TEST(HOGFixture, HOG)
{
UMat
src
;
imread
(
getDataPath
(
"gpu/hog/road.png"
),
cv
::
IMREAD_GRAYSCALE
).
copyTo
(
src
);
CV_Assert
(
!
src
.
empty
());
ASSERT_FALSE
(
src
.
empty
());
vector
<
cv
::
Rect
>
found_locations
;
declare
.
in
(
src
)
.
time
(
5
)
;
declare
.
in
(
src
);
HOGDescriptor
hog
;
hog
.
setSVMDetector
(
hog
.
getDefaultPeopleDetector
());
...
...
modules/objdetect/src/hog.cpp
浏览文件 @
3495c595
...
...
@@ -112,6 +112,7 @@ bool HOGDescriptor::checkDetectorSize() const
void
HOGDescriptor
::
setSVMDetector
(
InputArray
_svmDetector
)
{
_svmDetector
.
getMat
().
convertTo
(
svmDetector
,
CV_32F
);
CV_Assert
(
checkDetectorSize
());
Mat
detector_reordered
(
1
,
(
int
)
svmDetector
.
size
(),
CV_32FC1
);
...
...
@@ -126,8 +127,9 @@ void HOGDescriptor::setSVMDetector(InputArray _svmDetector)
for
(
size_t
k
=
0
;
k
<
block_hist_size
;
++
k
)
dst
[
k
]
=
src
[
k
];
}
size_t
descriptor_size
=
getDescriptorSize
();
free_coef
=
svmDetector
.
size
()
>
descriptor_size
?
svmDetector
[
descriptor_size
]
:
0
;
detector_reordered
.
copyTo
(
oclSvmDetector
);
CV_Assert
(
checkDetectorSize
());
}
#define CV_TYPE_NAME_HOG_DESCRIPTOR "opencv-object-detector-hog"
...
...
@@ -1068,6 +1070,8 @@ static inline int gcd(int a, int b)
return
a
;
}
#ifdef HAVE_OPENCL
static
bool
ocl_compute_gradients_8UC1
(
int
height
,
int
width
,
InputArray
_img
,
float
angle_scale
,
UMat
grad
,
UMat
qangle
,
bool
correct_gamma
,
int
nbins
)
{
...
...
@@ -1309,7 +1313,8 @@ static bool ocl_extract_descrs_by_cols(int win_height, int win_width, int block_
return
k
.
run
(
2
,
globalThreads
,
localThreads
,
false
);
}
bool
HOGDescriptor
::
ocl_compute
(
InputArray
_img
,
Size
win_stride
,
std
::
vector
<
float
>&
_descriptors
,
int
descr_format
)
const
static
bool
ocl_compute
(
InputArray
_img
,
Size
win_stride
,
std
::
vector
<
float
>&
_descriptors
,
int
descr_format
,
Size
blockSize
,
Size
cellSize
,
int
nbins
,
Size
blockStride
,
Size
winSize
,
float
sigma
,
bool
gammaCorrection
,
double
L2HysThreshold
)
{
Size
imgSize
=
_img
.
size
();
Size
effect_size
=
imgSize
;
...
...
@@ -1324,7 +1329,6 @@ bool HOGDescriptor::ocl_compute(InputArray _img, Size win_stride, std::vector<fl
Size
wins_per_img
=
numPartsWithin
(
imgSize
,
winSize
,
win_stride
);
UMat
labels
(
1
,
wins_per_img
.
area
(),
CV_8U
);
float
sigma
=
(
float
)
getWinSigma
();
float
scale
=
1.
f
/
(
2.
f
*
sigma
*
sigma
);
Mat
gaussian_lut
(
1
,
512
,
CV_32FC1
);
int
idx
=
0
;
...
...
@@ -1335,16 +1339,18 @@ bool HOGDescriptor::ocl_compute(InputArray _img, Size win_stride, std::vector<fl
for
(
int
j
=-
8
;
j
<
8
;
j
++
)
gaussian_lut
.
at
<
float
>
(
idx
++
)
=
(
8.
f
-
fabs
(
j
+
0.5
f
))
*
(
8.
f
-
fabs
(
i
+
0.5
f
))
/
64.
f
;
if
(
!
ocl_computeGradient
(
_img
,
grad
,
qangle
,
nbins
,
effect_size
,
gammaCorrection
))
return
false
;
UMat
gauss_w_lut
;
gaussian_lut
.
copyTo
(
gauss_w_lut
);
if
(
!
ocl_computeGradient
(
_img
,
grad
,
qangle
,
nbins
,
effect_size
,
gammaCorrection
))
return
false
;
if
(
!
ocl_compute_hists
(
nbins
,
blockStride
.
width
,
blockStride
.
height
,
effect_size
.
height
,
effect_size
.
width
,
grad
,
qangle
,
gauss_w_lut
,
block_hists
,
block_hist_size
))
return
false
;
effect_size
.
width
,
grad
,
qangle
,
gauss_w_lut
,
block_hists
,
block_hist_size
))
return
false
;
if
(
!
ocl_normalize_hists
(
nbins
,
blockStride
.
width
,
blockStride
.
height
,
effect_size
.
height
,
effect_size
.
width
,
block_hists
,
(
float
)
L2HysThreshold
))
return
false
;
effect_size
.
width
,
block_hists
,
(
float
)
L2HysThreshold
))
return
false
;
Size
blocks_per_win
=
numPartsWithin
(
winSize
,
blockSize
,
blockStride
);
wins_per_img
=
numPartsWithin
(
effect_size
,
winSize
,
win_stride
);
...
...
@@ -1358,12 +1364,14 @@ bool HOGDescriptor::ocl_compute(InputArray _img, Size win_stride, std::vector<fl
case
DESCR_FORMAT_ROW_BY_ROW
:
if
(
!
ocl_extract_descrs_by_rows
(
winSize
.
height
,
winSize
.
width
,
blockStride
.
height
,
blockStride
.
width
,
win_stride
.
height
,
win_stride
.
width
,
effect_size
.
height
,
effect_size
.
width
,
block_hists
,
descriptors
,
(
int
)
block_hist_size
,
descr_size
,
descr_width
))
return
false
;
effect_size
.
width
,
block_hists
,
descriptors
,
(
int
)
block_hist_size
,
descr_size
,
descr_width
))
return
false
;
break
;
case
DESCR_FORMAT_COL_BY_COL
:
if
(
!
ocl_extract_descrs_by_cols
(
winSize
.
height
,
winSize
.
width
,
blockStride
.
height
,
blockStride
.
width
,
win_stride
.
height
,
win_stride
.
width
,
effect_size
.
height
,
effect_size
.
width
,
block_hists
,
descriptors
,
(
int
)
block_hist_size
,
descr_size
,
blocks_per_win
.
width
,
blocks_per_win
.
height
))
return
false
;
block_hists
,
descriptors
,
(
int
)
block_hist_size
,
descr_size
,
blocks_per_win
.
width
,
blocks_per_win
.
height
))
return
false
;
break
;
default:
return
false
;
...
...
@@ -1371,6 +1379,7 @@ bool HOGDescriptor::ocl_compute(InputArray _img, Size win_stride, std::vector<fl
descriptors
.
reshape
(
1
,
(
int
)
descriptors
.
total
()).
getMat
(
ACCESS_READ
).
copyTo
(
_descriptors
);
return
true
;
}
#endif //HAVE_OPENCL
void
HOGDescriptor
::
compute
(
InputArray
_img
,
std
::
vector
<
float
>&
descriptors
,
Size
winStride
,
Size
padding
,
const
std
::
vector
<
Point
>&
locations
)
const
...
...
@@ -1388,7 +1397,8 @@ void HOGDescriptor::compute(InputArray _img, std::vector<float>& descriptors,
Size
paddedImgSize
(
imgSize
.
width
+
padding
.
width
*
2
,
imgSize
.
height
+
padding
.
height
*
2
);
CV_OCL_RUN
(
_img
.
dims
()
<=
2
&&
_img
.
type
()
==
CV_8UC1
&&
_img
.
isUMat
(),
ocl_compute
(
_img
,
winStride
,
descriptors
,
DESCR_FORMAT_COL_BY_COL
))
ocl_compute
(
_img
,
winStride
,
descriptors
,
DESCR_FORMAT_COL_BY_COL
,
blockSize
,
cellSize
,
nbins
,
blockStride
,
winSize
,
(
float
)
getWinSigma
(),
gammaCorrection
,
L2HysThreshold
))
Mat
img
=
_img
.
getMat
();
HOGCache
cache
(
this
,
img
,
padding
,
padding
,
nwindows
==
0
,
cacheStride
);
...
...
@@ -1612,6 +1622,8 @@ private:
Mutex
*
mtx
;
};
#ifdef HAVE_OPENCL
static
bool
ocl_classify_hists
(
int
win_height
,
int
win_width
,
int
block_stride_y
,
int
block_stride_x
,
int
win_stride_y
,
int
win_stride_x
,
int
height
,
int
width
,
const
UMat
&
block_hists
,
UMat
detector
,
...
...
@@ -1697,11 +1709,12 @@ static bool ocl_classify_hists(int win_height, int win_width, int block_stride_y
return
k
.
run
(
2
,
globalThreads
,
localThreads
,
false
);
}
bool
HOGDescriptor
::
ocl_detect
(
InputArray
img
,
std
::
vector
<
Point
>
&
hits
,
double
hit_threshold
,
Size
win_stride
)
const
static
bool
ocl_detect
(
InputArray
img
,
std
::
vector
<
Point
>
&
hits
,
double
hit_threshold
,
Size
win_stride
,
const
UMat
&
oclSvmDetector
,
Size
blockSize
,
Size
cellSize
,
int
nbins
,
Size
blockStride
,
Size
winSize
,
bool
gammaCorrection
,
double
L2HysThreshold
,
float
sigma
,
float
free_coef
)
{
hits
.
clear
();
if
(
s
vmDetector
.
empty
())
if
(
oclS
vmDetector
.
empty
())
return
false
;
Size
imgSize
=
img
.
size
();
...
...
@@ -1716,7 +1729,6 @@ bool HOGDescriptor::ocl_detect(InputArray img, std::vector<Point> &hits,
Size
wins_per_img
=
numPartsWithin
(
imgSize
,
winSize
,
win_stride
);
UMat
labels
(
1
,
wins_per_img
.
area
(),
CV_8U
);
float
sigma
=
(
float
)
getWinSigma
();
float
scale
=
1.
f
/
(
2.
f
*
sigma
*
sigma
);
Mat
gaussian_lut
(
1
,
512
,
CV_32FC1
);
int
idx
=
0
;
...
...
@@ -1727,19 +1739,18 @@ bool HOGDescriptor::ocl_detect(InputArray img, std::vector<Point> &hits,
for
(
int
j
=-
8
;
j
<
8
;
j
++
)
gaussian_lut
.
at
<
float
>
(
idx
++
)
=
(
8.
f
-
fabs
(
j
+
0.5
f
))
*
(
8.
f
-
fabs
(
i
+
0.5
f
))
/
64.
f
;
if
(
!
ocl_computeGradient
(
img
,
grad
,
qangle
,
nbins
,
effect_size
,
gammaCorrection
))
return
false
;
UMat
gauss_w_lut
;
gaussian_lut
.
copyTo
(
gauss_w_lut
);
if
(
!
ocl_computeGradient
(
img
,
grad
,
qangle
,
nbins
,
effect_size
,
gammaCorrection
))
return
false
;
if
(
!
ocl_compute_hists
(
nbins
,
blockStride
.
width
,
blockStride
.
height
,
effect_size
.
height
,
effect_size
.
width
,
grad
,
qangle
,
gauss_w_lut
,
block_hists
,
block_hist_size
))
return
false
;
effect_size
.
width
,
grad
,
qangle
,
gauss_w_lut
,
block_hists
,
block_hist_size
))
return
false
;
if
(
!
ocl_normalize_hists
(
nbins
,
blockStride
.
width
,
blockStride
.
height
,
effect_size
.
height
,
effect_size
.
width
,
block_hists
,
(
float
)
L2HysThreshold
))
return
false
;
size_t
descriptor_size
=
getDescriptorSize
();
float
free_coef
=
svmDetector
.
size
()
>
descriptor_size
?
svmDetector
[
descriptor_size
]
:
0
;
effect_size
.
width
,
block_hists
,
(
float
)
L2HysThreshold
))
return
false
;
Size
blocks_per_win
=
numPartsWithin
(
winSize
,
blockSize
,
blockStride
);
...
...
@@ -1748,7 +1759,8 @@ bool HOGDescriptor::ocl_detect(InputArray img, std::vector<Point> &hits,
if
(
!
ocl_classify_hists
(
winSize
.
height
,
winSize
.
width
,
blockStride
.
height
,
blockStride
.
width
,
win_stride
.
height
,
win_stride
.
width
,
effect_size
.
height
,
effect_size
.
width
,
block_hists
,
oclSvmDetector
,
(
float
)
free_coef
,
(
float
)
hit_threshold
,
labels
,
descr_size
,
(
int
)
block_hist_size
))
return
false
;
free_coef
,
(
float
)
hit_threshold
,
labels
,
descr_size
,
(
int
)
block_hist_size
))
return
false
;
Mat
labels_host
=
labels
.
getMat
(
ACCESS_READ
);
unsigned
char
*
vec
=
labels_host
.
ptr
();
...
...
@@ -1764,8 +1776,11 @@ bool HOGDescriptor::ocl_detect(InputArray img, std::vector<Point> &hits,
return
true
;
}
bool
HOGDescriptor
::
ocl_detectMultiScale
(
InputArray
_img
,
std
::
vector
<
Rect
>
&
found_locations
,
std
::
vector
<
double
>&
level_scale
,
double
hit_threshold
,
Size
win_stride
,
double
group_threshold
)
const
static
bool
ocl_detectMultiScale
(
InputArray
_img
,
std
::
vector
<
Rect
>
&
found_locations
,
std
::
vector
<
double
>&
level_scale
,
double
hit_threshold
,
Size
win_stride
,
double
group_threshold
,
const
UMat
&
oclSvmDetector
,
Size
blockSize
,
Size
cellSize
,
int
nbins
,
Size
blockStride
,
Size
winSize
,
bool
gammaCorrection
,
double
L2HysThreshold
,
float
sigma
,
float
free_coef
)
{
std
::
vector
<
Rect
>
all_candidates
;
std
::
vector
<
Point
>
locations
;
...
...
@@ -1779,12 +1794,16 @@ bool HOGDescriptor::ocl_detectMultiScale(InputArray _img, std::vector<Rect> &fou
Size
effect_size
=
Size
(
cvRound
(
imgSize
.
width
/
scale
),
cvRound
(
imgSize
.
height
/
scale
));
if
(
effect_size
==
imgSize
)
{
if
(
!
ocl_detect
(
_img
,
locations
,
hit_threshold
,
win_stride
))
return
false
;
if
(
!
ocl_detect
(
_img
,
locations
,
hit_threshold
,
win_stride
,
oclSvmDetector
,
blockSize
,
cellSize
,
nbins
,
blockStride
,
winSize
,
gammaCorrection
,
L2HysThreshold
,
sigma
,
free_coef
))
return
false
;
}
else
{
resize
(
_img
,
image_scale
,
effect_size
);
if
(
!
ocl_detect
(
image_scale
,
locations
,
hit_threshold
,
win_stride
))
return
false
;
if
(
!
ocl_detect
(
image_scale
,
locations
,
hit_threshold
,
win_stride
,
oclSvmDetector
,
blockSize
,
cellSize
,
nbins
,
blockStride
,
winSize
,
gammaCorrection
,
L2HysThreshold
,
sigma
,
free_coef
))
return
false
;
}
Size
scaled_win_size
(
cvRound
(
winSize
.
width
*
scale
),
cvRound
(
winSize
.
height
*
scale
));
...
...
@@ -1795,6 +1814,7 @@ bool HOGDescriptor::ocl_detectMultiScale(InputArray _img, std::vector<Rect> &fou
cv
::
groupRectangles
(
found_locations
,
(
int
)
group_threshold
,
0.2
);
return
true
;
}
#endif //HAVE_OPENCL
void
HOGDescriptor
::
detectMultiScale
(
InputArray
_img
,
std
::
vector
<
Rect
>&
foundLocations
,
std
::
vector
<
double
>&
foundWeights
,
...
...
@@ -1823,7 +1843,8 @@ void HOGDescriptor::detectMultiScale(
CV_OCL_RUN
(
_img
.
dims
()
<=
2
&&
_img
.
type
()
==
CV_8UC1
&&
scale0
>
1
&&
winStride
.
width
%
blockStride
.
width
==
0
&&
winStride
.
height
%
blockStride
.
height
==
0
&&
padding
==
Size
(
0
,
0
)
&&
_img
.
isUMat
(),
ocl_detectMultiScale
(
_img
,
foundLocations
,
levelScale
,
hitThreshold
,
winStride
,
finalThreshold
));
ocl_detectMultiScale
(
_img
,
foundLocations
,
levelScale
,
hitThreshold
,
winStride
,
finalThreshold
,
oclSvmDetector
,
blockSize
,
cellSize
,
nbins
,
blockStride
,
winSize
,
gammaCorrection
,
L2HysThreshold
,
(
float
)
getWinSigma
(),
free_coef
));
std
::
vector
<
Rect
>
allCandidates
;
std
::
vector
<
double
>
tempScales
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录