def findFace(self, frame): image = frame.array gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = self.face_cascade.detectMultiScale(gray, 1.3, 5) ret = True for face in faces: ret = self.trackHead(face[0] + face[2] / 2, face[1] + face[3] / 2) if not ret: area = face[2] * face[3] if area < 1000: driver.goForward(0.5) driver.stop() return not ret
def turnBody(): global hasTorqued, state, orient up, left = driver.getServoValues() if left > 6500: driver.goRight(0.5, 1000) driver.stop() elif left < 5500: driver.goLeft(0.5, 1000) driver.stop() else: driver.goLeft(0.01, 0) print("Made it to here!") orient = True return
def scan(frame, *targetColor): global scanDir up, left = driver.getServoValues() targetFound = target.frameContainsTargetColor(frame, *targetColor) if targetFound: driver.goLeft(0, 0) return True if scanDir == 0: if left >= 8000: scanDir = 1 else: driver.lookLeft(100) elif scanDir == 1: driver.lookRight(100) if left <= 4000: scanDir = 0 elif left == 6100: scanDir = 2 elif scanDir == 2: # not in frame, need to turn wheels driver.goLeft(1, 1200) driver.stop() scanDir = 1 # reset scanStat return False
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # State Logic if state == States.startup and not orient: print("Not Orient") frameLocated = scan(image, *colors["ice"]) if frameLocated == True: turnBody() elif state == States.startup and orient: print("Orient") state = States.navigation client.sendData("I'm coming for you human") elif state == States.navigation: driver.goForward(2) driver.stop() client.sendData("Who put all these gosh didly darn rocks here") time.sleep(2) driver.goForward(3) driver.stop() if returnTrip: state = States.dumping declare = True orient = False else: state = States.mining elif state == States.mining: face = faceFinder.findFace(frame) or face