pythonnameerror

Python NameError: name 'harris' is not defined


I apologize in advance if there is somewhere the same thread of mine.
I am new in Python programming and trying to compute an example from "Programming Computer Vision with Python" written by Jan Erik Solem.

Here is the code of the example (saved in a file called "harris.py"):

https://github.com/jesolem/PCV/blob/master/pcv_book/harris.py

(Be aware that my code ends at line 70)

After a good explanation of this code, in the book is stated: "Try running the following commands:"

im = array(Image.open(’empire.jpg’).convert(’L’))
harrisim = harris.compute_harris_response(im)
filtered_coords = harris.get_harris_points(harrisim,6)
harris.plot_harris_points(im, filtered_coords)

The problems I've encountered are two:

  1. I am not sure where to run those last lines of code, in harris.py or in a separate python file.
  2. In whichever file I run it, the following error is shown:

    harrisim = harris.compute_harris_response(im)
    NameError: name 'harris' is not defined

I don't understand why this error is shown, since 'harris' should call the python script harris.py. Or am I wrong?


Solution

  • It is meant to go into a separate file, but you need to import the harris module first:

    import harris
    

    before the module is available to your code.