3

Im currently trying to make a python script for Harris Corner Detection, and I keep getting this error no matter what other articles/fixes I find. Thanks for any help you can give.

Edit: Its the first line of the code that gives the error

Code:

import cv2
import numpy as np

filename = 'chessboard.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

gray = np.float32(gray)
dst = cv2.cornerHarris(gray,2,3,0.04)

#result is dilated for marking the corners, not important
dst = cv2.dilate(dst,None)

# Threshold for an optimal value, it may vary depending on the image.
img[dst>0.01*dst.max()]=[0,0,255]

cv2.imshow('dst',img)
if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()

2 Answers2

1

I had this issue occur also. In my environment settings I had a variable PYTHONPATH pointing to the directory of my Python 2.7 version of cv2.pyd. Updating this to the Python 3.4 version of the cv2.pyd directory fixed it.

Michael
  • 11
  • 1
0

In my case, I have install opencv 2.4.x for windows and copy cv2.pyd to conda home.This works for python2.7, but for python3.x, you can try install opencv follow these step:

1 Activate python3 env and run anaconda search -t conda opencv in command-line,then you will get a table,chose one of them from name column.

2 Then like anaconda show conda-forge/opencv .

3 Last you will find advice and just follow it:

To install this package with conda run:
     conda install --channel https://conda.anaconda.org/conda-forge opencv
Matiji66
  • 709
  • 7
  • 14