Home > front end >  How do I solve unspecified error with cv2.imshow?
How do I solve unspecified error with cv2.imshow?

Time:05-24

My code keeps breaking only at points where I use the cv2.imshow() function. It displays this error: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

It was working fine until after I installed another library, but I'm not sure how that would mess it up. I tried uninstalling that extra library but that didn't do anything to fix the issue. Any ideas? Some of the solutions I've found online are to install with pip install opencv-python, but that's how I installed it initially. I have also tried uninstalling and reinstalling opencv to no avail.

Additional details based on follow-up questions: I'm on a Windows computer using the Pycharm IDE, and I've been installing libraries using pip in the Miniconda app.

Here is what the code looks like. The error happens anytime I try to use imshow, so here's one example of code I run that causes the error:

import cv2

img = cv2.imread("Tropical-tree.jpg")

cv2.imshow("Image", img)
cv2.waitKey(0)

CodePudding user response:

For future reference if anyone else has this issue, here's how I solved it

I had been using an environment I made in the Miniconda3 program. To fix the issue, I made a new environment (also in Miniconda) using this command: conda create --name new_env python=3.6

Opencv works best with python 3.6 rather than the newest update, so it's important to specify the version when creating the environment. Then I went in the environment and reinstalled opencv using pip install opencv-python, and then in Pycharm I switched to use that environment and it worked fine. Hope this helps anyone else who runs into this!

  • Related