From 2e979342cbbfce298c17905cf02c7900214a6f99 Mon Sep 17 00:00:00 2001 From: GabeBolton <33410751+GabeBolton@users.noreply.github.com> Date: Sun, 14 Oct 2018 10:38:25 +1100 Subject: [PATCH] Make resolution and servo pos scale Added width & height variables and made servo positioning work off of width/height percentage instead of hard-coded values. --- face_tracker.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/face_tracker.py b/face_tracker.py index 831f4a6..0a001e9 100644 --- a/face_tracker.py +++ b/face_tracker.py @@ -22,6 +22,10 @@ eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') cap = cv2.VideoCapture(0) +width=480 #adjust these to change dimentions; larger width & height gives better resolution, but slower processing speed +height=360 +cap.set(3,width) +cap.set(4,height) # Defining and initializing globals global panServoAngle @@ -38,25 +42,25 @@ def servoPosition (x, y): global panServoAngle global tiltServoAngle - if (x < 250): + if (x < width*.45): panServoAngle += 10 if panServoAngle > 140: panServoAngle = 140 os.system("python angleServoCtrl.py " + str(panPin) + " " + str(panServoAngle)) - if (x > 300): + if (x > width*.55): panServoAngle -= 10 if panServoAngle < 40: panServoAngle = 40 os.system("python angleServoCtrl.py " + str(panPin) + " " + str(panServoAngle)) - if (y < 160): + if (y < height*.45): tiltServoAngle += 10 if tiltServoAngle > 140: tiltServoAngle = 140 os.system("python angleServoCtrl.py " + str(tiltPin) + " " + str(tiltServoAngle)) - if (y > 210): + if (y > height*.55): tiltServoAngle -= 10 if tiltServoAngle < 40: tiltServoAngle = 40