-1

This is a simple piece of code that executes with no problems from the command line (Python Anaconda 3.5):

import cv2
image = cv2.imread('image.jpg')
a=image.shape[0]
b=image.shape[1]
print("image size " + str(a) + " by " + str(b))

When it runs, you get the expected:

image size 3254 by 4928

However, when running from notepad++ 7.8.1, Windows 7), I get:

Traceback (most recent call last):
  File "C:\Users\Me\Desktop\test.py", line 3, in <module>
    a=image.shape[0]
AttributeError: 'NoneType' object has no attribute 'shape'

C:\Program Files (x86)\Notepad++>

This seems odd. The shortcut for python in Notepad++ is located in C:\Users\Me\AppData\Roaming\Notepad++ , in 'shortcuts.xml'. This is:

 <Command name="python_35" Ctrl="no" Alt="no" Shift="no" Key="0">cmd /K python &quot;$(FULL_CURRENT_PATH)&quot;</Command>

Any thoughts on why this might not be working? If I type 'cmd /K python', I do get the Anaconda version of python (I was wondering if I was seeing another version of python on my system). This doesn't fail on reading the image, so I'm thinking OpenCV is still being loaded.

asylumax
  • 781
  • 1
  • 8
  • 34
  • Use the full image path – Miki Dec 18 '19 at 16:10
  • Does this answer your question? [Running File from Notepad Plus Plus and Current Directory](https://stackoverflow.com/questions/39192941/running-file-from-notepad-plus-plus-and-current-directory) – AMC Dec 18 '19 at 17:47
  • If it solved your issue, you can post an answer to your own question, or delete it entirely. – AMC Dec 18 '19 at 17:47

1 Answers1

0

SOLUTION:

This question seems to solve the problem:

Running File from Notepad Plus Plus and Current Directory

cmd /k cd /d $(CURRENT_DIRECTORY) && python $(FULL_CURRENT_PATH)

The confusing issue was the the error was caused by trying to access image.shape[0]. If the image isn't there, no error occurs on imread; i.e. image=cv2.imread('imagexyz.jpg'), but it will happen when you try to access 'image'. Should check to see the image is there first, i.e.:

import cv2
image = cv2.imread('image_not_there.jpg')
if(image is None):
    print("no image")
else:
    a=image.shape[0]
    b=image.shape[1]
    print("image size " + str(a) + " by " + str(b))
asylumax
  • 781
  • 1
  • 8
  • 34