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
ac41d29e
Commit
ac41d29e
authored
May 14, 2010
by
James Bowman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#301, sample code for CalcHist
parent
9a342ef3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
1 deletion
+66
-1
cv_histograms.tex
doc/cv_histograms.tex
+1
-1
calchist.py
doc/python_fragments/calchist.py
+53
-0
test.py
tests/python/test.py
+12
-0
No files found.
doc/cv_histograms.tex
View file @
ac41d29e
...
...
@@ -159,7 +159,7 @@ int main( int argc, char** argv )
}
\end{lstlisting}
\else
% }{
% \lstinputlisting{
calchist.py}
\lstinputlisting
{
python
_
fragments/
calchist.py
}
\fi
% }
\cvCPyFunc
{
CalcProbDensity
}
...
...
doc/python_fragments/calchist.py
0 → 100644
View file @
ac41d29e
# Calculating and displaying 2D Hue-Saturation histogram of a color image
import
sys
import
cv
def
hs_histogram
(
src
):
# Convert to HSV
hsv
=
cv
.
CreateImage
(
cv
.
GetSize
(
src
),
8
,
3
)
cv
.
CvtColor
(
src
,
hsv
,
cv
.
CV_BGR2HSV
)
# Extract the H and S planes
h_plane
=
cv
.
CreateMat
(
src
.
rows
,
src
.
cols
,
cv
.
CV_8UC1
)
s_plane
=
cv
.
CreateMat
(
src
.
rows
,
src
.
cols
,
cv
.
CV_8UC1
)
cv
.
Split
(
hsv
,
h_plane
,
s_plane
,
None
,
None
)
planes
=
[
h_plane
,
s_plane
]
h_bins
=
30
s_bins
=
32
hist_size
=
[
h_bins
,
s_bins
]
# hue varies from 0 (~0 deg red) to 180 (~360 deg red again */
h_ranges
=
[
0
,
180
]
# saturation varies from 0 (black-gray-white) to
# 255 (pure spectrum color)
s_ranges
=
[
0
,
255
]
ranges
=
[
h_ranges
,
s_ranges
]
scale
=
10
hist
=
cv
.
CreateHist
([
h_bins
,
s_bins
],
cv
.
CV_HIST_ARRAY
,
ranges
,
1
)
cv
.
CalcHist
([
cv
.
GetImage
(
i
)
for
i
in
planes
],
hist
)
(
_
,
max_value
,
_
,
_
)
=
cv
.
GetMinMaxHistValue
(
hist
)
hist_img
=
cv
.
CreateImage
((
h_bins
*
scale
,
s_bins
*
scale
),
8
,
3
)
for
h
in
range
(
h_bins
):
for
s
in
range
(
s_bins
):
bin_val
=
cv
.
QueryHistValue_2D
(
hist
,
h
,
s
)
intensity
=
cv
.
Round
(
bin_val
*
255
/
max_value
)
cv
.
Rectangle
(
hist_img
,
(
h
*
scale
,
s
*
scale
),
((
h
+
1
)
*
scale
-
1
,
(
s
+
1
)
*
scale
-
1
),
cv
.
RGB
(
intensity
,
intensity
,
intensity
),
cv
.
CV_FILLED
)
return
hist_img
if
__name__
==
'__main__'
:
src
=
cv
.
LoadImageM
(
sys
.
argv
[
1
])
cv
.
NamedWindow
(
"Source"
,
1
)
cv
.
ShowImage
(
"Source"
,
src
)
cv
.
NamedWindow
(
"H-S Histogram"
,
1
)
cv
.
ShowImage
(
"H-S Histogram"
,
hs_histogram
(
src
))
cv
.
WaitKey
(
0
)
tests/python/test.py
View file @
ac41d29e
...
...
@@ -1998,6 +1998,18 @@ class DocumentFragmentTests(OpenCVTests):
cv
.
ConvertScale
(
disparity_left
,
disparity_left_visual
,
-
16
)
# self.snap(disparity_left_visual)
def
test_calchist
(
self
):
from
calchist
import
hs_histogram
i1
=
self
.
get_sample
(
"samples/c/lena.jpg"
)
i2
=
self
.
get_sample
(
"doc/pics/building.jpg"
)
i3
=
cv
.
CloneMat
(
i1
)
cv
.
Flip
(
i3
,
i3
,
1
)
h1
=
hs_histogram
(
i1
)
h2
=
hs_histogram
(
i2
)
h3
=
hs_histogram
(
i3
)
self
.
assertEqual
(
self
.
hashimg
(
h1
),
self
.
hashimg
(
h3
))
self
.
assertNotEqual
(
self
.
hashimg
(
h1
),
self
.
hashimg
(
h2
))
class
NewTests
(
OpenCVTests
):
pass
...
...
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