Skip to content
This repository was archived by the owner on Apr 30, 2023. It is now read-only.

Commit dd7ba5c

Browse files
committed
better styling
1 parent 7d66141 commit dd7ba5c

File tree

3 files changed

+157
-51
lines changed

3 files changed

+157
-51
lines changed

.vscode/.ropeproject/config.py

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# The default ``config.py``
2+
# flake8: noqa
3+
4+
5+
def set_prefs(prefs):
6+
"""This function is called before opening the project"""
7+
8+
# Specify which files and folders to ignore in the project.
9+
# Changes to ignored resources are not added to the history and
10+
# VCSs. Also they are not returned in `Project.get_files()`.
11+
# Note that ``?`` and ``*`` match all characters but slashes.
12+
# '*.pyc': matches 'test.pyc' and 'pkg/test.pyc'
13+
# 'mod*.pyc': matches 'test/mod1.pyc' but not 'mod/1.pyc'
14+
# '.svn': matches 'pkg/.svn' and all of its children
15+
# 'build/*.o': matches 'build/lib.o' but not 'build/sub/lib.o'
16+
# 'build//*.o': matches 'build/lib.o' and 'build/sub/lib.o'
17+
prefs['ignored_resources'] = ['*.pyc', '*~', '.ropeproject',
18+
'.hg', '.svn', '_svn', '.git', '.tox']
19+
20+
# Specifies which files should be considered python files. It is
21+
# useful when you have scripts inside your project. Only files
22+
# ending with ``.py`` are considered to be python files by
23+
# default.
24+
#prefs['python_files'] = ['*.py']
25+
26+
# Custom source folders: By default rope searches the project
27+
# for finding source folders (folders that should be searched
28+
# for finding modules). You can add paths to that list. Note
29+
# that rope guesses project source folders correctly most of the
30+
# time; use this if you have any problems.
31+
# The folders should be relative to project root and use '/' for
32+
# separating folders regardless of the platform rope is running on.
33+
# 'src/my_source_folder' for instance.
34+
#prefs.add('source_folders', 'src')
35+
36+
# You can extend python path for looking up modules
37+
#prefs.add('python_path', '~/python/')
38+
39+
# Should rope save object information or not.
40+
prefs['save_objectdb'] = True
41+
prefs['compress_objectdb'] = False
42+
43+
# If `True`, rope analyzes each module when it is being saved.
44+
prefs['automatic_soa'] = True
45+
# The depth of calls to follow in static object analysis
46+
prefs['soa_followed_calls'] = 0
47+
48+
# If `False` when running modules or unit tests "dynamic object
49+
# analysis" is turned off. This makes them much faster.
50+
prefs['perform_doa'] = True
51+
52+
# Rope can check the validity of its object DB when running.
53+
prefs['validate_objectdb'] = True
54+
55+
# How many undos to hold?
56+
prefs['max_history_items'] = 32
57+
58+
# Shows whether to save history across sessions.
59+
prefs['save_history'] = True
60+
prefs['compress_history'] = False
61+
62+
# Set the number spaces used for indenting. According to
63+
# :PEP:`8`, it is best to use 4 spaces. Since most of rope's
64+
# unit-tests use 4 spaces it is more reliable, too.
65+
prefs['indent_size'] = 4
66+
67+
# Builtin and c-extension modules that are allowed to be imported
68+
# and inspected by rope.
69+
prefs['extension_modules'] = []
70+
71+
# Add all standard c-extensions to extension_modules list.
72+
prefs['import_dynload_stdmods'] = True
73+
74+
# If `True` modules with syntax errors are considered to be empty.
75+
# The default value is `False`; When `False` syntax errors raise
76+
# `rope.base.exceptions.ModuleSyntaxError` exception.
77+
prefs['ignore_syntax_errors'] = False
78+
79+
# If `True`, rope ignores unresolvable imports. Otherwise, they
80+
# appear in the importing namespace.
81+
prefs['ignore_bad_imports'] = False
82+
83+
# If `True`, rope will insert new module imports as
84+
# `from <package> import <module>` by default.
85+
prefs['prefer_module_from_imports'] = False
86+
87+
# If `True`, rope will transform a comma list of imports into
88+
# multiple separate import statements when organizing
89+
# imports.
90+
prefs['split_imports'] = False
91+
92+
# If `True`, rope will remove all top-level import statements and
93+
# reinsert them at the top of the module when making changes.
94+
prefs['pull_imports_to_top'] = True
95+
96+
# If `True`, rope will sort imports alphabetically by module name instead of
97+
# alphabetically by import statement, with from imports after normal
98+
# imports.
99+
prefs['sort_imports_alphabetically'] = False
100+
101+
# Location of implementation of rope.base.oi.type_hinting.interfaces.ITypeHintingFactory
102+
# In general case, you don't have to change this value, unless you're an rope expert.
103+
# Change this value to inject you own implementations of interfaces
104+
# listed in module rope.base.oi.type_hinting.providers.interfaces
105+
# For example, you can add you own providers for Django Models, or disable the search
106+
# type-hinting in a class hierarchy, etc.
107+
prefs['type_hinting_factory'] = 'rope.base.oi.type_hinting.factory.default_type_hinting_factory'
108+
109+
110+
def project_opened(project):
111+
"""This function is called after opening the project"""
112+
# Do whatever you like here!

.vscode/.ropeproject/objectdb

6 Bytes
Binary file not shown.

deal_with_it.py

+45-51
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
import cv2
22

33

4-
eyes = cv2.CascadeClassifier("haarcascades/haarcascade_eye.xml")
4+
eye = cv2.CascadeClassifier("haarcascades/haarcascade_eye.xml")
55
face = cv2.CascadeClassifier("haarcascades/haarcascade_frontalface_alt.xml")
6-
image = cv2.imread("glasses.png", -1)
6+
image = cv2.imread("glasses.png", -1) # -1 includes the alpha channel
77
capture = cv2.VideoCapture(0)
88

9+
def adjust_glasses(h, eyes_w, eyes_h):
10+
''' helper function that computes values to scale/translate glasses '''
11+
12+
# derive initial glasses possition/scale from eyes
13+
v1 = eyes_h * (-1)
14+
v2 = eyes_h * 5
15+
u1 = eyes_w * (-1)
16+
u2 = eyes_w * 8
17+
18+
# normalize values
19+
u1 = max(0, u1)
20+
v1 = max(0, v1)
21+
u2 = min(h, u2)
22+
v2 = min(h, v2)
23+
24+
return v1, v2, u1, u2
25+
926
def deal_with_it(eyes_cascade, face_cascade, glasses_img):
10-
'''live meme generator'''
27+
''' function detects faces and places the classic meme sunglasses on the detected face(s)! '''
1128

12-
#mask
29+
#creates mask
1330
glasses_mask = glasses_img[:, :, 3]
1431
glasses_mask_inv = cv2.bitwise_not(glasses_mask)
1532

@@ -18,74 +35,51 @@ def deal_with_it(eyes_cascade, face_cascade, glasses_img):
1835

1936
while (True):
2037
# Capture video feed
21-
unused, img = capture.read()
22-
frame = cv2.flip(img, 1)
38+
img = capture.read()[1]
39+
frame = cv2.flip(img, 1)
2340

2441
# grayscale
2542
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
2643

27-
faces = face_cascade.detectMultiScale(gray,scaleFactor=1.1,minNeighbors=5,minSize=(30, 30),flags=cv2.CASCADE_SCALE_IMAGE)
44+
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.3, minNeighbors=2, minSize=(15, 25), flags=cv2.CASCADE_SCALE_IMAGE)
2845

2946
for (x, y, w, h) in faces:
3047

31-
roi_gray = gray[y:y+h, x:x+w]
32-
roi_color = frame[y:y+h, x:x+w]
48+
color = frame[y:y+h, x:x+w]
49+
grayscale = gray[y:y+h, x:x+w]
3350

34-
eyes = eyes_cascade.detectMultiScale(roi_gray)
35-
36-
for (nx,ny,nw,nh) in eyes:
37-
38-
glasses_width = nw * 4
39-
glasses_height = orig_glasses_height * 2
40-
area = glasses_width * glasses_height
51+
eyes = eyes_cascade.detectMultiScale(grayscale)
4152

42-
# possition
43-
x1 = nx - glasses_width * 2
44-
x2 = nx + nw + glasses_width * 2
45-
y1 = ny + nh - glasses_height
46-
y2 = ny + nh + glasses_height
47-
48-
# black magic
49-
if x1 < 0:
50-
x1 = 0
51-
if x2 > w:
52-
x2 = w
53-
if y1 < 0:
54-
y1 = 0
55-
if y2 > h:
56-
y2 = h
57-
58-
# adjust bassed on black magic
59-
glasses_height = y2 - y1
60-
glasses_width = x2 - x1
61-
62-
# rescale
63-
glasses = cv2.resize(glasses_img, (glasses_width,glasses_height), interpolation = cv2.INTER_AREA)
64-
mask = cv2.resize(glasses_mask, (glasses_width,glasses_height), interpolation = cv2.INTER_AREA)
65-
mask_inv = cv2.resize(glasses_mask_inv, (glasses_width,glasses_height), interpolation = cv2.INTER_AREA)
53+
for (eyes_x, eyes_y, eyes_w, eyes_h) in eyes:
54+
55+
v1, v2, u1, u2 = adjust_glasses(h, eyes_w, eyes_h)
56+
57+
# resize glasses and masks
58+
glasses = cv2.resize(glasses_img, (u2 - u1, v2 - v1))
59+
mask = cv2.resize(glasses_mask, (u2 - u1, v2 - v1))
60+
mask_inv = cv2.resize(glasses_mask_inv, (u2 - u1, v2 - v1))
6661

6762
# some more black magic
68-
roi = roi_color[y1:y2, x1:x2]
63+
roi = color[v1:v2, u1:u2]
6964

7065
# difference between regions of interest
71-
roi_bg = cv2.bitwise_and(roi,roi,mask = mask_inv)
72-
roi_fg = cv2.bitwise_and(glasses,glasses,mask = mask)
66+
foreround = cv2.bitwise_and(glasses, glasses, mask = mask)
67+
background = cv2.bitwise_and(roi, roi, mask = mask_inv)
7368

74-
# combine regions
75-
dst = cv2.add(roi_bg,roi_fg)
76-
roi_color[y1:y2, x1:x2] = dst
69+
# combines fg and bg of the eyes/glasses region by adding them
70+
color[v1:v2, u1:u2] = cv2.add(foreround, background)
7771

7872
break
7973

80-
# video feed
81-
cv2.imshow("Deal With It @ SalemStateMemes.edu", frame)
74+
# display video feed
75+
cv2.imshow("Sunglass-o-matic", frame)
8276

83-
#exit
84-
if cv2.waitKey(1) == 27: #esc key
77+
# The Escape key has to be pressed to exit the video window
78+
if cv2.waitKey(1) == 27:
8579
break
8680

8781
capture.release()
8882
cv2.destroyAllWindows()
8983

9084
if __name__ == '__main__':
91-
deal_with_it(eyes, face, image)
85+
deal_with_it(eye, face, image)

0 commit comments

Comments
 (0)