OPENCV 4 + CUDA on Jetson Nano
Вставка
- Опубліковано 20 сер 2024
- How to build and package OpenCV with CUDA support on the NVIDIA Jetson Nano Developer Kit. Please Like, Share and Subscribe! Full article on JetsonHacks: wp.me/p7ZgI9-33e
In the video, we use:
* Jetson Nano
* Raspberry Pi V2 camera
* Samsung T5 Drive
* A 5V, 4A power supply
The items above are available through the JetsonHacks Amazon store front! amazon.com/sho... As an Amazon Associate I earn from qualifying purchases. There's no charge to you, and the channel gets a small commission. Thanks!
Website: jetsonhacks.com
Github: github.com/jet...
Twitter: / jetsonhacks - Наука та технологія
Appreciate your computer vision oriented content on the Jetson nano. Thank You!
I am glad you like the video. Thank you for taking the time to watch it!
Thanks Jim, great Tutorial and a very nice build script!
Thank you for the kind words, and thanks for watching!
Thanks for your reply, which I understand. I asked about this on the NVIDIA forum yesterday and feel that I'm getting the run-around.
WOO! I just ordered a pair of IMX219-200's to go with my jetson dev board! I want to nvenc the streams, send them to my EPYC BEAST for some hard core cuda crunching :D
This is excellent!! Very appreciate for your clear description!
Thank you for your kind words.Thank you for taking the time to watch the video!
Thanks for another great video. Ps: love the [Echo on]GUI, GUI, GUI[Echo off] bit Ps2:Say hello to Bruce for me!
Thank you for the kind words. Bruce says hello back! Thanks for watching!
Thank you Jim !!! Looks very simple to do, and have complete info. Next week I'll try it out. Cheers. Alberto.
You are welcome. However, you should consider using the script from here instead: github.com/mdegans/nano_build_opencv
@@JetsonHacks Thank you Jim !
@@BTXSISTEMAS You are welcome and good luck on your project!
Another awesome JetsonHacks. Thanks!
You are very welcome. Thank you for the kind words, and thanks for watching!
Cool mic, the voice sounds extremely clear
Thank you for the kind words. This venerable Shure 57 has been with me 30 years. There's a reason it is an industry standard. Thanks for watching!
Thank you so much! It's very helpful!
I am glad you found it helpful. Thanks for watching!
As always, great content!! Thanks
You are too kind, you are more than welcome. Thanks for watching!
I was wondering that, excelent video
Thank you fro the kind words, and thanks for watching!
Thanks verry clear
You're welcome! Thanks for watching!
It's really great! Love your videos
Thank you for the kind words, and thanks for watching!
Thanks - saved me a heap of time!
You're welcome! Thanks for watching!
The latest version of the SDK Manager from NVIDIA installs OpenCV 4.1.1 as well.
thanks man , great video very helpful
You are welcome, and thanks for watching!
Thank you
You are very welcome, and thanks for watching!
Thanks You very much!
You are welcome, and thank you for watching!
Fantastic topic!!
Yes it is! Thank you for watching.
@@JetsonHacks at 4:50 you mention you're building it for python, what would change when using opencv in C++ code?
The C/C++ is the heart of the library, you do not have to specify anything for it to build. If you do not intend to build for Python, you can remove the Python build flags. This will save you a large amount of time for the build.
JetsonHacks Thanks!!
on %100 "Building cxx object ............ /src2/cv2.cpp.o"
i am waiting, waiting, waiting but nothing
help please
At 7:50 , you have mentioned "eventually killing the build , restarts make with 1 job" . How do you kill the build without closing the terminal? I am stuck with this step and I cannot move forward without knowing this. In need of your help.
I too have the same problem , need some help.
When the process runs out of memory, it kills itself and returns. Then, make is run again. You can ^C to terminate a process, and the terminal does not close. You may have better luck with the build CV scripts in the mdegans Github repository.
@@JetsonHacks I have the same problem, just stuck and doesn't do anything :c
Thanks for your information, but I'm in trouble with opencv.pc file.
When I follow your tutorial, gcc can't find opencv.
I think the problem is that I didn't make opencv.pc file in /usr/local/lib.
But I really don't know how to solve it......
Can somebody tell me how to solve problem??
I'll very grateful of it.....
Sorry for bad English T.T
Same
Jim, with CUDA 10.2 and OpenCV 4.1.1 fully installed on Jetson Xavier nx, driver for Arducam hq imx477 camera working fine, gst-launch-1.0 command on its own working fine for realtime camera streaming, has it ever happened to you that upon doing object detection with darknet (alexyAB set-up) and yolov4-tiny custom model that the camera started alternating a black screen with a video capture by the second? Any suggestions as to what is wrong? Thank you so much for your tutorials that have helped me a lot.
You are welcome. I have not experienced this issue, perhaps someone in the official NVIDIA Jetson forums can help. Thanks for watching!
@@JetsonHacks hello Jim, I solved the problem by providing direct power supply to the little screen attached and the flashing stopped. It had nothing to do with hardware set-up, but the screen was not getting sufficient power while the object detection was sapping power from the device. Attaching a smaller screen (6 inch vs 10 inch screen) solved the problem as well. Just for your info, because you are connected to many users who may be experiencing similar problems. Best! DD
Thank you for sharing your solution!
I wanted to know what changes are needed to install Opencv to Python3 as it by default getting install to Python2.7 ....Please help me if anyone gets this
Amazing!
Thanks for watching!
Thanks :-)
You are welcome, and thank *you* for watching!
Awesome explanation and walk through. Very helpful. Can you post video for using Nvidia DeepStream SDK on Jetson Nano ?
Thank you for the kind words, and thanks for watching!
after i try getBuildInformation, CUDA is in python 2 but not in python 3, how can i get cuda in python3?
Thanks for all your videos! I love them pretty much!
Currently, I've trained a model in Google COLAB, but the trained model generated is in PYTORCH. So, I'd like to know what I have to do to run this model on the Jetson NANO. Thank you in advance.
It is more efficient for you to look for the answers on the Jetson forums first. For example: forums.developer.nvidia.com/t/pytorch-for-jetson-version-1-10-now-available/72048
Thanks very much for the tutorial. The only issue I experienced was an error with the gstreamer_view.cpp after I pasted the link into the examples directory in the terminal. Any ideas why I might be getting this?
hello, i face some problem to use opencv using webcam on jetson nano, it display error: ( -215 : Assertion failed ) size.width 0.aa size.heights in function ' imshow
Hard to tell from your description what the problem might be.
I kept Num_Jobs=1 since I was installing on a memory card. The installation is completed, however everything seems fine except cUDNN is still No with CUDA enabled. Do I need to add cUDNN in the cMake?
Thank you very much sir! I was wondering how to get this work with another camera other than the Raspberry Pi V2 one ?
I am using a Ricoh Theta V camera (working as a video device thanks to v4l2loopback)
Please ask this question on the official NVIDIA Jetson Nano forum.
Thanks for the guidelines, I'm interested to learn more about the pkg build, is there a referral link that I can look into?
every videos are such intersting and wonderful. can you help me in making darknet frame works on jetsn nano i just wanted to train my own custom object detector(yolov4). its been difficult for me to install darknet executable file especially in make file
Thank you for the kind words. I don't know enough about Darknet to provide any meaningful insight into the issues you are experiencing. Good luck on your project, and thanks for watching!
if we build the opencv4 and we want to use opencv3 how do we do it then?
maybe a bit outdated but I followed this tutorial to install openCV but I did not get the cuDNN installed... any tip? txs for the clarity of the explanation!
It's hard to tell from your description what the issue might be. Are you using a Jetson Nano? What version of cuDNN are you installing? The script tries to use 8.0. Which version of OpenCV are you trying to build. This video has been updated here: ua-cam.com/video/art0-99fFa8/v-deo.html
@@JetsonHacks I saw it... indeed covers those aspects. Trying now!!!!
Thanks!!!
You are welcome, and thanks for watching!
After running and compiling it successfully ,when i ran example, it says package opencv was not found in the pkg-config search path? how to correct this. Thanks
Is the directory containing opencv.pc in the PKG_CONFIG_PATH environment variable?
@@JetsonHacks Checked on your blog and enabled the pkg flag and example is running fine but while running my custom code in vscode every time i have to pkg-config every used library every time like in the example code,I know cmake can do this too but is there any other way. Thanks for reply
Hello, thanks for the vidéo :) What do you mean when you write "restarts make with one job" at 7:51 ? I also had an issue to finish to build but I don't know the command to make it continue ? Thank you again. Jeremy
You are welcome. In the script:
# Consider the MAXN performance mode if using a barrel jack on the Nano
time make -j$NUM_JOBS
if [ $? -eq 0 ] ; then
echo "OpenCV make successful"
else
# Try to make again; Sometimes there are issues with the build
# because of lack of resources or concurrency issues
echo "Make did not build " >&2
echo "Retrying ... "
# Single thread this time
make
if [ $? -eq 0 ] ; then
echo "OpenCV make successful"
else
# Try to make again
echo "Make did not successfully build" >&2
echo "Please fix issues and retry build"
exit 1
fi
fi
The reference is to the second "make", after the comment "# Single thread this time"
Thanks for watching!
@@JetsonHacks Hi, thanks for the many and all super interesting videos. I am also confused around the same issue.
My Jetson is totally stuck now. Am i supposed to kill it and restart the whole process again? or is this something that will happen by itself? It feels very confusing, but I am also a super beginner.
Can you please clarify what is expected to happen and we are supposed to do?
@@pietrolungaro6411 This is not a beginner level project. What are you trying to accomplish by building this?
Hi sir, my jetson nano stuck at "100% Building CXx object ... python2.dir/__/src2/cv2.cpp.o". Screen is freezed and mouse doesnt move now. Do i restart the device? Or it still working? How can i solve this issue. I dont understand what do i change for one job? My problem is about this issue? Please help me :'(
Hello,Sir Iam using Jetson AGX orin and H265 gimbal(camera) using python I used simple opencv cv2.videocapture program using IP address but there is lag in the video how to over come it....
Not quite sure, you probably will need to adjust the GStreamer parameters to better suit your project. It's worth asking this question on the official NVIDIA Jetson forums. Thanks for watching!
@@JetsonHacks Thanks
Hello. Thanks for explanation. Can I cmake contrib library too to run it on nano ?
You are welcome. If you read the script, you will see that the contrib library is included. You can configure OpenCV with any of the CMake flags that you want. Thanks for watching!
@@JetsonHacks delicious :) I think it is good idea to prepare video about options during process of compiling of opencv. I was looking about explanation of flags but no found. Cuda features world etc.
I'm doing as You said in video and contrib is not included. I have to make new flag for non free library in sh file ?
Hello sir . Thanks for informative video.
I have a doubt!
Is the version of cv2 4.1.1 on running it in python3.
I mean entering python3 interpreter ( how you entered python).
Coz in my Jetson when I check version of cv2 using python2 it's 4.1.1 but using python3 it's 3.2.0
I need help to change it to 4.1.1
It would be great if you can help me with this sir.
Hoping you'll reply 😅
Thanks! I see all the all the packages in the build file, what do I run to move this to a new SD installation? Just sudo make install?
sudo make install will install over the default version. If you are going to do that, you should probably purge the old one first. An alternative is to set your paths to the new build. Thanks for watching!
@@JetsonHacks Thanks for the prompt and good information.
I have problems with this version of opencv4, now I have 2 versions of opencv, before this install ROS Melodic and all necessary plugins like opencv(3.2 is installed by default), cv-bridge etc. But now that I install this script I have 2 versions of opencv and when I catkin build my ROS packages that use cv-bridge, it recognizes both and gives me a warning! Do I have to configure opencv 4 with cuda first and then install ROS for it to work well in my packages?
ROS is not linked against OpenCV 4, so you would need to recompile the ROS packages against the newer OpenCV. This is a daunting task unless you know your way around ROS extremely well. Good luck on your project!
So as you compile it with qt, the whole opencv license becomes gpl right? I heard qt takes money for commercial project license..
Depends on how you use it. If it's an open source project, it is LGPL. If it's a commercial product, different rules may apply. It's something you will need to let the lawyers handle.
Your guide are excellent! How can I use python and OpenCV to get a capture in any time from the Raspberry Pi cam at any size?
Thank you for the kind words. I am not sure what you are asking. The RPi camera has certain native formats which is straightforward to bring in to OpenCV. If you want to change the resolution or manipulate the image, it depends on what you do as to the performance. Thanks for watching!
@@JetsonHacks Thanks for answering. What I want to say is that through a command in python3 I could take a picture from the Pi camera specifying the size of the photo. It is for a project, it consists of classifying objects through artificial vision and then being manipulated by a robotic arm. All controlled by the Jetson Nano. The control of the kinematic model for the 6 dof manipulator is already implemented on python3 in the Jetson thanks to your videos.
@@pedrorafaelvidalarias6517 You should experiment and see if it meets your needs. I'm not sure that you need OpenCV 4 for that application, you can probably test it out with the default that is on the Nano.
Hello, Jim, I'm following your videos to build OpenCV in my Jetson nano. I got the OpenCV installed and importing cv2 on python shell compiles it successfully. But when I run the .cpp examples from your folder it gives the following error:
/usr/bin/ld: cannot find -lopencv_contrib
/usr/bin/ld: cannot find -lopencv_legacy
/usr/bin/ld: cannot find -lgstreamer_view.cpp
collect2: error: ld returned 1 exit status
I'm new to jetson nano development. could you please give an idea of why these errors are showing?
I installed openCV 4 but it said it failed downloading the package. what do I have to do to get openCV 4 on my jetson? how can i remove or delete the failed download? thanks!
I don't know what "failed downloading the package" means.
Thanks for your video to begin with. So I have followed the exact same instructions to try to build my OpenCV, but when I printed cv2.getBuildInformation, the output window didn't show anything related cuda as well as the OpenCV modules that supposedly had to come with it, and I am wondering what could be the possible cause of this? I viewed the build log and nowhere did it say it failed to build the .so files. The opencvcuda .so files also existed under the lib directory as I last checked.
Did you found the solution?????
I also appreciate your computer vision oriented content on the Jetson Nano.
I follow the same steps in the video which you have mentioned. However, I have also extended my memory of swap to 4 GB to avoid any kind of failure. I started my build, everything went well but at 100 percent, my build got hung or what should I say . . stopped. I am not able to understand the reason for this. Your help to fix this stuff would be helpful for me :) waiting for a prompt reply
Thank you for the kind words. I am not able to suggest a fix to your issue because I don't understand from your description what the error might be.
@@JetsonHacks Hi, I think he refers to the part you mentioned with "The memory thrashes .... eventually killing the build". I guess many people are experiencing the same issue with the build not being killed and remaining stuck "forever".
How many hours is that "eventually"? Can you please let us know? Maybe something changed with the latest software releases from Nvidia?
Thank you so much sir! By the way, when I do ccmake in build file, it said that the OPENCV_DNN_CUDA and OPENCV_DNN_OPENCL are already turned on. But, when I do print(cv2.getBuildInformation()). It said that cudnn is "NO". (I think this is why I can't use net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)) Do you have any solution for this? Thanks in advance. Ps. I am working on NVIDIA Jetson Nano
can i use this for ubuntu pc , there is any change i should to do
The scripts are for the Jetson CUDA architecture and may need to be different from a desktop environment. Thanks for watching!
Hi Jim, have you tried Jetson Nano with Kinect V2?
No I haven't.
Hi Jim, I downgrade my opencv4 (Nano 4GB) now I want to use again and rebuild, is your video can solve my issue?
This video is a little old, there's a better build script available: github.com/mdegans/nano_build_opencv
Thanks for watching!
@@JetsonHacks ah thanks, I tried to install in someone's blog but it consume about 10gb and then I had to stop it and I came here again, you never regret me:) Really thanks. I hope this installation won't cause big consuming area
Thanks for the video. One question.
I got error like "unsupported GNU version! gcc versions later than 7 are not supported!" while compiling. I see CUDA-10.0 installed in the nano. How did you manage to solve this issue? or you didn't get any error like this?
The video is a few years old, the requirements may have changed. You'll probably have better luck with this script: github.com/mdegans/nano_build_opencv
Thanks for watching!
Many thanks to Mr. Jim (the Master)!!!
If You could please give a hint how to install "CPack_binary" generated *.deb files?
I got 5 of them (OpenCV-unknown-aarch64-dev.deb, *-libs.deb, *-licenses.deb, *-main.deb and *-scripts.deb), do I need to install all of them, and if yes: does the order somehow matter?
Each one of the .deb files holds different parts of your OpenCV build. You can use the dpkg to install the .debs from the command line, or install using the GUI. If you double click the .deb file, it should launch the installer.
@@JetsonHacks Thanks!!!
2 hours, 32.5 minutes. I've got more swap!!! How'd you beat me? 😆
By the way, thank you! Only doing this for Yolov3 and tf2 but I'll make them work with this haha
You're welcome. I probably just got lucky on the speed deal. Thanks for watching!
Thank you so much for your video.
I got successfully built the OpenCV 4.1.1 on jetson nano.
when I try to run the yolov3 object detection code(USB camera) then the code is not using the GPU instead of all the CPU.
please advise.
This is not a question that can be easily answered in a UA-cam comment. You will need to both study a little and configure the OpenCV DNN for GPU usage. Thanks for watching!
@@JetsonHacks thanks for your reply.
I would like to ask , If I follow your build steps, (after successful build ), then if I use (in my code) "GPU supported opencv dnn functions" will automatically use GPU instead of CPU.?
Please advise.
@@SaddamBinSyedI don't understand your question. The video covers installation of a CUDA capable OpenCV. Functions/algorithm that have CUDA support built in will use CUDA (GPU). It is beyond the scope of what we can cover here to evaluate each OpenCV function as to whether it is CUDA enabled or not. I suggest that you do some research to better understand what GPU/CUDA support might mean for your use case.
@@JetsonHacks thank you for your response.
Hi
Congrats for and excelent video!
I didi run the script for Jetson Xavier NX and run smoothly without any problem and even though it installed the CUDA libraries, the cuDNN = No in the build information. Any reason, for this? Any way to solve it?
Did you modify the script to include cuDNN?
@@JetsonHacks No I only run the scrtipt as you do it in the video. Do I hae to include something? where and what?
@@josegregorioperezmagallane3211 You can look here for an example: github.com/mdegans/nano_build_opencv
cheers, which software do you use to record the screen?
I use a separate hardware capture device made by Elgato. It's an older model made by Elgato which records 1080p HDMI over USB to a Macintosh/PC. This video has a separate DSLR video overlayed on top with video editing software. Thanks for watching!
Thanks for the script! Worked flawlessly! For those running it with root on SD card, it took around 3.5 hours.
Running into trouble trying to use DNN_BACKEND_CUDA and DNN_TARGET_CUDA with object detection. (not a member of cv::dnn class). Even though I set the following flags:
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_DNN_CUDA=ON \
Checked the dnn.hpp file of 4.1.1 and DNN_BACKEND(/TARGET)_CUDA wasn't listed there. The master branch is listing it. Any idea how to use it with 4.1.1?
The DNN_CUDA dev confirmed his solution only works with the open cv master branch. Installed it with your script, yolov3 worked well now! Improvement from 12000ms (Cpu only) to 800ms (608px input), 400ms(416px input) and 250ms (300 input)
This is excellent to hear! It sounds like this might make an interesting example to show. Thanks for watching!
Turned out the master branch with full DNN_CUDA support is actually 4.1.2-dev! Tiny-Yolo is running on around 28fps now! I think it would make an awesome article if you implemented opencv cuda_dnn into a ROS node? I couldn't figure out how to properly do it yet without crashing the jetson. :-/
@@masseteilchen3000
Hi there,
which version of OpenCV did you install finally?
Is it 4.1.1 or other? if not 4.1.1 how can I change the 4.1.1 into the master branch on buildOpenCV.sh file?
highly appreciated your help.
This is the modified buildOpenCV.sh which worked for me: pastebin.com/VXQR9fcQ
Remember to use a beefy power supply when running yolo, or run it in 5W mode to prevent crashing.
how much space i required to install this cuda?
It depends on which options you chose to include in your build. You will need quite a bit of room to compile the code. Personally I would have at least 8GB free. As I recall, it takes significantly less than that, but because the build takes a long time it's better not to run out of space. Thanks for watching!
cool!
thanks for .sh file!
You're welcome, and thanks for watching!
@@JetsonHacks may I use CUDA gstreamer for convert images and video on Jetson nano plus raspberry camera to green filtered and red filtered images and video ? Thanks
@@shmeleff_ural This is too involved of an answer for a UA-cam comment. Please ask this question on the official NVIDIA Jetson support forums, where a large group of developers and NVIDIA engineers share their experience.
Will this method/process work for the newer 2GB Jetson nano?
I do not know, I haven't tried it. When you try, make sure that you have the number of jobs = 1. Thanks for watching!
@@JetsonHacks thanks! I did that and it is compiling as I type (about 3 hours in)
What would you recommend as the best IDE for opencv on the nano.
It depends on which programming language you are using. A generally good environment is Visual Studio, especially if you are using Python.ua-cam.com/video/2sHQBTtDz6c/v-deo.html Thanks for watching!
@@JetsonHacks Preferably C++. I have been using visual studio on Windows but have used code::blocks and qt in the past.
@@simonkirkman4673 All three work on the Jetson, whichever you feel the most comfortable with.
just wanted to know, as this opencv 4.x is build with cuda support if i did simple image processing tasks such as generating bounding boxes or writing text on images.... will that be processed by cpu or gpu?? if possible please suggest any way to use gpu to do the task using python3 thanks!!
You should try to use the default OpenCV 3.3.1 and check the GPU usage. You will see that the GPU is used for drawing to the screen. Writing text and drawing boxes aren't really what the CUDA algorithms in OpenCV are about. Thanks for watching!
OpenCL is not supported by the GPU on the Jetson. Typically you would use CUDA on the DNN module, this include setting the Cmake flag
OPENCV_DNN_CUDA to YES
Thanks for watching!
Hi Jim. I compile opencv and oss from your tutorial. I've tried to stream h264 in opencv but video capture has lags. I've found gstreamer in Ubuntu and it has good low latency. I'm digging how to use gstreamer in python 3.6 or 2.7 but can not found. Have you any examples how to do this using gpu of Jetson nano in opencv ?
This is beyond what can be listed in a UA-cam comment. Please ask these questions of the official NVIDIA Jetson Nano forum.
Hello @markopopoland did you overcame the above problem you have mention Iam facing the same issue
is it for python3 too??
Yes. Please read the accompanying article and Github repository for more information. You will be better off if you use Michael de Gans script.
@@JetsonHacks thanks i did it
Getting errors on CMakeOutput.log qnd in CMakeerror.log .how to reaolve sir
Updated video: ua-cam.com/video/art0-99fFa8/v-deo.html