3

I'm having an error in OpenCV when I try to run a python code. I tried running

import cv2
import numpy as np
import matplotlib.pyplot as plt
img = cv2.imread("watch.jpg", cv2.IMREAD_GRAYSCALE)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

But I'm getting this error.

OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/pankaja/Desktop/OpenCV-tmp/opencv/modules/highgui/src/window.cpp, line 611 Traceback (most recent call last): File "/home/pankaja/PycharmProjects/ImageProcessing/imageprocess.py", line 8, in cv2.imshow('image', img) cv2.error: /home/pankaja/Desktop/OpenCV-tmp/opencv/modules/highgui/src/window.cpp:611: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon 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

with some errors finally I managed to install libgtk2.0-dev and pkg-config (The following packages have unmet dependencies OpenCV 3.2 Python 3.5), but still the it's giving the error

So, now I think of doing to do a fresh installation on both python 3.5 and OpenCV to fix the problem. How can I uninstall OpenCV completely?

Thidasa Pankaja
  • 930
  • 8
  • 25
  • 44

2 Answers2

4

I had the same problem once. I fixed the problem by completely uninstalling opencv and reinstalling it from source. There are some dependencies like ffmpeg you should install.

EDIT: To completely uninstall opencv

  1. If you installed from source you can use the following command

    make uninstall

run This command from build directory of the opencv source.

  1. If you installed using pip

    sudo pip uninstall opencv

  2. If you Installed using apt-get

    sudo apt-get remove python-opencv

    sudo apt-get purge python-opencv

I hope this might help

Mitiku
  • 5,337
  • 3
  • 18
  • 35
  • I've installed OpenCV using the source. So I ran **make uninstall** . Now when I ran **import cv2** in python3 it says **ImportError: No module named 'cv2'** but there are some folders and files left in usr/ directory (when I searched openCV there are files/folders left) . Is it mean that uninstallation is failed ? – Thidasa Pankaja Sep 05 '17 at 06:13
  • Is it ok delete them manually? Because there's so many [this image of them](http://imgur.com/a/T5txU) , I'm bit scared as I've done somethings before that almost killed my hard drive. Anyway, appreciate your help – Thidasa Pankaja Sep 05 '17 at 06:28
  • 1
    @ThidasaParanavitharana you can safely delete these two folders. /usr/local/share/OpenCV and /usr/local/include/opencv – Mitiku Sep 05 '17 at 06:31
  • I deleted those folders and installed OpenCV again on a virtual environment and now it works fine. – Thidasa Pankaja Sep 07 '17 at 12:35
2

I had the same error for a couple of weeks.So I decided to reinstall the opencv just like you did.

First,sudo pip uninstall opencv or if you installed through apt-get,sudo apt-get remove python-opencv After that,pip install opencv-contrib-python It worked like a charm.Only getting error in video processing.Guess that would take a week to rectify that.

Source:See this if you need any clarification