gpt4 book ai didi

python - OpenCV Python 属性错误 : 'module' object has no attribute 'imshow'

转载 作者:太空宇宙 更新时间:2023-11-03 21:07:46 25 4
gpt4 key购买 nike

完整代码:

# 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 似乎没有安装或什么的:/

对不起,我是个笨蛋。而我正在刺向黑暗。感谢您的帮助。

最佳答案

根据 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 的最佳方式。

关于python - OpenCV Python 属性错误 : 'module' object has no attribute 'imshow' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46060845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com