当前位置: 首页>>代码示例>>Python>>正文


Python Scanner.foundFaces方法代码示例

本文整理汇总了Python中Scanner.foundFaces方法的典型用法代码示例。如果您正苦于以下问题:Python Scanner.foundFaces方法的具体用法?Python Scanner.foundFaces怎么用?Python Scanner.foundFaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Scanner的用法示例。


在下文中一共展示了Scanner.foundFaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AutoTurret

# 需要导入模块: import Scanner [as 别名]
# 或者: from Scanner import foundFaces [as 别名]
class AutoTurret(threading.Thread):

	def __init__(self, launcher):
		threading.Thread.__init__(self)
		self.face_cascade = cv2.CascadeClassifier(FACE_CASCADE_PATH)
		self.turretOn = False
		self.launcher = launcher
		self.trackingOn = False
		self.imageReady = threading.Event()
		self.scanner = Scanner(launcher)
		self.img = None
		self.outline = None
#		self.count = 0


	# Processes an image and returns a list of rectangles 
	# of all the faces detected in the image
	# (Returns an empty list if no faces are detected)

	def detectFaces(self, img):
		
		# Grayscales the image for faster/more accurate face detection
		gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

		# Equalizes the image for more accurate results
		gray = cv2.equalizeHist(gray)

		# Processes an image and returns a list of rectangles
		# with the coordinates of all the faces
		#
		# Uses the fastest ScaleFactor, the bare minimum of neighbors,
		# and a large minimum face size to maximize processing speed
		# for the Beaglebone. Also uses to Canny Pruning to increase
		# efficiency of face detection
		outlines = self.face_cascade.detectMultiScale(gray, scaleFactor=1.4, minNeighbors=2, minSize=(50, 50), flags = cv.CV_HAAR_DO_CANNY_PRUNING)
		
		# If there is no face detected, update the scanner count
		# and return an empty list
		if len(outlines) == 0:
			self.scanner.noFaces()
			self.scanner.updateIdleCount()
			return []

		# If faces are found, update the scanner and return
		# the list of rectangles
		print 'Faces Found'
		self.scanner.foundFaces()
		outlines[:,2:] += outlines[:,:2]
		return outlines


	# Draws a rectangle on the image and saves the file
	# in a folder. Used mainly for debugging

#	def drawRect(self, img, outline):
#		if not len(outlines) == 0:
#		x1, y1, x2, y2 = outline
#		cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0) ,2)
#		cv2.circle(img, ((x1 + x2)/2, (y1 + y2)/2), 10, (0, 0, 255), -1)
#		cv2.imwrite('./test/detected' +  str(self.count) + '.jpg', img)
#		self.count += 1
	
	# Gets a rectangle of the target and adjusts the launcher to aim
	# at the center of the target. The amount of time the launcher turns
	# is based off of the distance multiplied by a specific constant

	def tracking(self, img, target):

		# Gets the x and y coords. of the center of the screen
		centerHeight, centerWidth, depth = img.shape
		centerX = centerWidth / 2
		centerY = centerHeight / 2

		# Gets the x and y coords. of the center of the target
		x1, y1, x2, y2 = target
		targetX = (x1 + x2) / 2
		targetY = (y1 + y2) / 2

		# Adjusts the launcher based off the distance away
		# from the target
		if targetX > (centerX + HORIZONTAL_ERROR):
			self.launcher.turretRight()
			time.sleep(self.calculateHorizontalDelay(centerX, targetX))
			self.launcher.turretStop()
		elif targetX < (centerX - HORIZONTAL_ERROR):
                        self.launcher.turretLeft()
                        time.sleep(self.calculateHorizontalDelay(centerX, targetX))
                        self.launcher.turretStop()
		elif targetY < (centerY - VERTICAL_ERROR):
                        self.launcher.turretUp()
                        time.sleep(self.calculateVerticalDelay(centerY, targetY))
                        self.launcher.turretStop()
			self.scanner.updateFireCount()
		elif targetY > (centerY + VERTICAL_ERROR):
                        self.launcher.turretDown()
                        time.sleep(self.calculateVerticalDelay(centerY, targetY))
                        self.launcher.turretStop()
			self.scanner.updateFireCount()
		else:
			print 'Locked on'
#.........这里部分代码省略.........
开发者ID:stephenarifin,项目名称:autoturret,代码行数:103,代码来源:AutoTurret.py


注:本文中的Scanner.foundFaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。