Skip to content

Commit

Permalink
updated code
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Schrapel committed Oct 15, 2020
1 parent 7981fa4 commit df6b1eb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
Binary file added ArUco_marker.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# PCL-Button-Feedback
# Webcam Augmentation with Python and ArUco Markers
This repository demonstrates how easy we can bring emotions back to video chat programs when wearing face masks.
Imagine you are in an important video meeting while you are at a public place or a train where face masks are mandatory. You could be misunderstood as you have limited opportunities to express your emotions.
By attaching an ArUco marker to your face mask and using my Python script you can enhance your .


## OBS + Virtual-Camera-Plugin Tutorial

## Before you start
In diesem Abschnitt soll das Setup für eine virtuelle Kamera beschrieben werden.

1. Zunächst muss folgendes installiert werden:
Expand Down
2 changes: 1 addition & 1 deletion Tutorial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Navigate to **Tools → Virtual Camera** in the main window of OBS Studio. If y
A new window appears. Select the target camera OBS-Camera2 as shown below. Then, press Start and close this window.
![Step 8](/Tutorial/Step_08.jpg)

At the bottom on the main window you should see now an entry of the recorded window in Sources. Press the right mouse button and select filters.
At the bottom on the main window you should see now an entry of the recorded window in Sources. Press the right mouse button and select Filters.
![Step 9](/Tutorial/Step_09.jpg)

A new window appears in which you press the + on the right bottom corner. Then select the VirtualCam.
Expand Down
53 changes: 33 additions & 20 deletions emoji_webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
Press 0 to 9 or - to add emoji
Press w to stop overlaying emojis
Press + to increase the size of the shown emoji
Press - to decrease the size of the shown emoji
This code can help to show emotions with masks in video chats.
I have used parts of my code to teach my students how prototyping and AR can support wearing masks.
"""
Expand All @@ -23,6 +27,13 @@
import cv2
import math

"""Configuration"""

VIDEO_SOURCE = 0 # Number of webcam to use
REZISE_PX = 240 # Size of the emoji in pixels
SCALE = 4 # Initial scale of the emoji



"""returns center of marker"""
def getCenter(prev_res):
Expand Down Expand Up @@ -81,9 +92,11 @@ def isMarker(img , marker):
return greenshare > 0.2

"""Opens webcam (set number according to your machine!)"""
cap = cv2.VideoCapture(0)
# stores the index of the selected emoji
cap = cv2.VideoCapture(VIDEO_SOURCE)

# stores the index of the actual selected emoji
imgindex = -1

"""Load emojis"""
img_emojilove=cv2.imread("Emojis/1F60D_color.png")
img_emojitogune=cv2.imread("Emojis/1F61B_color.png")
Expand All @@ -98,20 +111,6 @@ def isMarker(img , marker):
img_emojihot=cv2.imread("Emojis/1F975_color.png")


"""Resize emojis to 80x80 px"""
img_emojilove=cv2.resize(img_emojilove,(int(80),int(80)))
img_emojitogune=cv2.resize(img_emojitogune,(int(80),int(80)))
img_emojiteeth=cv2.resize(img_emojiteeth,(int(80),int(80)))
img_emojicry=cv2.resize(img_emojicry,(int(80),int(80)))
img_emojicrazy=cv2.resize(img_emojicrazy,(int(80),int(80)))
img_emojimoulth=cv2.resize(img_emojimoulth,(int(80),int(80)))
img_emojihappy=cv2.resize(img_emojihappy,(int(80),int(80)))
img_emojikiss=cv2.resize(img_emojikiss,(int(80),int(80)))
img_emojiangry=cv2.resize(img_emojiangry,(int(80),int(80)))
img_emojilol=cv2.resize(img_emojilol,(int(80),int(80)))
img_emojihot=cv2.resize(img_emojihot,(int(80),int(80)))


"""add emojis to dict"""
emojis= { i : [] for i in range(0,11) }
emojis[0]=img_emojilove
Expand All @@ -126,6 +125,11 @@ def isMarker(img , marker):
emojis[9]=img_emojilol
emojis[10]=img_emojihot

"""Resize emojis to (REZISE_PX x REZISE_PX) px"""
for e in range(0,len(emojis)):
emojis[e] = cv2.resize(emojis[e],(int(REZISE_PX),int(REZISE_PX)))


# stores the previous corners of the marker
prev_res=[]

Expand All @@ -136,7 +140,7 @@ def isMarker(img , marker):
except:
print("Please install module opencv-contrib-python via pip!")
exit()
imgemoji= np.zeros([80,80,3])
imgemoji= np.zeros([REZISE_PX,REZISE_PX,3])


"""starting loop ☺ """
Expand Down Expand Up @@ -168,7 +172,7 @@ def isMarker(img , marker):
# find center position
center=getCenter(prev_res[0][0])
# add emoji to image
scale=(getSize(prev_res[0][0])/80) * 3
scale=(getSize(prev_res[0][0])/REZISE_PX) * SCALE
frame=emojiOverlay(frame , img_emoji , pos=center,scale=scale)

# make emoji motion smooth in case of errors in detecting markers
Expand All @@ -181,19 +185,28 @@ def isMarker(img , marker):
# find center position
center=getCenter(marker)

scale=(getSize(marker)/80) * 2
scale=(getSize(marker)/REZISE_PX) * SCALE
frame=emojiOverlay(frame , img_emoji , pos=center,scale=scale)
break

cv2.imshow('Webcam',frame)

"""press q to stop webcam recording"""
"""press w to delete emoji overlay"""
"""press + to increae size of the emoji"""
"""press - to decreae size of the emoji"""
k = cv2.waitKey(1) % 256

if k == ord('q'):
break
elif k == ord('+'):
SCALE+=0.5
elif k == ord('-'):
SCALE-=0.5
if SCALE<=0:
SCALE=0.5
else:
"""press w to delete emoji overlay"""

if k == ord('w'):
imgindex = -1
"""press 0 to 9 or ß or - to add overlayed emoji"""
Expand Down

0 comments on commit df6b1eb

Please sign in to comment.