python - get_boudingbox 未定义错误(opencv2,python)
问题描述
我正在尝试通过创建边界框从图像中提取人脸,但出现如下所示的错误。
第一个代码块:
def get_predicition(image):
"""Expects the image input, this image further cropped to face
and the cropped face image will be sent for evalution funtion
finally
returns the annotated reusult with bounding box around the face.
"""
height, width = image.shape[:2]
try: # If in case face is not detected at any frame
face = face_detector(image, 1)[0] # Face detection
x, y, size = get_boundingbox(face=face, width=width, height=height) # Calling to get bound box around the face
except IndexError:
pass
cropped_face = image[y:y+size, x:x+size] # cropping the face
output,label = evaluate(cropped_face) # Sending the cropped face to get classifier result
font_face = cv2.FONT_HERSHEY_SIMPLEX # font settings
thickness = 2
font_scale = 1
if label=='Real':
color = (0,255, 0)
else:
color = (0, 0, 255)
x = face.left() # Setting the bounding box on uncropped image
y = face.top()
w = face.right() - x
h = face.bottom() - y
cv2.putText(image, label+'_'+str('%.2f'%output)+'%', (x, y+h+30),
font_face, font_scale,
color, thickness, 2) # Putting the label and confidence values
return cv2.rectangle(image, (x, y), (x + w, y + h), color, 2)# draw box over face
第二个代码块:
cropped_face =[]
for image in images:
faces = face_detector(image[0], 1)
height, width = image[0].shape[:2]
try: # If in case face is not detected at any frame
x, y, size = get_boundingbox(face=faces[0], width=width, height=height)
except IndexError:
continue
cropped_face.append([image[0][y:y+size, x:x+size],image[1]])
第一个代码块运行没有任何错误,但是当我尝试运行第二个代码块时。我收到如下所示的错误:
NameError Traceback (most recent call last)
<ipython-input-48-52e274eb31f6> in <module>
5 try: # If in case face is not detected at any frame
6
----> 7 x, y, size = get_boundingbox(face=faces[0], width=width, height=height)
8 except IndexError:
9 continue
NameError: name 'get_boundingbox' is not defined
解决方案
推荐阅读
- javascript - React - 将函数传递给具有默认道具的组件
- python - Mauch 循环测试问题
- javascript - 探索大量真/假属性的优雅解决方案
- python - 如何从 Python 中的离散数据集创建 3d 热图?
- spring - 在运行时更新 Spring Bean
- flutter - showDatePicker 的标头溢出错误
- drupal - Drupal 7 文件上传字段为空
- c++ - 调试时的 C++ 计时
- postgresql - 聚合嵌套 Pgsql 查询
- python - Pandas Groupby Divide by Last in Sequence by Unique Key