Hi guys.
Today, I would like to share how to use OpenCV on Jetson Inference.
Jetson Inference examples such as Image Recognition / Detection / Segmentation are using GStreamer, not OpenCV.
However, sometimes it is needed to use OpenCV Mat for image processing.
So, in this posting, I would like to share how to change data gotten from GStreamer to OpenCV Mat type.
Here is my environment
- Device: Jetson Nano
- Camera: USB Camera (Microsoft)
- Using Example: "detectnet-camera.cpp"
Step1. Open "detectnet-camera.cpp" file & Import OpenCV
1-1. Open jetson-inference -> examples -> detectnet-camera -> detectnet-camera.cpp
1-2. Import opencv header as shown below.
//*****************************************
#include "gstCamera.h"
#include "glDisplay.h"
#include "detectNet.h"
#include "commandLine.h"
#include
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
//*****************************************
Step2. Modify functions to access data gotten from GStreamer.
- Modify code as shown below
- We added argument '1' for CaptureRGBA function. For default setting, third argument is set as 'false' which is '0'. If third argument is set as '0', it means captured data will be saved on GPU memory and it is not available to access on the data in normal method. If third argument is set as '1', captured data will be saved on GPU/CPU shared memory. Therefore, we can access on data.
Step3. Convert 1D pointer data to Mat format
- Add following code to convert 1D pointer data to Mat format
Step4. Make
- go to directory "jetson-inference -> build" and enter command "make"
Step5. Check Output
Here is the result
- USB Cam Output
- Picam Output
'NVIDIA Jetson' 카테고리의 다른 글
Jetson Nano Visual Studio Code & Arduino install Guide (2) | 2021.05.12 |
---|---|
YOLOv4 on NVIDIA Jetson Nano (0) | 2021.05.10 |
Getting Started with Jetson Nano (0) | 2019.10.25 |