Jetson Nano latest SD card image (r32.3.1) contains openCV 4.1.1 but no ".py" source

I recently bought a Jetson Nano developer kit and downloaded the latest SD card image, r32.3.1. Created the SD card, booted the nano, installed the code-OSS (free version of Microsoft’s Visual Studio IDE) to develop Python programs. (I am following along a Youtube series “AI on the Jetson Nano” found at www.toptechboy.com.) The version of openCV on the SD card is 4.1.1. All is working okay as far as entering and running Python programs, but I do notice that I do NOT get “code completion” help when entering a statement. For example, watching the Youtube videos, when the presenter types

frame=cv2.rectangle()

it results in a popup showing the parameters for rectangle, and when the presenter types

fnt=cv2.FONT

(and pressing Ctrl-space maybe; this is what I do in the Eclipse IDE on my regular PC when developing Java programs) results in a popup showing a list of fonts.

However, on my nano, when I type the same thing (within the IDE of course), I do not get the “code completion” hints. I do get the hints when entering statements that do not refer to cv2 items (such as “np.” and pressing Ctrl-space does produce suggestions). Doing some research, I found what I think is why. Run the following simple Python program. From a terminal window or within the IDE.

******** Begin program ********
import cv2
print(cv2.version)
print(cv2.file)
******** End program ********

The output I see on my Jetson Nano is

4.1.1
/usr/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so

There should be a file ending with “.py” and/or “.pyc”. The “.py” one contains source that (I think) the code-OSS IDE needs to produce the code completions. As shown by the output for my system, I do not have such a file, hence no code completions. If I do the same thing, but do “import numpy as np” as the first line and “print(np.file)” as the third line I see

/usr/lib/python3/dist-packages/numpy/init.py

Doing a “ls” on the numpy subdirectory shows several “.py” files that are numpy related. Doing a “ls” on the above cv2 subdirectory shows a few “.py” files, none of which is cv2 related; the python-3.6 subdirectory only contains the “.so” file. This explains to me why I see code completion hints for non-cv2 items but do not see hints for cv2 items.

In summary, it appears that the current SD card image does not contain any cv2 related Python source files. This explains (to me) why there are no cv2 related code completion hints shown in the IDE.

The “toptechboy” presenter is using an earlier version of the SD card. He did have to go through some contortions (watch video 10 where he installed opencv) to get opencv installed. His version is 3.3.1. Apparently, the Python source is present, so he does see code completion hints.

Is there something I can do to get the hints with my SD card? Having the code completion hints would be a great help for a developer.

I am a newbie to the Jetson Nano, so I could be missing something simple.

Hi,
Do you also have OpenCV4.1.1 on your regular PC? It looks like the deviation is from 3.3.1 to 4.1.1. We don’t have modification to OpenCV code. Ideally it should not have different behavior if the PC and Nano are both 4.1.1.

I do not have OpenCV on my regular PC. It is running Fedora 30. Doing a check, I see that issuing “dnf install python3-opencv” would install 3.4, not 4.1.1, so I would not be comparing apples to apples. I understand that I can install OpenCV4.1.1 from source, but I do not want to do that on my regular PC.

I’ve spent the last several hours researching this and have come up empty. Since I’m a newbie to the Nano and OpenCV, I’m not sure how cv2 related python source would be installed.

On my Nano, running “apt-get install --dry-run python3-opencv” shows that it would install 3.2. How did Nvidia build the supplied OpenCV4.1.1?

Is it possible to get an earlier version of the SD card image? The videos I’m watching began in August 2019, so the presenter probably started with an SD card from around that time. I’m willing to try to duplicate what he did if I can get that image.

Hi,
For re-install opencv, please check
https://devtalk.nvidia.com/default/topic/1064776/

You originally stated that “… the deviation is from 3.3.1 to 4.1.1”. I want to start from scratch with the older SD card image to see what’s present for openCV. In particular, I would like to see if code completion works.

As I stated in my previous post, I am willing to check this if I can get the earlier SD card image.

I think we are miscommunicating. Let me start over.

  1. I am using the latest SD card image, nv-jetson-nano-card-image-r32.3.1.zip. The version of openCV on that card image is 4.1.1.
  2. Installed numpy via “sudo apt-get install python3-matplotlib” which installs matplotlib and numpy.
  3. Installed the code-OSS IDE and configured it for python3. When entering source, code completion works for basic python3 and works for matplotlib and numpy. Code completion does not work for cv2, which is in openCV.
  4. The version of openCV that WOULD be installed via apt-get is 3.2. Run “sudo apt-get install --dry-run python3-opencv” to verify.
  5. Based on item 4, the version of openCV that is part of the latest card image was packaged some other way. Searching the nvidia forum yielded the following link

https://devtalk.nvidia.com/default/topic/1070109/jetson-nano/how-to-properly-install-and-configure-opencv-in-an-environment-/

which links to two ways to build openCV from source. Perhaps this is what was done for the current SD card image.
6. As mentioned in my original post, I am following along a Youtube series “AI on the Jetson Nano”. See www.toptechboy.com. The python source the presenter enters in the videos has code completion for cv2 statements. However, the videos started back in August, 2019, so the SD card image being used is different. There apparently was a problem with openCV and python on the image used–watch the Lesson 10 video to see how it was solved. In short, the fix was to perform the install mentioned in item 4, then immediately remove it. The presenter mentioned that this technique was suggested in the nvidia forums.
7. All I want is for cv2 code completion to work. It does not for the latest card image. It does work for the card image used in the Youtube videos.
8. I finally noticed that previous SD card images are available at

https://developer.nvidia.com/embedded/downloads#?tx=$product,jetson_nano

My old eyes missed it until late yesterday. I found in the video for Lesson 1 that the card image used was jetson-nano-sd-card-image-r32.2.zip. It is for JP 4.2.1 and was released 2019/07/19.

As mentioned in my previous post, I plan to use this earlier SD card image and try to understand why cv2 code completion works. It might shed some light on why cv2 code completion does not work on the current SD card image.

Test results using the 2019/07/19 SD card image (jetson-nano-sd-card-image-r32.2.zip).

  1. Booted the nano. Opened a terminal.
  2. Python 2 sanity test.
    2.1. python
    2.2. import cv2 (successful)
    2.3. print(cv2.version)
    2.4. output: 3.3.1
    2.5. print(cv2.file)
    2.6. output: /usr/lib/python2.7/dist-packages/cv2.so
    2.7. End python 2 sanity test; exit python.
  3. Python 3 sanity test 1.
    3.1. python3
    3.2. import cv2
    3.3. Error: numpy.core.multiarray failed to import
    3.4. import numpy as np
    3.5. Error: ModuleNotFoundError: No module named numpy
    3.6. End first python 3 sanity test; exit python.
  4. sudo apt-get install python3-matplotlib (Note: this also installs numpy)
  5. Python 3 sanity test 2.
    5.1. python3
    5.2. import numpy as np (successful)
    5.3. import cv2 (successful)
    5.4. print(cv2.version)
    5.5. output: 3.3.1
    5.6. print(cv2.file)
    5.7. output: /usr/lib/python3.6/dist-packages/cv2.cpython-36m-aarch64-linux-gnu.so
    5.8. End second python 3 sanity test; exit python.
  6. Run simple OpenCV program from terminal. Ran successfully. Source not included here. Will post it if requested.
  7. Install code-OSS IDE. Follow instructions in the video series Lesson 8 mentioned above.
  8. Test same simple OpenCV program within the IDE.
    8.1. Open the source. Right-click; select run from terminal; run it. Successful.
    8.2. Test code completion.
    8.2.1. Begin a new line in the source: “fnt=cv2.FONT”.
    8.2.2. After entering the text, press Ctrl-spacebar. Suggestions appear.
    8.2.3. Code completion (Intellisense) appears to work for cv2 related items.
    8.3. End IDE test.
  9. Not necessary, but did step 8 for python 2. Same results.

Summary.

  1. OpenCV appears to be correctly installed for python 2 on the 2019/07/19 SD card image.
  2. OpenCV was not correctly installed for python 3 on the 2019/07/19 SD card image. Had to install numpy. After that, OpenCV appears to be okay.
  3. Code completion of cv2 related code seems to work within the code-OSS IDE for the 2019/07/19 SD card image.
  4. After doing the above testing, continued researching what might be wrong with the latest SD card image dated 2019/12/17. Nothing helpful found.
  5. Test steps 6 and 8, listed above, uncovered another issue with the 2019/12/17 SD card image. A new item will be posted to the forum. It pertains to errors using a webcam. The errors do not occur when using the 2019/07/19 SD card image.

There’s a typo in step 4 of the 02/05/2020 “Test results” post. “sudo apt-get install matplotlib” should be 'sudo apt-get install python3-matplotlib". I entered it correctly when performing the steps but typed it wrong here.

More thoughts about the code completion issue. Since code completion works for OpenCV when using the 2019/07/19 SD card image, and I cannot find any cv2-related python source files, the IDE is finding what is necessary elsewhere, perhaps within the cv2.so file (see steps 2.7 and 5.7). The location of the cv2.so file when using the 2019/12/17 SD card image is two subdirectories further down from the dist-packages subdirectory (see the initial 01/31/2020 post above). This is a difference, but I do not know if it is significant. Any ideas?

If you put your mouse near the top of your post, you can click on the pencil icon to edit the post so you can fix your typo. The icons appear in the upper right corner of your post.

Thanks! Fixed it (and discovered strikethrough). I’m new to the forum, so I have a lot to learn.

I really appreciate this post. I am having exactly the same problem and came here looking for a solution. I too am following the TopTechBoy videos and I am at the install openCV stage, but with the most recent Disk Image that uses cv2 4.1.1, I updated to SDK 4.4 and still the same problem that intellesense does not function. Did you ever find a solution? Or do I need to revert back to the old image?

Paul (TopTechBoy) says he has a fix for the Intellisense problem. It will be shown in the Lesson 48 video, scheduled for July 1, 2020. A long time to wait. However, If you click on Lesson 48, then click on “SHOW MORE”, you will see hints at what he did to fix the problem. I wish he’d show that video sooner.

Ok, thank you. I am investigating how to set up python environments. The lead python programmer for VS code says it works if you have the correct environment… whatever that means. I will keep this post updated if I find anything out.

Here’s a clip from the TopTechBoy Lesson 48 page that tells you what to do to fix the problem:

********** Begin clip **********
These are the commands used in the video: Add these settings inside the { } : “python.linting.pylintArgs”: [“–generate-members”, “–extension-pkg-whitelist=cv2”], “python.autoComplete.extraPaths”: [“/usr/lib/python3.6/dist-packages/cv2/python-3.6”]
********** End clip **********

I believe that these are settings within Code-OSS (the IDE). Where to add these settings I do not know. Watching the video will explain it. I vaguely recall when I was doing my own research on this problem, I ran across something about setting “python.autoComplete.extraPaths” but did not pursue it. Maybe someone on your end can make sense of this.

Yes, this seems to be the “right general area”. donjayamanne.github.io is the website where I first saw this. The problem is I do not fully understand what these folks are talking about. There is, apparently, a proper way to install python versions and the associated workspace, these are called “environments”. I am trying to figure out how to do that. In a nutshell, we store each python version and all imports etc. in their own space “directories” I think. This allows us to update python etc and not break things. I just need to find out how to do it without all the computer science language… lol I’ll keep you posted

Just after I posted this… I found A quick-and-dirty guide on how to install packages for Python reading it now lol

Another guide that looks useful:
Pipenv & Virtual Environments — The Hitchhiker's Guide to Python

Found where these statements go … Look into the following to see the details: Editing Python Code in Visual Studio Code

I have not done it yet. I will be working through setting up environments today, seems simple enough and makes sense to do, but I need to reflash and set things up again so it will take awhile.

ok, I have success. to get this working… AND it does work!
open code-oss
goto file->preferences->settings
select User Settings (Tab at top)
select Extensions
select Python
in python you will see an option “Edit in settings.json” (any of these will work)
this opens up the editor on the file settings.json
in this file are the two braces {with text in between}
mine looked like:
{
“python.pythonPath”: “/usr/bin/python3”
}
you need to do the following:

  1. add a comma to the last line in your list what ever it is.
    In my case:
    {
    “python.pythonPath”: “/usr/bin/python3”,
    }
  2. add the 2 lines provided to the end of the list after the comma you added:
    In my case:
    {
    “python.pythonPath”: “/usr/bin/python3”,
    “python.linting.pylintArgs”: [“–generate-members”, “–extension-pkg-whitelist=cv2”],
    “python.autoComplete.extraPaths”: [“/usr/lib/python3.6/dist-packages/cv2/python-3.6”]
    }
    do a save all from the files drop drop down tab and restart …

and as Paul would say, BOOM! it works

Note: If you cut and paste, you may have problems with some of the characters, I did, I ended up just typing it into the editor.

Excellent! I will dust off my old r32.3.1 SD card and try it later today. Right now I have chores to do.

BTW I am using the newest image (r32.4.2) from nVidia and so far all is working well with Pauls’ tutorials… which I can now get back to… good luck and have fun my friend I am glad we got this resolved.

I finally got around to trying this. It does work! I now see code completion for cv2.xxx stuff.

Question: you enclosed the pylintArgs statement within a pair of **. Does this make it a comment? I ask because, following Paul’s instructions, we skipped getting pylint installed early on.

Your next response says you are using the newest image (r32.4.2), which is what I was thinking of doing as well. Glad to hear intellisense, with the settings.json updates, works.

However, as indicated in my original post, I am also having other problems with r32.3.2 with regard to my web cam, a Logitech C920S:

  1. default width and height are 2304 and 1536; had to do a cv2.set to get the width and height set to 640 and 480. (initial cam.get(cv2.CAP_PROP_FRAME_WIDTH)=2304.0; similar for height.)
  2. default frame rate shows as 2. (cam.get(cv2.CAP_PROP_FPS)=2.0.)

I do NOT have these issues with the old r32.3.1 and intellisense works. Because of this, I plan to stay with it for now. I may try the newest image to see if these two issues still exist, but since it is a Developer Preview, I will probably wait for the official version. That means I can only watch Paul’s latest videos–can’t do the facial recognition. Grumble.