2017-09-05 124 views
3

全码:OpenCV的Python的AttributeError的: '模块' 对象有没有属性 'imshow'

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

所以我试图研究一个答案。有在这个网站的类似问题,但我试着做他们说什么,它并没有帮助:这是我做的

  • 跑了作为须藤
  • (0)都imshow后添加cv2.waitKey
  • 将其改为cv2.waitKey(0)& 0xFF的(我不知道这是怎么一回事,但我读的地方,你需要做的是为64位的机器,其矿)
  • 我已经注释掉imshow ,其他一切正常。我得到了预期的结果。但imshow似乎没有安装或什么东西:/

我很抱歉我是这样一个白痴。而我正在刺向黑暗。我感谢任何帮助。

+0

尝试将opencv库复制到/ usr/include,然后再试一次 –

+0

看看您是否已经为某个重要模块命名了一个文件。 – user2357112

+0

@JeruLuke:不要引用格式堆栈跟踪。 – user2357112

回答

2

pkg-config opencv --cflags --libs输出:

-I/usr/local/include -L/usr/local/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的最佳方式。

相关问题