【发布时间】:2018-12-02 19:31:41
【问题描述】:
我的脚本检测到人脸,然后使用 dlib 相关跟踪器算法对其进行跟踪。
我正在尝试使用cv2.imshow(track_index, face_img) 在单独的窗口中显示每个跟踪的人脸,其中face_image 是使用dlib.rectangle 坐标从视频中捕获的帧裁剪的人脸感兴趣区域。
部分代码如下:
#get the updated tracker position
pos = tracker.get_position()
pos = dlib.rectangle(
int(pos.left()),
int(pos.top()),
int(pos.right()),
int(pos.bottom()),
)
#draw a bounding box around the tracked face
cv2.rectangle(image, (pos.left(), pos.top()), (pos.right(), pos.bottom()),
(100, 200, 100))
#crop the face from the frame
face_img = image[pos.top():pos.bottom(),pos.left():pos.right()]
#refers to the number of the track created
track_index = "track no.{}".format(trc - i)
font = cv2.FONT_HERSHEY_TRIPLEX
cv2.putText(image, track_index, (pos.left(), pos.bottom() +12), font, 0.5, (255, 255, 0))
#show the tracked face
cv2.imshow(track_index, face_img)
这可以正常工作,直到面部超出边界或第一次出现在框架边界的一半之外。在这种情况下,程序会停止并引发大小错误。
Traceback (most recent call last):
File "/home/Developing space/facetrack/hog_detect_face_track.py", line 44, in <module>
cv2.imshow(track_index, face_img)
cv2.error: OpenCV(3.4.1) /io/opencv/modules/highgui/src/window.cpp:356: error: (-215) size.width>0 && size.height>0 in function imshow
如何强制框架边框内的 ROI 阻止此错误发生?
【问题讨论】:
标签: python opencv face-detection dlib imshow