Couldn't Add OpenCV during "make" Command (Orin)

Hello;

I am having trouble to use OpenCV during “make” command. The code I try to run is gst-nvinfer-custome. The Makefile included this line for calling OpenCV “PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 /usr/lib/x86_64-linux-gnu/pkgconfig/opencv4.pc” code line. It gave me an error of opencv4.pc file not found.

I found a suggestion from mehematdeniz and modify the “Makerfile” but it looks like still not able to find OpenCV.

Here is the Makefile (I don’t have access to “CMakeLists.txt” file):

################################################################################
# Copyright (c) 2017-2022, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#################################################################################
#

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

OPENCV = 1
GPU = 1

CXX:= g++
SRCS:= gstnvinfer.cpp  gstnvinfer_allocator.cpp gstnvinfer_property_parser.cpp \
       gstnvinfer_meta_utils.cpp gstnvinfer_impl.cpp gstnvinfer_yaml_parser.cpp \
	   align_functions.cpp tensor_extractor.cpp
INCS:= $(wildcard *.h)
LIB:=libnvdsgst_infer.so

NVDS_VERSION:=6.1

CFLAGS+= -fPIC -std=c++11 -DDS_VERSION=\"6.1.0\" \
	 -I /usr/local/cuda-$(CUDA_VER)/include \
	 -I /opt/nvidia/deepstream/deepstream-6.1/sources/includes \
	 -I /opt/nvidia/deepstream/deepstream-6.1/sources/gst-plugins/gst-nvdspreprocess/include \
	 -I /opt/nvidia/deepstream/deepstream-6.1/sources/libs/nvdsinfer -DNDEBUG

-D_GLIBCXX_USE_CXX11_ABI=0
CFLAGS+=-I /usr/include/opencv4 
		

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

LIBS := -shared -Wl,-no-undefined \
	-L/usr/local/cuda-$(CUDA_VER)/lib64/ -lcudart

LIBS+= -L$(LIB_INSTALL_DIR) -lnvdsgst_helper -lnvdsgst_meta -lnvds_meta \
       -lnvds_infer -lnvbufsurface -lnvbufsurftransform -ldl -lpthread -lyaml-cpp \
       -lcuda -Wl,-rpath,$(LIB_INSTALL_DIR)
	   

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

# PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 /usr/lib/x86_64-linux-gnu/pkgconfig/opencv4.pc
PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 
CFLAGS+=$(shell pkg-config --cflags $(PKGS))
LIBS+=$(shell pkg-config --libs $(PKGS))

# Error in OpenCV in Nivida AGX Orin
# ref: https://forums.developer.nvidia.com/t/opencv-no-package-opencv-found/169616/2?u=cloudlakecho
ifeq ($(OPENCV), 1) 
  COMMON+= -DOPENCV
  CFLAGS+= -DOPENCV
  LDFLAGS+= `pkg-config --libs opencv4` -lstdc++
  COMMON+= `pkg-config --cflags opencv4` 
endif

ifeq ($(GPU), 1) 
  COMMON+= -DGPU -I/usr/local/cuda/include/ -I/usr/local/cuda/targets/aarch64-linux/include/
  CFLAGS+= -DGPU
  LDFLAGS+= -L/usr/lib/aarch64-linux-gnu -lcuda -lcudart -lcublas -lcurand
endif
#

all: $(LIB)

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

$(LIB): $(OBJS) $(DEP) Makefile
	$(CXX) -o $@ $(OBJS) $(LIBS)

install: $(LIB)
	cp -rv $(LIB) $(GST_INSTALL_DIR)

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

This is at the end of error log (log is too long, so I don’t want to show in here, but entire log - to read please use Chrome browser):

/usr/bin/ld: align_functions.cpp:(.text._ZN2cv4Mat_IhEaSEONS_3MatE[_ZN2cv4Mat_IhEaSEONS_3MatE]+0xcc): undefined reference to `cv::Mat::operator=(cv::Mat&&)'
/usr/bin/ld: align_functions.cpp:(.text._ZN2cv4Mat_IhEaSEONS_3MatE[_ZN2cv4Mat_IhEaSEONS_3MatE]+0xd4): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: align_functions.cpp:(.text._ZN2cv4Mat_IhEaSEONS_3MatE[_ZN2cv4Mat_IhEaSEONS_3MatE]+0x110): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/usr/bin/ld: align_functions.cpp:(.text._ZN2cv4Mat_IhEaSEONS_3MatE[_ZN2cv4Mat_IhEaSEONS_3MatE]+0x14c): undefined reference to `cv::Mat::~Mat()'
/usr/bin/ld: align_functions.o: in function `cv::Mat_<unsigned char>::release()':
align_functions.cpp:(.text._ZN2cv4Mat_IhE7releaseEv[_ZN2cv4Mat_IhE7releaseEv]+0x10): undefined reference to `cv::Mat::release()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:81: libnvdsgst_infer.so] Error 1

Any suggestion appreciated.

Thank You.

My runtime environment:
   Hardware: Nvidia Orin
   OS: Ubuntu 20.04 on AArch 64 processor (not x86_64 or Amd)

Hi there @cloudlakecho,

I think your post might get better visibility in the Orin category (where I moved it now).
But since it is about proper setup of Makefiles for DeepStream, you might also want to check in the category where you found the suggestion you reference above, which is the DeepStream SDK forums.

Thanks!

1 Like

@MarkusHoHo Thanks for suggestion and moved my question to Orin category. I will wait for any tip.

At the same time, I don’t think my problem depending on specific hardware Orin but more to architecture, AArch 64.

Regarding the DeepStream SDK forum, I already looked around the similar problem. The existing solution seems promising but it still not work for my case. I will search again.

Hi,
Please check if this helps:
How to create opencv gpumat from nvstream? - #18 by DaneLLL

@DaneLLL Thanks for suggestion.
I will add your method and try again (your PKGS and CFLAGS sections are already in mine):

LIBS+=-L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_videoio -lopencv_cudafilters

I have one question in your method. Your original post had “# Remove opencv in PKGS”. Do you mean I have to omit all OpenCV related package in PKGS in my “Makefile”?

Hi,

This is not required now. In old releases, the release is with OpenCV 3.3.1 and in Makefile, it is

PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 opencv

Now the release is with OpenCV 4.1.1 and it is revised to:

PKGS:= gstreamer-1.0 gstreamer-base-1.0 gstreamer-video-1.0 opencv4

@DaneLLL Thanks for the details. I will try again “make” command with other modficiation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.