opencv 3.2 中 cv2.cv.fromarray 的替换是什么?

What is the replacement of cv2.cv.fromarray in opencv 3.2?

我正在写一个人脸识别程序,我从网上得到的参考是使用以前的 OpenCV 版本。我正在使用从源代码构建的 OpenCV 3.2.0。在参考中将名字放在视频中脸部的正下方。我的参考代码看起来像

cv2.putText(cv2.cv.fromarray(img), str(id), (x, y + h), font, 2, 255);

我收到一个错误:

AttributeError: 'module' object has no attribute 'cv'

请帮忙。

对于 OpenCV 图像的 Python API 是 numpy 数组,因此不需要 fromarray()(如果在 cv 模块中可用) .

有关示例,请参阅 here。您可以将 img 传递给 cv2.putText()