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
f8b23cff
Commit
f8b23cff
authored
Jul 09, 2014
by
pradeep
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed test errors, added support for C data types.
parent
c5b4b993
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
14 deletions
+38
-14
histogram.cpp
modules/imgproc/src/histogram.cpp
+28
-6
test_histograms.cpp
modules/imgproc/test/test_histograms.cpp
+10
-8
No files found.
modules/imgproc/src/histogram.cpp
View file @
f8b23cff
...
...
@@ -2325,13 +2325,16 @@ double cv::compareHist( InputArray _H1, InputArray _H2, int method )
}
else
if
(
method
==
CV_COMP_KL_DIV
)
{
for
(
j
=
0
;
j
<
len
;
j
++
){
for
(
j
=
0
;
j
<
len
;
j
++
)
{
double
p
=
h1
[
j
];
double
q
=
h2
[
j
];
if
(
p
==
0.0
)
if
(
fabs
(
p
)
<=
DBL_EPSILON
)
{
continue
;
if
(
q
==
0.0
)
q
+=
1e-10
;
}
if
(
fabs
(
q
)
<=
DBL_EPSILON
)
{
q
=
1e-10
;
}
result
+=
p
*
cv
::
log
(
p
/
q
);
}
}
...
...
@@ -2370,7 +2373,7 @@ double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
CV_Assert
(
H1
.
size
(
i
)
==
H2
.
size
(
i
)
);
const
SparseMat
*
PH1
=
&
H1
,
*
PH2
=
&
H2
;
if
(
PH1
->
nzcount
()
>
PH2
->
nzcount
()
&&
method
!=
CV_COMP_CHISQR
&&
method
!=
CV_COMP_CHISQR_ALT
)
if
(
PH1
->
nzcount
()
>
PH2
->
nzcount
()
&&
method
!=
CV_COMP_CHISQR
&&
method
!=
CV_COMP_CHISQR_ALT
&&
method
!=
CV_COMP_KL_DIV
)
std
::
swap
(
PH1
,
PH2
);
SparseMatConstIterator
it
=
PH1
->
begin
();
...
...
@@ -2450,6 +2453,18 @@ double cv::compareHist( const SparseMat& H1, const SparseMat& H2, int method )
s1
=
fabs
(
s1
)
>
FLT_EPSILON
?
1.
/
std
::
sqrt
(
s1
)
:
1.
;
result
=
std
::
sqrt
(
std
::
max
(
1.
-
result
*
s1
,
0.
));
}
else
if
(
method
==
CV_COMP_KL_DIV
)
{
for
(
i
=
0
;
i
<
N1
;
i
++
,
++
it
)
{
float
v1
=
it
.
value
<
float
>
();
const
SparseMat
::
Node
*
node
=
it
.
node
();
float
v2
=
PH2
->
value
<
float
>
(
node
->
idx
,
(
size_t
*
)
&
node
->
hashval
);
if
(
!
v2
)
v2
=
1e-10
;
result
+=
v1
*
cv
::
log
(
v1
/
v2
);
}
}
else
CV_Error
(
CV_StsBadArg
,
"Unknown comparison method"
);
...
...
@@ -2795,7 +2810,7 @@ cvCompareHist( const CvHistogram* hist1,
CvSparseMatIterator
iterator
;
CvSparseNode
*
node1
,
*
node2
;
if
(
mat1
->
heap
->
active_count
>
mat2
->
heap
->
active_count
&&
method
!=
CV_COMP_CHISQR
&&
method
!=
CV_COMP_CHISQR_ALT
)
if
(
mat1
->
heap
->
active_count
>
mat2
->
heap
->
active_count
&&
method
!=
CV_COMP_CHISQR
&&
method
!=
CV_COMP_CHISQR_ALT
&&
method
!=
CV_COMP_KL_DIV
)
{
CvSparseMat
*
t
;
CV_SWAP
(
mat1
,
mat2
,
t
);
...
...
@@ -2897,6 +2912,13 @@ cvCompareHist( const CvHistogram* hist1,
result
=
1.
-
result
*
s1
;
result
=
sqrt
(
MAX
(
result
,
0.
));
}
else
if
(
method
==
CV_COMP_KL_DIV
)
{
cv
::
SparseMat
sH1
,
sH2
;
((
const
CvSparseMat
*
)
hist1
->
bins
)
->
copyToSparseMat
(
sH1
);
((
const
CvSparseMat
*
)
hist2
->
bins
)
->
copyToSparseMat
(
sH2
);
result
=
cv
::
compareHist
(
sH1
,
sH2
,
CV_COMP_KL_DIV
);
}
else
CV_Error
(
CV_StsBadArg
,
"Unknown comparison method"
);
...
...
modules/imgproc/test/test_histograms.cpp
View file @
f8b23cff
...
...
@@ -1021,11 +1021,12 @@ int CV_CompareHistTest::validate_test_results( int /*test_case_idx*/ )
sq0
+=
v0
*
v0
;
sq1
+=
v1
*
v1
;
result0
[
CV_COMP_BHATTACHARYYA
]
+=
sqrt
(
v0
*
v1
);
if
(
fabs
(
v0
)
>
DBL_EPSILON
)
{
if
(
fabs
(
v1
)
<
DBL_EPSILON
)
v1
+=
1e-10
;
result0
[
CV_COMP_KL_DIV
]
+=
v0
*
cv
::
log
(
v0
/
v1
);
if
(
fabs
(
v0
)
<=
DBL_EPSILON
)
continue
;
if
(
fabs
(
v1
)
<=
DBL_EPSILON
)
v1
=
1e-10
;
result0
[
CV_COMP_KL_DIV
]
+=
v0
*
std
::
log
(
v0
/
v1
);
}
}
}
...
...
@@ -1052,11 +1053,12 @@ int CV_CompareHistTest::validate_test_results( int /*test_case_idx*/ )
s0
+=
v0
;
sq0
+=
v0
*
v0
;
result0
[
CV_COMP_BHATTACHARYYA
]
+=
sqrt
(
v0
*
v1
);
if
(
fabs
(
v0
)
>
DBL_EPSILON
)
{
if
(
fabs
(
v1
)
<
DBL_EPSILON
)
v1
+=
1e-10
;
result0
[
CV_COMP_KL_DIV
]
+=
v0
*
cv
::
log
(
v0
/
v1
);
if
(
v0
<=
DBL_EPSILON
)
continue
;
if
(
!
v1
)
v1
=
1e-10
;
result0
[
CV_COMP_KL_DIV
]
+=
v0
*
cv
::
log
(
v0
/
v1
);
}
}
...
...
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