Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
skin_detector
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
人工智能
skin_detector
Commits
a96c8d49
Commit
a96c8d49
authored
Apr 05, 2015
by
WillBrennan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mean_color method
parent
f5c59c18
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
main.py
main.py
+4
-0
mean_color.py
mean_color.py
+36
-0
No files found.
main.py
View file @
a96c8d49
...
...
@@ -11,6 +11,7 @@ import cv2
import
numpy
# Custom Modules
import
scripts
import
mean_color
class
SkinDetector
(
object
):
...
...
@@ -76,6 +77,9 @@ class SkinDetector(object):
logger
.
debug
(
'Initialising process'
)
dt
=
time
.
time
()
self
.
assert_image
(
img
)
logger
.
debug
(
'Generating mean-color image'
)
#img = mean_color.img_mean(img)
logger
.
debug
(
'Conducting thresholding'
)
self
.
n_mask
=
0
self
.
mask
=
numpy
.
zeros
(
img
.
shape
[:
2
],
dtype
=
numpy
.
uint8
)
self
.
get_mask_hsv
(
img
)
...
...
mean_color.py
0 → 100644
View file @
a96c8d49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__
=
'Will Brennan'
# Built-in modules
import
time
import
logging
# Standard modules
import
numpy
import
sklearn.utils
import
sklearn.cluster
as
cluster
# Custom modules
logger
=
logging
.
getLogger
(
'main'
)
def
img_mean
(
frame
,
n_clusters
=
64
):
result
=
frame
.
copy
()
flat_frame
=
frame
.
reshape
(
-
1
,
3
)
frame
=
sklearn
.
utils
.
shuffle
(
flat_frame
)[:
min
(
1000
,
frame
.
shape
[
0
]
*
frame
.
shape
[
1
])]
logger
.
debug
(
'frame shape: {0}'
.
format
(
frame
.
shape
))
logger
.
debug
(
'starting training...'
)
t0
=
time
.
time
()
kmeans
=
cluster
.
KMeans
(
n_clusters
=
n_clusters
,
random_state
=
0
)
.
fit
(
frame
)
logger
.
debug
(
'training took {0}s'
.
format
(
round
(
time
.
time
()
-
t0
,
2
)))
lookup
=
kmeans
.
predict
(
flat_frame
)
label_idx
=
0
for
i
in
range
(
result
.
shape
[
0
]):
for
j
in
range
(
result
.
shape
[
1
]):
result
[
i
][
j
]
=
kmeans
.
cluster_centers_
[
lookup
[
label_idx
]]
label_idx
+=
1
logger
.
debug
(
'label shape: {0}'
.
format
(
result
.
shape
))
result
.
astype
(
dtype
=
numpy
.
uint8
)
return
result
\ No newline at end of file
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