Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
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
edx
edx-platform
Commits
99ecc784
Commit
99ecc784
authored
Jan 30, 2013
by
Vik Paruchuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix skin tone check
parent
3389802d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
5 deletions
+17
-5
common/lib/xmodule/xmodule/open_ended_image_submission.py
+17
-5
No files found.
common/lib/xmodule/xmodule/open_ended_image_submission.py
View file @
99ecc784
...
...
@@ -74,6 +74,19 @@ class ImageProperties(object):
too_many_colors
=
(
color_count
<=
MAX_COLORS
)
return
too_many_colors
def
check_if_rgb_is_skin
(
self
,
rgb
):
"""
Checks if a given input rgb tuple/list is a skin tone
@param rgb: RGB tuple
@return: Boolean true false
"""
r
,
g
,
b
=
rgb
check_r
=
(
r
>
60
)
check_b
=
(
r
*
0.4
)
<
b
<
(
r
*
0.85
)
check_g
=
(
r
*
0.2
)
<
g
<
(
r
*
0.7
)
return
check_r
and
check_b
and
check_g
def
get_skin_ratio
(
self
):
"""
Gets the ratio of skin tone colors in an image
...
...
@@ -82,10 +95,9 @@ class ImageProperties(object):
colors
=
self
.
image
.
getcolors
(
MAX_COLORS_TO_COUNT
)
is_okay
=
True
if
colors
is
not
None
:
skin
=
sum
([
count
for
count
,
rgb
in
colors
if
rgb
[
0
]
>
60
and
rgb
[
1
]
<
(
rgb
[
0
]
*
0.85
)
and
rgb
[
2
]
<
(
rgb
[
0
]
*
0.7
)
and
rgb
[
1
]
>
(
rgb
[
0
]
*
0.4
)
and
rgb
[
2
]
>
(
rgb
[
0
]
*
0.2
)])
bad_color_val
=
float
(
skin
)
/
len
(
colors
)
skin
=
sum
([
count
for
count
,
rgb
in
colors
if
self
.
check_if_rgb_is_skin
(
rgb
)])
total_colored_pixels
=
sum
([
count
for
count
,
rgb
in
colors
])
bad_color_val
=
float
(
skin
)
/
total_colored_pixels
if
bad_color_val
>
.
4
:
is_okay
=
False
...
...
@@ -101,7 +113,7 @@ class ImageProperties(object):
image_is_okay
=
self
.
count_colors
()
and
self
.
get_skin_ratio
()
and
not
self
.
image_too_large
except
:
pass
return
image_is_okay
...
...
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