Include OpenCV lib in deepstream-test3-app

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) Jetson Nano
• DeepStream Version 5.0
• JetPack Version (valid for Jetson only) 4.4-b144
• TensorRT Version 7.1.3
• Issue Type( questions, new requirements, bugs) question

Dear all,

I would like to exploit OpenCV API within a probe in the deepstream-test3-app.
I am following this example:

I have included the following statements in the deepstream-test3-app.c

#include "/usr/include/opencv4/opencv2/core.hpp"
#include "/usr/include/opencv4/opencv2/highgui/highgui.hpp"

This is the makefile that I use:

APP:= deepstream-test3-app

TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)

NVDS_VERSION:=5.0

LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/

ifeq ($(TARGET_DEVICE),aarch64)
  CFLAGS:= -DPLATFORM_TEGRA
endif

SRCS:= $(wildcard *.c)

INCS:= $(wildcard *.h)

PKGS:= gstreamer-1.0 opencv4

OBJS:= $(SRCS:.c=.o)

CFLAGS+= -I../../../includes

CFLAGS+= `pkg-config --cflags $(PKGS)`

LIBS:= `pkg-config --libs $(PKGS)`

LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lm \
       -Wl,-rpath,$(LIB_INSTALL_DIR)

all: $(APP)

%.o: %.c $(INCS) Makefile
	$(CC) -c -o $@ $(CFLAGS) $<

$(APP): $(OBJS) Makefile
	$(CC) -o $(APP) $(OBJS) $(LIBS)

clean:
	rm -rf $(OBJS) $(APP)

However when I compile the app I receive the following error:

cc -c -o deepstream_test3_app.o -DPLATFORM_TEGRA -I../../../includes `pkg-config --cflags gstreamer-1.0 opencv4` deepstream_test3_app.c
In file included from deepstream_test3_app.c:67:0:
/usr/include/opencv4/opencv2/core.hpp:49:4: error: #error core.hpp header must be compiled as C++
 #  error core.hpp header must be compiled as C++
    ^~~~~
In file included from /usr/include/opencv4/opencv2/core.hpp:52:0,
                 from deepstream_test3_app.c:67:
/usr/include/opencv4/opencv2/core/cvdef.h:690:4: error: #error "OpenCV 4.x+ requires enabled C++11 support"
 #  error "OpenCV 4.x+ requires enabled C++11 support"
    ^~~~~
/usr/include/opencv4/opencv2/core/cvdef.h:695:10: fatal error: array: No such file or directory
 #include <array>
          ^~~~~~~
compilation terminated.
Makefile:55: recipe for target 'deepstream_test3_app.o' failed
make: *** [deepstream_test3_app.o] Error 1

Would you be so kind to help me fixing this error?
Thank you very much in advance!!

This is a compiling issue, it has nothing to do with DeepStream.

*.hpp is C++ header file. It must be used with C++. The error message has told you the reason and solution. You need to switch to C++ if you want to use deepstream with opencv2.

There are C++ samples in deepstream SDK. E.G. /opt/nvidia/deepstream/deepstream-5.0/sources/sample_apps/deepstream-infer-tensor-meta-test

Please google for more C++ samples.

Ciao Fiona,

apologies for the late reply.
Yes indeed, I was looking to adjust the makefile to correctly link the opencv sources and use g++ compiler.

I have adjusted as follows the makefile. I put it here for future references:

APP:= deepstream-test3-app

TARGET_DEVICE = $(shell gcc -dumpmachine | cut -f1 -d -)

NVDS_VERSION:=5.0

CUDA_VER?=10.2
ifeq ($(CUDA_VER),)
  $(error "CUDA_VER is not set")
endif

LIB_INSTALL_DIR?=/opt/nvidia/deepstream/deepstream-$(NVDS_VERSION)/lib/

ifeq ($(TARGET_DEVICE),aarch64)
  CFLAGS:= -DPLATFORM_TEGRA
endif

SRCS:= $(wildcard *.c)

INCS:= $(wildcard *.h)

PKGS:= gstreamer-1.0 opencv4

OBJS:= $(SRCS:.c=.o)
CC := g++

CFLAGS+= -I /usr/local/cuda-$(CUDA_VER)/include \
         -I../../../includes

CFLAGS+= `pkg-config --cflags $(PKGS)`

LIBS:= `pkg-config --libs $(PKGS)`

LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_meta -lnvds_meta -lnvdsgst_helper -lnvbufsurface -lnvbufsurftransform -lm \
       -Wl,-rpath,$(LIB_INSTALL_DIR)

all: $(APP)

%.o: %.c $(INCS) Makefile
	$(CC) -c -o $@ $(CFLAGS) $<

$(APP): $(OBJS) Makefile
	$(CC) -o $(APP) $(OBJS) $(LIBS)

clean:
	rm -rf $(OBJS) $(APP)

Thanks once more!

1 Like