本文整理匯總了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