imagenet-camera - how to compile/build?

Hello,

I just made some small changes to the C++ imagenet-camera example to fit my needs. (using USB Camera and some output changes)
(https://github.com/dusty-nv/jetson-inference/blob/master/imagenet-camera/imagenet-camera.cpp)

In the tutorial the process is mentioned:
note: by default, the Jetson’s onboard CSI camera will be used as the video source. If you wish to use a USB webcam instead, change the DEFAULT_CAMERA define at the top of imagenet-camera.cpp to reflect the /dev/video V4L2 device of your USB camera…

Now I tried to compile my changes and I get errors like “gstCamera.h” is missing. (which I was expecting…)

Can someone tell me how to compile/build this properly? (Sorry I am not so familar to the “make” process)

I only want to build my modified imagenet-camera.cpp, which is called “imagenet-camera_mod.cpp”

If you are building your modified project out-of-tree, you probably need to add an include directory to your compiler’s include path (jetson-inference/build/aarch64/include). Or you could run ‘sudo make install’ on jetson-inference repo and it will install the headers to a common system location.

If you continue having issues, it may be easier to just modify imagenet-camera.cpp directly, or to copy the imagenet-camera folder in the source tree and add your new folder to jetson-inference/CMakeLists.txt

Whenever you add new source file or subproject to jetson-inference, re-run ‘cmake …/’ step from the build directory to pick up the changes.

Dear all,

I try to modify ~/jetson-inference/imagenet-camera to use my webcam

suryadi@nonaku:~/jetson-inference/imagenet-camera$ ls -la
drwxr-xr-x  3 suryadi suryadi  4096 Apr 17 23:35 .
drwxr-xr-x 21 suryadi suryadi  4096 Apr 17 13:08 ..
-rw-r--r--  1 suryadi suryadi 65279 Apr 17 23:35 CMakeCache.txt
drwxr-xr-x  7 suryadi suryadi  4096 Apr 17 23:30 CMakeFiles
-rw-r--r--  1 suryadi suryadi  2563 Apr 17 23:27 cmake_install.cmake
-rw-r--r--  1 suryadi suryadi   946 Apr 17 23:35 CMakeLists.txt
-rw-r--r--  1 suryadi suryadi  5721 Apr 17 13:05 imagenet-camera.cpp
-rw-r--r--  1 suryadi suryadi  5749 Apr 17 23:02 imagenet-webcam.cpp
-rw-r--r--  1 suryadi suryadi  9219 Apr 17 23:27 Makefile
suryadi@nonaku:~$ v4l2-ctl --list-devices
Webcam C170 (usb-70090000.xusb-2.2):
	/dev/video0

I try

suryadi@nonaku:~$ cat /dev/v4l/by-id/*
cat: /dev/v4l/by-id/usb-_Webcam_C170-video-index0: Invalid argument

Why is it shows invalid argument?

How to find the index of /dev/video V4L2, so I can change -1 into my webcam index?

I try to use index = 1.

#define DEFAULT_CAMERA 1

Then I modify my CMakeList.txt as follows:

# require CMake 2.8 or greater
cmake_minimum_required(VERSION 3.10)

# declare my-recognition project
project(imagenet-webcam)

# import jetson-inference and jetson-utils packages.
# note that if you didn't do "sudo make install"
# while building jetson-inference, this will error.
find_package(jetson-utils)
find_package(jetson-inference)

# CUDA and Qt4 are required
find_package(CUDA)
find_package(Qt4)

# setup Qt4 for build
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})

file(GLOB imagenetCameraSources *.cpp)
file(GLOB imagenetCameraIncludes *.h )

# compile the imagenet-webcam program
cuda_add_library(jetson-inference SHARED ${inferenceSources})
# cuda_add_executable(imagenet-webcam imagenet-webcam.cpp)
cuda_add_executable(imagenet-webcam ${imagenetCameraSources})

# link my-recognition to jetson-inference library
target_link_libraries(imagenet-webcam jetson-inference)

install(TARGETS imagenet-webcam DESTINATION bin)

Then I issue command: $ cmake .

suryadi@nonaku:~/jetson-inference/imagenet-camera$ cmake .
CMake Error at /usr/share/cmake-3.10/Modules/FindCUDA.cmake:1801 (add_library):
  add_library cannot create target "jetson-inference" because an imported
  target with the same name already exists.
Call Stack (most recent call first):
  CMakeLists.txt:25 (cuda_add_library)

-- Configuring incomplete, errors occurred!
See also "/home/suryadi/jetson-inference/imagenet-camera/CMakeFiles/CMakeOutput.log".
See also "/home/suryadi/jetson-inference/imagenet-camera/CMakeFiles/CMakeError.log".

At my /usr/local/lib:

suryadi@nonaku:/usr/local/lib$ ls -la
total 3140
drwxr-xr-x  4 root root     4096 Apr 17 14:25 .
drwxr-xr-x 11 root root     4096 Mar 13 16:34 ..
-rw-r--r--  1 root root  1351536 Apr 17 14:25 libjetson-inference.so
-rw-r--r--  1 root root  1844312 Apr 17 14:25 libjetson-utils.so
drwxrwsr-x  4 root staff    4096 Des 13 13:17 python2.7
drwxrwsr-x  3 root staff    4096 Mei 18  2018 python3.6

How to correct this matter? Thank you very much in advance.

Warmest Regards,
Suryadi

Hi Suryadi, this bit says your webcam device is mounted at /dev/video0, so the device index = 0

suryadi@nonaku:~$ v4l2-ctl --list-devices
Webcam C170 (usb-70090000.xusb-2.2):
	/dev/video0

So #define DEFAULT_CAMERA 0 in imagenet-camera.cpp

I would recommend editing imagenet-camera.cpp directly first, and then simply recompiling by running make command. Then once you get it working, you can move on to adding your own application to the build.

Dear Dusty,

Please help to make CMakeList.txt correctly, so I freely create another program beside from the repository.

I mesh up the imagenet-camera program then I delete ~/jetson-inference directory and restart from the start.
Is there a way so I did not need to cmake …/ (because it must download all the neural network from the start again)?

thank you very much in advance.

warmest regards,
suryadi

Dear Dusty,

After I finished sudo make install steps again then

suryadi@nonaku:~/jetson-inference/build/aarch64/bin$ v4l2-ctl -V

Format Video Capture:
	Width/Height      : 640/480
	Pixel Format      : 'YUYV'
	Field             : None
	Bytes per Line    : 1280
	Size Image        : 614400
	Colorspace        : sRGB
	Transfer Function : Default (maps to sRGB)
	YCbCr/HSV Encoding: Default (maps to ITU-R 601)
	Quantization      : Default (maps to Limited Range)
	Flags             :

I edit imagenet-camera.cpp

// from gstCamera* camera = gstCamera::Create(DEFAULT_CAMERA);
	gstCamera* camera = gstCamera::Create(640, 480, DEFAULT_CAMERA);

It works

Please help me, how to compile just imagenet-camera.cpp alone. Because I need to create another program outside the repository environment.

~/jetson-inference/imagenet-camera$gcc -I /home/suryadi/jetson-inference/build/aarch64/include/ /usr/include/gstreamer-1.0/ -L /home/suryadi/jetson-inference/build/aarch64/lib imagenet-camera.cpp

the error is as follow:
In file included from imagenet-camera.cpp:23:0:
/home/suryadi/jetson-inference/build/aarch64/include/gstCamera.h:26:10: fatal error: gst/gst.h: No such file or directory
 #include <gst/gst.h>
          ^~~~~~~~~~~

gst.h is at /usr/include/gstreamer-1.0/

Thank you very much in advance.

Warmest Regards,
Suryadi

Selection_081.png

Dear all,

After I download NVIDIA-Aerial-Drone-Dataset.tar.gz (7.1 GB), I ran out space at my Jetson Nano. So I move whole directory jetson-inference from /home/suryadi into /media/suryadi/TOSHIBA EXT (1 TB external harddisk).

When I try to compile programs, it give error as follow:

/media/suryadi/TOSHIBA EXT/jetson-inference/build$ cmake ../
CMake Error: The current CMakeCache.txt directory /media/suryadi/TOSHIBA EXT/jetson-inference/build/CMakeCache.txt is different than the directory /home/suryadi/jetson-inference/build where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source "/media/suryadi/TOSHIBA EXT/jetson-inference/CMakeLists.txt" does not match the source "/home/suryadi/jetson-inference/CMakeLists.txt" used to generate cache.  Re-run cmake with a different source directory.

Please help. Thanks you very much in advance.

Best Regards,
Suryadi

Hi,

You can delete the build folder and recreate one to fix the error.
Thanks.

I am struggling with J0eBl4ck’s original issue. I am building a project out of tree, and unfortunately have no choice in the matter. I currently am just trying to get the imagenet-camera example to compile and run out-of-tree. I have copied it into a new folder and modified the CMakeLists.txt file as follows:

require CMake 2.8 or greater

cmake_minimum_required(VERSION 2.8)

declare RoadDetection project

project(imagenet-camera)

import jetson-inference and jetson-utils packages.

note that if you didn’t do “sudo make install”

while building jetson-inference, this will error.

find_package(jetson-utils)
find_package(jetson-inference)

CUDA and Qt4 are required

find_package(CUDA)
find_package(Qt4)

setup Qt4 for build

include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})

include header

include_directories(${PROJECT_SOURCE_DIR})
include_directories(/media/agribrink/Storage/develop/jetson-inference/build/aarch64/include)

file(GLOB imagenetCameraSources *.cpp)
file(GLOB imagenetCameraIncludes *.h )

cuda_add_executable(imagenet-camera ${imagenetCameraSources} ${imagenetCameraIncludes})

target_link_libraries(imagenet-camera jetson-inference)

Upon building I get errors such as “fatal error: gstCamera.h: No such file or directory
#include “gstCamera.h””. I have run sudo make install from the jetson-inference folder but the issue persists. If I were to manually copy the gstCamera.h file into this new folder it would solve that error but I would have to do the same for all included header files which turns out to be a long list. Any advice on getting this to build on its own is welcomed.

Hi gstewart9727, try adding these include directories to your CMakeLists.txt:

include_directories(/media/agribrink/Storage/develop/jetson-inference/build/aarch64/include/jetson-inference)
include_directories(/media/agribrink/Storage/develop/jetson-inference/build/aarch64/include/jetson-utils)
include_directories(/usr/include/gstreamer-1.0 /usr/lib/aarch64-linux-gnu/gstreamer-1.0/include /usr/include/glib-2.0 /usr/include/libxml2 /usr/lib/aarch64-linux-gnu/glib-2.0/include/)

Or you could skip manually including the jetson-inference/build/aarch64/include/* dirs in your CMakeLists if you changed the #include statements in imagenet-camera.cpp to be like:

#include <jetson-utils/gstCamera.h>
#include <jetson-utils/glDisplay.h>
#include <jetson-utils/cudaFont.h>

#include <jetson-inference/imageNet.h>
#include <jetson-utils/commandLine.h>

In this case, it would include the headers from /usr/local/include that were installed when you ran “sudo make install”.

2 Likes