本文整理汇总了Python中Scanner.start方法的典型用法代码示例。如果您正苦于以下问题:Python Scanner.start方法的具体用法?Python Scanner.start怎么用?Python Scanner.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AutoTurret
# 需要导入模块: import Scanner [as 别名]
# 或者: from Scanner import start [as 别名]
#.........这里部分代码省略.........
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'
self.scanner.updateFireCount()
# Calculates the time needed to turn horizontally
def calculateHorizontalDelay(self, center, target):
distance = abs(center - target)
if distance < 100:
return SMALL_DELAY_CONSTANT * distance
else:
return LARGE_DELAY_CONSTANT * distance
# Calculates the time needed to adjust vertically
def calculateVerticalDelay(self, center, target):
return SMALL_DELAY_CONSTANT * abs(center - target)
# When an image is ready, the autoturret will analyze the image
# and detect faces in the image. If there are faces detected,
# the launcher will adjust in order to be on target for the face
def run(self):
# Starts the scanner thread
self.scanner.setDaemon(True)
self.scanner.start()
while(1):
if self.turretOn:
# Waits for an image to be ready from the
# ImageListener thread
self.imageReady.clear()
print 'autoturret waiting'
self.imageReady.wait()
# Reads the second image from the triple
# buffer and analyzes it
print 'Detecting...'
if not (os.listdir(IMG_INPUT_PATH) == []):
pictures = os.listdir(IMG_INPUT_PATH)
pictures.sort()
target = IMG_INPUT_PATH + pictures[len(pictures) - 1]
print target
self.img = cv2.imread(target)
outlines = self.detectFaces(self.img)
# If faces were found in the image
if not len(outlines) == 0:
self.outline = outlines[0]
# self.drawRect(self.img, self.outline)
# Adjust the launcher
self.tracking(self.img, self.outline)
# If no image files were found in the folder
else:
print 'no files found'
def turretStatus(self, state):
self.turretOn = state
def getScanner(self):
return self.scanner
def stop(self):
self.cap.release()
self._Thread__stop()
def ready(self):
self.imageReady.set()