def _cascade_detect(self, raw_image):
''' use opencv cascades to recognize objects on the incomming images '''
cascade = cv2.CascadeClassifier(self._cascade)
image = np.asarray(bytearray(raw_image), dtype="uint8")
gray_image = cv2.imdecode(image, cv2.IMREAD_GRAYSCALE)
color_image = cv2.imdecode(image, cv2.IMREAD_ANYCOLOR)
coordinates = cascade.detectMultiScale(
gray_image,
scaleFactor=1.15,
minNeighbors=5,
minSize=(30, 30)
)
for (x, y, w, h) in coordinates:
cv2.rectangle(color_image, (x, y), (x + w, y + h), (0, 255, 0), 2)
self._logger.debug("face recognized at: x: {}, y: {}, w: {}, h: {}".format(x, y, w, h))
return color_image, self._tojson(coordinates)
评论列表
文章目录