【发布时间】:2018-02-14 02:18:37
【问题描述】:
完整代码:
# import the necessary packages
from __future__ import print_function
import cv2
# load the image and convert it to grayscale
image = cv2.imread("jurassic_world.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("preview", image)
# initialize the AKAZE descriptor, then detect keypoints and extract
# local invariant descriptors from the image
detector = cv2.AKAZE_create()
(kps, descs) = detector.detectAndCompute(gray, None)
print("keypoints: {}, descriptors: {}".format(len(kps), descs.shape))
# draw the keypoints and show the output image
cv2.drawKeypoints(image, kps, image, (0, 255, 0))
cv2.imshow("Output", image)
cv2.waitKey(0)
错误:
Traceback (most recent call last):
File "test_akaze.py", line 8, in <module>
cv2.imshow("preview", image)
AttributeError: 'module' object has no attribute 'imshow'
所以我试图研究一个答案。这个网站上有一个类似的问题,但我试着按照他们说的去做,但没有帮助:这就是我所做的
- 以 sudo 身份运行
- 在两个 imshow 之后添加了 cv2.waitKey(0)
- 将其更改为 cv2.waitKey(0) & 0xFF(我不知道这是怎么回事,但我在某处读到,对于我的 64 位机器,您必须这样做)
- 我已将 imshow 注释掉,其他一切正常。我得到了想要的结果。但是 imshow 似乎没有安装或其他东西:/
对不起,我是个白痴。我在黑暗中刺伤。感谢您的帮助。
【问题讨论】:
-
尝试将opencv库复制到/usr/include,然后再试一次
-
在终端运行
pkg-config --cflags --libs并在此处发布结果。 -
@Dadep 你还没有构建带有 gui 支持的 opencv。
-
@MichelleBergin 对不起,
pkg-config opencv --cflags --libs。您是从源代码构建 OpenCV 还是从存储库安装? -
@MichelleBergin 没有
libopencv_highgui.so文件。您没有构建带有 gui 支持的 opencv。