本文整理汇总了Python中HelperFunctions.calcRectInRect方法的典型用法代码示例。如果您正苦于以下问题:Python HelperFunctions.calcRectInRect方法的具体用法?Python HelperFunctions.calcRectInRect怎么用?Python HelperFunctions.calcRectInRect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HelperFunctions
的用法示例。
在下文中一共展示了HelperFunctions.calcRectInRect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: eyeRectsInImage
# 需要导入模块: import HelperFunctions [as 别名]
# 或者: from HelperFunctions import calcRectInRect [as 别名]
def eyeRectsInImage(cvImage, fileName='', detectionDebug=False):
logger = logging.getLogger('ELIME.OpenCVFunctions.eyeRectsInImage')
listOfEyeRects = []
logger.info("Start detecting faces.")
faces = detectFacesInImage(cvImage, detectionDebug)
biggestFace = None
logger.info("%d faces found.", len(faces))
for faceRect in faces:
if not biggestFace:
biggestFace = faceRect
else:
(x, y, w, h) = faceRect
(bx, by, bw, bh) = biggestFace
if w * h > bw * bh:
biggestFace = faceRect
if biggestFace is not None:
logger.debug("biggest face is %s", biggestFace)
(bx, by, bw, bh) = biggestFace
width, height = cv.GetSize(cvImage)
imArea = width * height
bfArea = bw * bh
division = bfArea / float(imArea)
if division > MINFACEPERCENTAGE:
logger.info("%f biggest face size of image size - bigger than threshhold %f. Using face region for eye search.", division, MINFACEPERCENTAGE)
eyes = detectEyesInRectInImage(cvImage, biggestFace, detectionDebug)
for (eyeRect, n) in eyes:
listOfEyeRects.append(HelperFunctions.calcRectInRect(eyeRect, biggestFace))
else:
logger.info("%f biggest face size of image size - smaller than threshhold %f. Search everywhere in image for eyes.", division, MINFACEPERCENTAGE)
eyes = detectEyesInRectInImage(cvImage, None, detectionDebug)
for (eyeRect, n) in eyes:
listOfEyeRects.append(eyeRect)
else:
logger.info("No face found. Search everywhere in image for eyes.")
eyes = detectEyesInRectInImage(cvImage, None, detectionDebug)
for (eyeRect, n) in eyes:
listOfEyeRects.append(eyeRect)
# return new sorted list
listOfEyeRects = sorted(listOfEyeRects, key=lambda rect: HelperFunctions.middleOfRect(rect)[0])
if detectionDebug:
facecolor = cv.RGB(0, 0, 255)
biggestfacecolor = cv.RGB(122, 0, 255)
eyecolor = cv.RGB(255, 255, 0)
rectsAndColor = []
for face in faces:
rectsAndColor.append((face, facecolor))
rectsAndColor.append((biggestFace, biggestfacecolor))
for eye in listOfEyeRects:
rectsAndColor.append((eye, eyecolor))
windowName = "finally {0:d} faces {1:d} eyes in {2}".format(len(faces), len(listOfEyeRects), fileName)
UiFunctions.displayColoredRects(cvImage, windowName, rectsAndColor)
logger.debug("Returning Eyes: %s", listOfEyeRects)
return listOfEyeRects