Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
6d0f8aa8
Commit
6d0f8aa8
authored
Mar 02, 2015
by
Vladislav Vinogradov
Committed by
Alexander Smorkalov
Apr 19, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix tests for gpu HOG
initialize HOG after CUDA device switch (cherry picked from commit
c849492d
)
parent
bea98bd2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
26 deletions
+43
-26
test_objdetect.cpp
modules/gpu/test/test_objdetect.cpp
+43
-26
No files found.
modules/gpu/test/test_objdetect.cpp
View file @
6d0f8aa8
...
@@ -48,9 +48,24 @@ using namespace cvtest;
...
@@ -48,9 +48,24 @@ using namespace cvtest;
//#define DUMP
//#define DUMP
struct
HOG
:
testing
::
TestWithParam
<
cv
::
gpu
::
DeviceInfo
>
,
cv
::
gpu
::
HOGDescriptor
class
HogForTest
:
public
cv
::
gpu
::
HOGDescriptor
{
public
:
cv
::
gpu
::
GpuMat
getBlockHists
()
const
{
return
block_hists
;
}
void
computeBlockHistograms
(
const
cv
::
gpu
::
GpuMat
&
img
)
{
cv
::
gpu
::
HOGDescriptor
::
computeBlockHistograms
(
img
);
}
};
struct
HOG
:
testing
::
TestWithParam
<
cv
::
gpu
::
DeviceInfo
>
{
{
cv
::
gpu
::
DeviceInfo
devInfo
;
cv
::
gpu
::
DeviceInfo
devInfo
;
cv
::
Ptr
<
HogForTest
>
hog
;
#ifdef DUMP
#ifdef DUMP
std
::
ofstream
f
;
std
::
ofstream
f
;
...
@@ -69,6 +84,8 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
...
@@ -69,6 +84,8 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
devInfo
=
GetParam
();
devInfo
=
GetParam
();
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
cv
::
gpu
::
setDevice
(
devInfo
.
deviceID
());
hog
=
new
HogForTest
;
}
}
#ifdef DUMP
#ifdef DUMP
...
@@ -126,39 +143,39 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
...
@@ -126,39 +143,39 @@ struct HOG : testing::TestWithParam<cv::gpu::DeviceInfo>, cv::gpu::HOGDescriptor
void
testDetect
(
const
cv
::
Mat
&
img
)
void
testDetect
(
const
cv
::
Mat
&
img
)
{
{
gamma_correction
=
false
;
hog
->
gamma_correction
=
false
;
setSVMDetector
(
cv
::
gpu
::
HOGDescriptor
::
getDefaultPeopleDetector
());
hog
->
setSVMDetector
(
cv
::
gpu
::
HOGDescriptor
::
getDefaultPeopleDetector
());
std
::
vector
<
cv
::
Point
>
locations
;
std
::
vector
<
cv
::
Point
>
locations
;
// Test detect
// Test detect
detect
(
loadMat
(
img
),
locations
,
0
);
hog
->
detect
(
loadMat
(
img
),
locations
,
0
);
#ifdef DUMP
#ifdef DUMP
dump
(
cv
::
Mat
(
block_hists
),
locations
);
dump
(
cv
::
Mat
(
hog
->
getBlockHist
()
),
locations
);
#else
#else
compare
(
cv
::
Mat
(
block_hists
),
locations
);
compare
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
locations
);
#endif
#endif
// Test detect on smaller image
// Test detect on smaller image
cv
::
Mat
img2
;
cv
::
Mat
img2
;
cv
::
resize
(
img
,
img2
,
cv
::
Size
(
img
.
cols
/
2
,
img
.
rows
/
2
));
cv
::
resize
(
img
,
img2
,
cv
::
Size
(
img
.
cols
/
2
,
img
.
rows
/
2
));
detect
(
loadMat
(
img2
),
locations
,
0
);
hog
->
detect
(
loadMat
(
img2
),
locations
,
0
);
#ifdef DUMP
#ifdef DUMP
dump
(
cv
::
Mat
(
block_hists
),
locations
);
dump
(
cv
::
Mat
(
hog
->
getBlockHist
()
),
locations
);
#else
#else
compare
(
cv
::
Mat
(
block_hists
),
locations
);
compare
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
locations
);
#endif
#endif
// Test detect on greater image
// Test detect on greater image
cv
::
resize
(
img
,
img2
,
cv
::
Size
(
img
.
cols
*
2
,
img
.
rows
*
2
));
cv
::
resize
(
img
,
img2
,
cv
::
Size
(
img
.
cols
*
2
,
img
.
rows
*
2
));
detect
(
loadMat
(
img2
),
locations
,
0
);
hog
->
detect
(
loadMat
(
img2
),
locations
,
0
);
#ifdef DUMP
#ifdef DUMP
dump
(
cv
::
Mat
(
block_hists
),
locations
);
dump
(
cv
::
Mat
(
hog
->
getBlockHist
()
),
locations
);
#else
#else
compare
(
cv
::
Mat
(
block_hists
),
locations
);
compare
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
locations
);
#endif
#endif
}
}
...
@@ -216,8 +233,8 @@ GPU_TEST_P(HOG, GetDescriptors)
...
@@ -216,8 +233,8 @@ GPU_TEST_P(HOG, GetDescriptors)
// Convert train images into feature vectors (train table)
// Convert train images into feature vectors (train table)
cv
::
gpu
::
GpuMat
descriptors
,
descriptors_by_cols
;
cv
::
gpu
::
GpuMat
descriptors
,
descriptors_by_cols
;
getDescriptors
(
d_img
,
win_size
,
descriptors
,
DESCR_FORMAT_ROW_BY_ROW
);
hog
->
getDescriptors
(
d_img
,
hog
->
win_size
,
descriptors
,
cv
::
gpu
::
HOGDescriptor
::
DESCR_FORMAT_ROW_BY_ROW
);
getDescriptors
(
d_img
,
win_size
,
descriptors_by_cols
,
DESCR_FORMAT_COL_BY_COL
);
hog
->
getDescriptors
(
d_img
,
hog
->
win_size
,
descriptors_by_cols
,
cv
::
gpu
::
HOGDescriptor
::
DESCR_FORMAT_COL_BY_COL
);
// Check size of the result train table
// Check size of the result train table
wins_per_img_x
=
3
;
wins_per_img_x
=
3
;
...
@@ -251,39 +268,39 @@ GPU_TEST_P(HOG, GetDescriptors)
...
@@ -251,39 +268,39 @@ GPU_TEST_P(HOG, GetDescriptors)
img_rgb
=
readImage
(
"hog/positive1.png"
);
img_rgb
=
readImage
(
"hog/positive1.png"
);
ASSERT_TRUE
(
!
img_rgb
.
empty
());
ASSERT_TRUE
(
!
img_rgb
.
empty
());
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
hog
->
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
// Everything is fine with interpolation for left top subimage
// Everything is fine with interpolation for left top subimage
ASSERT_EQ
(
0.0
,
cv
::
norm
(
(
cv
::
Mat
)
block_hists
,
(
cv
::
Mat
)
descriptors
.
rowRange
(
0
,
1
)));
ASSERT_EQ
(
0.0
,
cv
::
norm
(
cv
::
Mat
(
hog
->
getBlockHists
())
,
(
cv
::
Mat
)
descriptors
.
rowRange
(
0
,
1
)));
img_rgb
=
readImage
(
"hog/positive2.png"
);
img_rgb
=
readImage
(
"hog/positive2.png"
);
ASSERT_TRUE
(
!
img_rgb
.
empty
());
ASSERT_TRUE
(
!
img_rgb
.
empty
());
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
hog
->
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
compare_inner_parts
(
cv
::
Mat
(
block_hists
),
cv
::
Mat
(
descriptors
.
rowRange
(
1
,
2
)));
compare_inner_parts
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
cv
::
Mat
(
descriptors
.
rowRange
(
1
,
2
)));
img_rgb
=
readImage
(
"hog/negative1.png"
);
img_rgb
=
readImage
(
"hog/negative1.png"
);
ASSERT_TRUE
(
!
img_rgb
.
empty
());
ASSERT_TRUE
(
!
img_rgb
.
empty
());
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
hog
->
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
compare_inner_parts
(
cv
::
Mat
(
block_hists
),
cv
::
Mat
(
descriptors
.
rowRange
(
2
,
3
)));
compare_inner_parts
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
cv
::
Mat
(
descriptors
.
rowRange
(
2
,
3
)));
img_rgb
=
readImage
(
"hog/negative2.png"
);
img_rgb
=
readImage
(
"hog/negative2.png"
);
ASSERT_TRUE
(
!
img_rgb
.
empty
());
ASSERT_TRUE
(
!
img_rgb
.
empty
());
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
hog
->
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
compare_inner_parts
(
cv
::
Mat
(
block_hists
),
cv
::
Mat
(
descriptors
.
rowRange
(
3
,
4
)));
compare_inner_parts
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
cv
::
Mat
(
descriptors
.
rowRange
(
3
,
4
)));
img_rgb
=
readImage
(
"hog/positive3.png"
);
img_rgb
=
readImage
(
"hog/positive3.png"
);
ASSERT_TRUE
(
!
img_rgb
.
empty
());
ASSERT_TRUE
(
!
img_rgb
.
empty
());
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
hog
->
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
compare_inner_parts
(
cv
::
Mat
(
block_hists
),
cv
::
Mat
(
descriptors
.
rowRange
(
4
,
5
)));
compare_inner_parts
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
cv
::
Mat
(
descriptors
.
rowRange
(
4
,
5
)));
img_rgb
=
readImage
(
"hog/negative3.png"
);
img_rgb
=
readImage
(
"hog/negative3.png"
);
ASSERT_TRUE
(
!
img_rgb
.
empty
());
ASSERT_TRUE
(
!
img_rgb
.
empty
());
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
cv
::
cvtColor
(
img_rgb
,
img
,
CV_BGR2BGRA
);
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
hog
->
computeBlockHistograms
(
cv
::
gpu
::
GpuMat
(
img
));
compare_inner_parts
(
cv
::
Mat
(
block_hists
),
cv
::
Mat
(
descriptors
.
rowRange
(
5
,
6
)));
compare_inner_parts
(
cv
::
Mat
(
hog
->
getBlockHists
()
),
cv
::
Mat
(
descriptors
.
rowRange
(
5
,
6
)));
}
}
INSTANTIATE_TEST_CASE_P
(
GPU_ObjDetect
,
HOG
,
ALL_DEVICES
);
INSTANTIATE_TEST_CASE_P
(
GPU_ObjDetect
,
HOG
,
ALL_DEVICES
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment