OpenCV Python AttributeError:'module'对象没有属性'imshow'

时间:2017-09-05 17:59:03

标签: python opencv

完整代码:

# 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'

所以我试着研究一个答案。在这个网站上有一个类似的问题,但我试着做他们说的话,但没有帮助:这就是我做的事情

  • Ran as sudo
  • 在imshow
  • 之后添加了cv2.waitKey(0)
  • 将其更改为cv2.waitKey(0)&amp; 0xFF(我不知道这是什么,但我读到了你必须为我的64位机器做的事情)
  • 我已经注释掉了imshow,其他一切都有效。我得到了理想的结果。但imshow似乎没有安装或者其他东西:/

对不起我是个白痴。而我正在黑暗中刺伤。我感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

来自pkg-config opencv --cflags --libs的输出:

  

-I / USR /本地/包括-L / USR /本地/ lib中-lopencv_imgcodecs -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_video -lopencv_bioinspired -lopencv_ccalib -lopencv_calib3d -lopencv_features2d -lopencv_face -lopencv_latentsvm -lopencv_objdetect -lopencv_ml -lopencv_reg - lopencv_surface_matching -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core -lopencv_hal

没有libopencv_highgui.so出席。您在评论中提到您禁用了VideoIO。

关注this link以获得构建OpenCV的最佳方式。