Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCV Python AttributeError:&x27;模块';对象没有属性';imshow&x27;_Python_Opencv - Fatal编程技术网

OpenCV Python AttributeError:&x27;模块';对象没有属性';imshow&x27;

OpenCV Python AttributeError:&x27;模块';对象没有属性';imshow&x27;,python,opencv,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)

完整代码:

# 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'
回溯(最近一次呼叫最后一次):
文件“test_akaze.py”,第8行,在
cv2.imshow(“预览”,图像)
AttributeError:“模块”对象没有属性“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_形状-lopencv_缝合-lopencv_superres-lopencv_videostab-lopencv_视频-lopencv_仿生-lopencv_ccalib-lopencv_calib3d-lopencv_特征2d-lopencv_面部-lopencv_最新SVM-lopencv_objdetect-lopencv_ml-lopencv_表面匹配-Flanncu-lopencv_xphoto-lopencv_photo-lopencv_imgproc-lopencv_core-lopencv_hal

没有
libopencv\u highgui。因此
存在。你在评论中提到你禁用了VideoIO


按照以下方法创建OpenCV。

尝试将OpenCV库复制到/usr/include,然后再次尝试在终端运行
pkg-config--cflags--libs
并将结果发布到此处。@Dadep您还没有使用gui支持构建OpenCV。@MichelleBergin抱歉,
pkg-config-OpenCV--cflags--libs
。您是从源代码构建OpenCV还是从存储库安装的?@MichelleBergin没有
libopencv\u highgui.so
文件。您没有使用gui支持构建opencv。