Skip to content

Commit

Permalink
Make programs executable
Browse files Browse the repository at this point in the history
* *.py: Changing flags makes the python script
	executable, so we can click the script in the file explorer and
	that's it
* README.md: Add introduction for each program
  • Loading branch information
TravorLZH committed May 19, 2019
1 parent 213edba commit 7a886dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ $ pip3 install opencv-python # This installs numpy as its dependency
$ pip3 install face_recognition # This installs dlib as its dependency
```

I will add more information as the course goes on.
## What this repo has

* **display.py** program to show a picture using OpenCV functions
* **video\_capture.py** to record what's in the webcam
* **mirror\_facedetect.py** to detect faces in the webcam
1 change: 1 addition & 0 deletions display.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import sys
import cv2
import numpy
Expand Down
8 changes: 7 additions & 1 deletion mirror_facedetect.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/usr/bin/env python3
# mirror_facedetect.py: Detect faces in the view of webcam
import cv2
import numpy
import face_recognition
import sys
import os

# Increase this number to speed up and lower the accuracy
k=4

font=cv2.FONT_HERSHEY_PLAIN

# Allow users to change k while running
if len(sys.argv)>=2:
k=int(sys.argv[1])
Expand All @@ -21,6 +25,8 @@ def mark_faces(frm):
for i,face in enumerate(faces):
top,right,bottom,left=face
frm=cv2.rectangle(frm,(k*left,k*top),(k*right,k*bottom),colors[i%3],3)
os.system("clear") # To make the screen not that messy
print("Found {} faces".format(len(faces)))
return frm

camera=cv2.VideoCapture(0)
Expand All @@ -31,7 +37,7 @@ def mark_faces(frm):
break
frm=cv2.flip(frm,1)
# This is just to put rectangle to highlight the faces
mark_faces(frm)
frm=mark_faces(frm)
cv2.imshow('The Mirror',frm)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
4 changes: 3 additions & 1 deletion video_capture.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
import cv2
import numpy # This seems to be useless, but it's needed to operate ndarrays

Expand All @@ -20,9 +21,10 @@
ret, frame=cap.read()
if ret==False:
break
frame=cv2.flip(frame,1) # To make mirror effect
out.write(frame)
cv2.imshow('Camera',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
if cv2.waitKey(50) & 0xFF == ord('q'):
break

# Destroy the camera object
Expand Down

0 comments on commit 7a886dc

Please sign in to comment.