4

Full Code:

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

Error:

Traceback (most recent call last):
  File "test_akaze.py", line 8, in <module>
    cv2.imshow("preview", image)
AttributeError: 'module' object has no attribute 'imshow'

So I've tried to research an answer. There is a similar question on this site but I tried to do what they said and it didn't help: Here is what I did

  • Ran as sudo
  • added cv2.waitKey(0) after both imshow
  • changed it to cv2.waitKey(0) & 0xFF (I have no idea what this is all about but I read somewhere that you have to do that for 64bit machines which mine is)
  • I have commented out the imshow, everything else works. I get the desired result. But imshow seems like it's not installed or something :/

I am sorry I am such an idiot. And I am stabbing at the dark. I appreciate any help.

14
  • Try copying the opencv libs to /usr/include, then try again Commented Sep 5, 2017 at 18:04
  • 1
    In terminal run pkg-config --cflags --libs and post results here. Commented Sep 5, 2017 at 18:07
  • 1
    @Dadep You've not built opencv with gui support. Commented Sep 5, 2017 at 18:09
  • 1
    @MichelleBergin Sorry, pkg-config opencv --cflags --libs. Did you build OpenCV from source or install from repository? Commented Sep 5, 2017 at 18:13
  • 1
    @MichelleBergin There's no libopencv_highgui.so file. You did not build opencv with gui support. Commented Sep 5, 2017 at 18:16

1 Answer 1

2

From the output of 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

There's no libopencv_highgui.so present. You mentioned in the comments that you disabled VideoIO.

Follow this link for best way of building OpenCV.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.