gstreamer NVMM <-> opencv gpuMat

Hi Honey_Patouceul,

There could be an issue in Makefile,

/usr/local/cuda/bin/nvcc -ccbin g++ -I./  --shared  -Xcompiler -fPIC  -I/usr     /include  -gencode arch=compute_62,code=compute_62      -o gst-custom-opencv_cudaprocess.o -c gst-custom-opencv_cudaprocess.cu
ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat$ make
/usr/local/cuda/bin/nvcc -ccbin g++ -I./  --shared  -Xcompiler -fPIC  -I/usr     /include  -gencode arch=compute_62,code=compute_62      -o gst-custom-opencv_cudaprocess.o -c gst-custom-opencv_cudaprocess.cu
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
Makefile:140: recipe for target 'gst-custom-opencv_cudaprocess.o' failed
make: *** [gst-custom-opencv_cudaprocess.o] Error 1

I edited the command line given by Makefile - to say -I/usr/include, then command line seems to work

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat$ /usr/local/cuda/bin/nvcc -ccbin g++ -I./  --shared  -Xcompiler -fPIC  -I/usr/include  -gencode arch=compute_62,code=compute_62      -o gst-custom-opencv_cudaprocess.o -c gst-custom-opencv_cudaprocess.cu

However I get error …which I guess, is related to old opencv version

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat$ /usr/local/cuda/bin/nvcc -ccbin g++ -I./  --shared  -Xcompiler -fPIC  -I/usr/include  -gencode arch=compute_62,code=compute_62      -o gst-custom-opencv_cudaprocess.o -c gst-custom-opencv_cudaprocess.cu
/usr/include/opencv2/gpu/gpu.hpp(438): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(444): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1271): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1272): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1273): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1291): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1293): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1294): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1295): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1297): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1301): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1306): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1307): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1307): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1309): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1311): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1841): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1842): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1844): error: vector is not a template

/usr/include/opencv2/gpu/gpu.hpp(1845): error: vector is not a template

Hi dumbogeorge,

Thanks for mentioning this issue. I have edited my post so that my comment is now on its own line on do not interfere. Sorry for the confusion.

I have only tested on R28.1 with opencv4tegra for now.

Here is Sobel filtering sample tested on R28.1 with opencv-3.3.0
[EDIT: You may read Late EDIT in post #19 about this weird Sobel filter…it works only with EGL stream (but I don’t know why !).]
:

gst-custom-opencv_cudaprocess.cu:

/*
 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  * Neither the name of NVIDIA CORPORATION nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <stdlib.h>

#include <cuda.h>

#include "opencv2/core.hpp"
#include "opencv2/cudafilters.hpp" 

#include "cudaEGL.h"

#if defined(__cplusplus)
extern "C" void Handle_EGLImage (EGLImageKHR image);
extern "C" {
#endif

typedef enum {
  COLOR_FORMAT_Y8 = 0,
  COLOR_FORMAT_U8_V8,
  COLOR_FORMAT_RGBA,
  COLOR_FORMAT_NONE
} ColorFormat;

typedef struct {
  /**
  * cuda-process API
  *
  * @param image   : EGL Image to process
  * @param userPtr : point to user alloc data, should be free by user
  */
  void (*fGPUProcess) (EGLImageKHR image, void ** userPtr);

  /**
  * pre-process API
  *
  * @param sBaseAddr  : Mapped Surfaces(YUV) pointers
  * @param smemsize   : surfaces size array
  * @param swidth     : surfaces width array
  * @param sheight    : surfaces height array
  * @param spitch     : surfaces pitch array
  * @param sformat    : surfaces format array
  * @param nsurfcount : surfaces count
  * @param userPtr    : point to user alloc data, should be free by user
  */
  void (*fPreProcess)(void **sBaseAddr,
                      unsigned int *smemsize,
                      unsigned int *swidth,
                      unsigned int *sheight,
                      unsigned int *spitch,
                      ColorFormat *sformat,
                      unsigned int nsurfcount,
                      void ** userPtr);

  /**
  * post-process API
  *
  * @param sBaseAddr  : Mapped Surfaces(YUV) pointers
  * @param smemsize   : surfaces size array
  * @param swidth     : surfaces width array
  * @param sheight    : surfaces height array
  * @param spitch     : surfaces pitch array
  * @param sformat    : surfaces format array
  * @param nsurfcount : surfaces count
  * @param userPtr    : point to user alloc data, should be free by user
  */
  void (*fPostProcess)(void **sBaseAddr,
                      unsigned int *smemsize,
                      unsigned int *swidth,
                      unsigned int *sheight,
                      unsigned int *spitch,
                      ColorFormat *sformat,
                      unsigned int nsurfcount,
                      void ** userPtr);
} CustomerFunction;

void init (CustomerFunction * pFuncs);

#if defined(__cplusplus)
}
#endif

/**
  * Dummy custom pre-process API implematation.
  * It just access mapped surface userspace pointer &
  * memset with specific pattern modifying pixel-data in-place.
  *
  * @param sBaseAddr  : Mapped Surfaces pointers
  * @param smemsize   : surfaces size array
  * @param swidth     : surfaces width array
  * @param sheight    : surfaces height array
  * @param spitch     : surfaces pitch array
  * @param nsurfcount : surfaces count
  */
static void
pre_process (void **sBaseAddr,
                unsigned int *smemsize,
                unsigned int *swidth,
                unsigned int *sheight,
                unsigned int *spitch,
                ColorFormat  *sformat,
                unsigned int nsurfcount,
                void ** usrptr)
{
  /* add your custom pre-process here
     we draw a green block for demo */
}

/**
  * Dummy custom post-process API implematation.
  * It just access mapped surface userspace pointer &
  * memset with specific pattern modifying pixel-data in-place.
  *
  * @param sBaseAddr  : Mapped Surfaces pointers
  * @param smemsize   : surfaces size array
  * @param swidth     : surfaces width array
  * @param sheight    : surfaces height array
  * @param spitch     : surfaces pitch array
  * @param nsurfcount : surfaces count
  */
static void
post_process (void **sBaseAddr,
                unsigned int *smemsize,
                unsigned int *swidth,
                unsigned int *sheight,
                unsigned int *spitch,
                ColorFormat  *sformat,
                unsigned int nsurfcount,
                void ** usrptr)
{
  /* add your custom post-process here
     we draw a green block for demo */
}

/* This filter will be created by init() function below */
cv::Ptr< cv::cuda::Filter > filter;

static void cv_process(void *pdata, int32_t width, int32_t height)
{
    /* Create a GpuMat with data pointer */
    cv::cuda::GpuMat d_mat(height, width, CV_8UC4, pdata);
    
    /* Apply Sobel filter */
    filter->apply (d_mat, d_mat);
}

/**
  * Performs CUDA Operations on egl image.
  *
  * @param image : EGL image
  */
static void
gpu_process (EGLImageKHR image, void ** usrptr)
{
  CUresult status;
  CUeglFrame eglFrame;
  CUgraphicsResource pResource = NULL;

  cudaFree(0);
  status = cuGraphicsEGLRegisterImage(&pResource, image, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
  if (status != CUDA_SUCCESS) {
    printf("cuGraphicsEGLRegisterImage failed : %d \n", status);
    return;
  }

  status = cuGraphicsResourceGetMappedEglFrame( &eglFrame, pResource, 0, 0);
  if (status != CUDA_SUCCESS) {
    printf ("cuGraphicsSubResourceGetMappedArray failed\n");
  }

  status = cuCtxSynchronize();
  if (status != CUDA_SUCCESS) {
    printf ("cuCtxSynchronize failed \n");
  }

  if (eglFrame.frameType == CU_EGL_FRAME_TYPE_PITCH) {
    if (eglFrame.eglColorFormat == CU_EGL_COLOR_FORMAT_RGBA) {
	/* Perform now your custom opencv processing */
	cv_process(eglFrame.frame.pPitch[0], eglFrame.width, eglFrame.height);
    } else {
	printf ("Invalid eglcolorformat for opencv\n");
    }
  }

  status = cuCtxSynchronize();
  if (status != CUDA_SUCCESS) {
    printf ("cuCtxSynchronize failed after memcpy \n");
  }

  status = cuGraphicsUnregisterResource(pResource);
  if (status != CUDA_SUCCESS) {
    printf("cuGraphicsEGLUnRegisterResource failed: %d \n", status);
  }
}

extern "C" void
init (CustomerFunction * pFuncs)
{
  pFuncs->fPreProcess = pre_process;
  pFuncs->fGPUProcess = gpu_process;
  pFuncs->fPostProcess = post_process;

  filter = cv::cuda::createSobelFilter(CV_8UC4, CV_8UC4, 1, 1, 1, 1, cv::BORDER_DEFAULT);
}

Here is the makefile (my opencv-3.3.0 is installed in /usr/local/opencv-3.3.0, you may adjust for your case):

###############################################################################
#
# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#  * Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#  * Neither the name of NVIDIA CORPORATION nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
###############################################################################

# Location of the CUDA Toolkit
CUDA_PATH ?= /usr/local/cuda
INCLUDE_DIR = /usr/include
LIB_DIR = /usr/lib/aarch64-linux-gnu
TEGRA_LIB_DIR = /usr/lib/aarch64-linux-gnu/tegra
OPENCV_DIR = /usr/local/opencv-3.3.0

# For hardfp
#LIB_DIR = /usr/lib/arm-linux-gnueabihf
#TEGRA_LIB_DIR = /usr/lib/arm-linux-gnueabihf/tegra

OSUPPER = $(shell uname -s 2>/dev/null | tr "[:lower:]" "[:upper:]")
OSLOWER = $(shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]")

OS_SIZE = $(shell uname -m | sed -e "s/i.86/32/" -e "s/x86_64/64/" -e "s/armv7l/32/")
OS_ARCH = $(shell uname -m | sed -e "s/i386/i686/")

GCC ?= g++
NVCC := $(CUDA_PATH)/bin/nvcc -ccbin $(GCC)

# internal flags
NVCCFLAGS   := --shared
CCFLAGS     := -fPIC
CVCCFLAGS:=-I$(OPENCV_DIR)/include
CVLDFLAGS:=-L$(OPENCV_DIR)/lib -lopencv_core -lopencv_cudafilters

LDFLAGS     :=

# Extra user flags
EXTRA_NVCCFLAGS   ?=
EXTRA_LDFLAGS     ?=
EXTRA_CCFLAGS     ?=

override abi := aarch64
LDFLAGS += --dynamic-linker=/lib/ld-linux-aarch64.so.1

# For hardfp
#override abi := gnueabihf
#LDFLAGS += --dynamic-linker=/lib/ld-linux-armhf.so.3
#CCFLAGS += -mfloat-abi=hard

ifeq ($(ARMv7),1)
NVCCFLAGS += -target-cpu-arch ARM
ifneq ($(TARGET_FS),)
CCFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += -rpath-link=$(TARGET_FS)/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib
LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/$(abi)-linux-gnu

# For hardfp
#LDFLAGS += -rpath-link=$(TARGET_FS)/usr/lib/arm-linux-$(abi)

endif
endif

# Debug build flags
dbg = 0
ifeq ($(dbg),1)
      NVCCFLAGS += -g -G
      TARGET := debug
else
      TARGET := release
endif

ALL_CCFLAGS :=
ALL_CCFLAGS += $(NVCCFLAGS)
ALL_CCFLAGS += $(EXTRA_NVCCFLAGS)
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(CCFLAGS))
ALL_CCFLAGS += $(addprefix -Xcompiler ,$(EXTRA_CCFLAGS))

ALL_LDFLAGS :=
ALL_LDFLAGS += $(ALL_CCFLAGS)
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))
ALL_LDFLAGS += $(addprefix -Xlinker ,$(EXTRA_LDFLAGS))

# Common includes and paths for CUDA
INCLUDES  := -I./
LIBRARIES := -L$(LIB_DIR) -lEGL -lGLESv2
LIBRARIES += -L$(TEGRA_LIB_DIR) -lcuda -lrt

################################################################################

# CUDA code generation flags
ifneq ($(OS_ARCH),armv7l)
GENCODE_SM10    := -gencode arch=compute_10,code=sm_10
endif
GENCODE_SM20    := -gencode arch=compute_20,code=sm_20
GENCODE_SM30    := -gencode arch=compute_30,code=sm_30
GENCODE_SM32    := -gencode arch=compute_32,code=sm_32
GENCODE_SM35    := -gencode arch=compute_35,code=sm_35
GENCODE_SM50    := -gencode arch=compute_50,code=sm_50
GENCODE_SMXX    := -gencode arch=compute_50,code=compute_50
GENCODE_SM53    := -gencode arch=compute_53,code=compute_53  # for TX1
GENCODE_SM62    := -gencode arch=compute_62,code=compute_62  # for TX2

ifeq ($(OS_ARCH),armv7l)
GENCODE_FLAGS   ?= $(GENCODE_SM32)
else
# This only support TX1(5.3) or TX2(6.2) -like architectures
GENCODE_FLAGS   ?= $(GEGENCODE_SM53) $(GENCODE_SM62)   
endif

# Target rules
all: build

build: lib-gst-custom-opencv_cudaprocess.so

gst-custom-opencv_cudaprocess.o : gst-custom-opencv_cudaprocess.cu
	$(NVCC) $(INCLUDES) $(ALL_CCFLAGS) $(CVCCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<

lib-gst-custom-opencv_cudaprocess.so : gst-custom-opencv_cudaprocess.o
	$(NVCC) $(ALL_LDFLAGS) $(CVLDFLAGS) $(GENCODE_FLAGS) -o $@ $^ $(LIBRARIES)

clean:
	rm lib-gst-custom-opencv_cudaprocess.so gst-custom-opencv_cudaprocess.o

clobber: clean

Hi Honey_Patouceul,

Thanks for the code with new OCV3.3.0. When I try it I see that it goes into debugger…

Compilation -

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ make
/usr/local/cuda/bin/nvcc -ccbin g++ -I./  --shared  -Xcompiler -fPIC  -I/usr/include/opencv/include  -gencode arch=compute_62,code=compute_62      -o gst-custom-opencv_cudaprocess.o -c gst-custom-opencv_cudaprocess.cu
/usr/local/cuda/bin/nvcc -ccbin g++   --shared  -Xcompiler -fPIC  -Xlinker --dynamic-linker=/lib/ld-linux-aarch64.so.1  -L/usr/include/opencv/lib -lopencv_core -lopencv_cudafilters  -gencode arch=compute_62,code=compute_62      -o lib-gst-custom-opencv_cudaprocess.so gst-custom-opencv_cudaprocess.o -L/usr/lib/aarch64-linux-gnu -lEGL -lGLESv2 -L/usr/lib/aarch64-linux-gnu/tegra -lcuda -lrt

Run -

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ gst-launch-1.0 nvcamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, format=I420, framerate=120/1' ! nvivafilter customer-lib-name=./lib-gst-custom-opencv_cudaprocess.so cuda-process=true ! 'video/x-raw(memory:NVMM), format=RGBA' ! nvegltransform ! nveglglessink
Setting pipeline to PAUSED ...
Caught SIGSEGV
#0  0x0000007f9bceea38 in __waitpid (pid=7545, stat_loc=0x7fe24c94b4, 
#1  0x0000007f9bd296b8 in g_on_error_stack_trace ()
#2  0x0000000000405bec in ?? ()
#3  0x0000007f8b646000 in ?? () from /usr/lib/libopencv_core.so.2.4
#4  0x0000007f02010000 in ?? ()
Spinning.  Please run 'gdb gst-launch-1.0 7541' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.

What is the install path of opencv3 ?

-I/usr/include/opencv/include

seems a bit strange to me…

What is your LD_LIBRARY_PATH environment variable ?

echo $LD_LIBRARY_PATH
#3  0x0000007f8b646000 in ?? () from /usr/lib/libopencv_core.so.2.4

If you’ve not set it to find opencv3 before opencv2 (opencv4tegra is intalled in default path /usr, so it will be found if you’ve not set it accordingly), then it is likely to produce such issue.

I have to say that in my case, opencv4tegra has moved to /usr/local with other opencv versions, but I don’t think that’s much difference (I just have to set it it explicitely).

Yes, very certainly that is the issue. Could it work with 3.2.0 ? That is what I am using .

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ lt /usr/local/lib/libopencv_core*
-rw-r--r-- 1 root root 4635256 Jul 26 13:35 /usr/local/lib/libopencv_core.so.3.2.0
lrwxrwxrwx 1 root root      23 Jul 26 13:59 /usr/local/lib/libopencv_core.so.3.2 -> libopencv_core.so.3.2.0
lrwxrwxrwx 1 root root      21 Jul 26 13:59 /usr/local/lib/libopencv_core.so -> libopencv_core.so.3.2

My path is -

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ echo $LD_LIBRARY_PATH
/usr/local/lib

Still - it seems to pick up 2.4 ???

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ gst-launch-1.0 nvcamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, format=I420, framerate=120/1' ! nvivafilter customer-lib-name=./lib-gst-custom-opencv_cudaprocess.so cuda-process=true ! 'video/x-raw(memory:NVMM), format=RGBA' ! nvegltransform ! nveglglessink
Setting pipeline to PAUSED ...
Caught SIGSEGV
#0  0x0000007fa3fa9a38 in __waitpid (pid=8151, stat_loc=0x7ff90b91a4, 
#1  0x0000007fa3fe46b8 in g_on_error_stack_trace ()
#2  0x0000000000405bec in ?? ()
#3  0x0000007f93646000 in ?? () from /usr/lib/libopencv_core.so.2.4
#4  0x0000007f02010000 in ?? ()
Spinning.  Please run 'gdb gst-launch-1.0 8147' to continue debugging, Ctrl-C to quit, or Ctrl-\ to dump core.
^C

Yes, still looks the same issue… For reference, your LD_LIBRARY_PATH should also have cuda:

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/lib

Have you updated the makefile with the one from post #23, updating OPENCV_DIR to /usr/local and then make clean and make again ? (I have separate directories for 2.4 and 3.3 versions).

Just to be sure, what gives

ls -al /usr/local/lib/libopencv*

/usr/local/lib/libopencv* seems like right place for opencv

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ ls -al /usr/local/lib/libopencv*
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_aruco.so -> libopencv_aruco.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_aruco.so.3.2 -> libopencv_aruco.so.3.2.0
-rw-r--r-- 1 root root   306040 Jul 26 13:53 /usr/local/lib/libopencv_aruco.so.3.2.0
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_bgsegm.so -> libopencv_bgsegm.so.3.2
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_bgsegm.so.3.2 -> libopencv_bgsegm.so.3.2.0
-rw-r--r-- 1 root root    73016 Jul 26 13:45 /usr/local/lib/libopencv_bgsegm.so.3.2.0
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_bioinspired.so -> libopencv_bioinspired.so.3.2
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_bioinspired.so.3.2 -> libopencv_bioinspired.so.3.2.0
-rw-r--r-- 1 root root   253592 Jul 26 13:45 /usr/local/lib/libopencv_bioinspired.so.3.2.0
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_calib3d.so -> libopencv_calib3d.so.3.2
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_calib3d.so.3.2 -> libopencv_calib3d.so.3.2.0
-rw-r--r-- 1 root root  1290920 Jul 26 13:47 /usr/local/lib/libopencv_calib3d.so.3.2.0
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_ccalib.so -> libopencv_ccalib.so.3.2
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_ccalib.so.3.2 -> libopencv_ccalib.so.3.2.0
-rw-r--r-- 1 root root   376264 Jul 26 13:48 /usr/local/lib/libopencv_ccalib.so.3.2.0
lrwxrwxrwx 1 root root       21 Jul 26 13:59 /usr/local/lib/libopencv_core.so -> libopencv_core.so.3.2
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_core.so.3.2 -> libopencv_core.so.3.2.0
-rw-r--r-- 1 root root  4635256 Jul 26 13:35 /usr/local/lib/libopencv_core.so.3.2.0
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_cudaarithm.so -> libopencv_cudaarithm.so.3.2
lrwxrwxrwx 1 root root       29 Jul 26 13:59 /usr/local/lib/libopencv_cudaarithm.so.3.2 -> libopencv_cudaarithm.so.3.2.0
-rw-r--r-- 1 root root 26448520 Jul 26 13:36 /usr/local/lib/libopencv_cudaarithm.so.3.2.0
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_cudabgsegm.so -> libopencv_cudabgsegm.so.3.2
lrwxrwxrwx 1 root root       29 Jul 26 13:59 /usr/local/lib/libopencv_cudabgsegm.so.3.2 -> libopencv_cudabgsegm.so.3.2.0
-rw-r--r-- 1 root root   288960 Jul 26 13:39 /usr/local/lib/libopencv_cudabgsegm.so.3.2.0
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_cudacodec.so -> libopencv_cudacodec.so.3.2
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_cudacodec.so.3.2 -> libopencv_cudacodec.so.3.2.0
-rw-r--r-- 1 root root    49360 Jul 26 13:43 /usr/local/lib/libopencv_cudacodec.so.3.2.0
lrwxrwxrwx 1 root root       31 Jul 26 13:59 /usr/local/lib/libopencv_cudafeatures2d.so -> libopencv_cudafeatures2d.so.3.2
lrwxrwxrwx 1 root root       33 Jul 26 13:59 /usr/local/lib/libopencv_cudafeatures2d.so.3.2 -> libopencv_cudafeatures2d.so.3.2.0
-rw-r--r-- 1 root root  4557944 Jul 26 13:48 /usr/local/lib/libopencv_cudafeatures2d.so.3.2.0
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_cudafilters.so -> libopencv_cudafilters.so.3.2
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_cudafilters.so.3.2 -> libopencv_cudafilters.so.3.2.0
-rw-r--r-- 1 root root 66438608 Jul 26 13:40 /usr/local/lib/libopencv_cudafilters.so.3.2.0
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_cudaimgproc.so -> libopencv_cudaimgproc.so.3.2
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_cudaimgproc.so.3.2 -> libopencv_cudaimgproc.so.3.2.0
-rw-r--r-- 1 root root  5599616 Jul 26 13:40 /usr/local/lib/libopencv_cudaimgproc.so.3.2.0
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_cudalegacy.so -> libopencv_cudalegacy.so.3.2
lrwxrwxrwx 1 root root       29 Jul 26 13:59 /usr/local/lib/libopencv_cudalegacy.so.3.2 -> libopencv_cudalegacy.so.3.2.0
-rw-r--r-- 1 root root  1672808 Jul 26 13:48 /usr/local/lib/libopencv_cudalegacy.so.3.2.0
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_cudaobjdetect.so -> libopencv_cudaobjdetect.so.3.2
lrwxrwxrwx 1 root root       32 Jul 26 13:59 /usr/local/lib/libopencv_cudaobjdetect.so.3.2 -> libopencv_cudaobjdetect.so.3.2.0
-rw-r--r-- 1 root root   314904 Jul 26 13:49 /usr/local/lib/libopencv_cudaobjdetect.so.3.2.0
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_cudaoptflow.so -> libopencv_cudaoptflow.so.3.2
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_cudaoptflow.so.3.2 -> libopencv_cudaoptflow.so.3.2.0
-rw-r--r-- 1 root root  4724312 Jul 26 13:49 /usr/local/lib/libopencv_cudaoptflow.so.3.2.0
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_cudastereo.so -> libopencv_cudastereo.so.3.2
lrwxrwxrwx 1 root root       29 Jul 26 13:59 /usr/local/lib/libopencv_cudastereo.so.3.2 -> libopencv_cudastereo.so.3.2.0
-rw-r--r-- 1 root root  1754704 Jul 26 13:50 /usr/local/lib/libopencv_cudastereo.so.3.2.0
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_cudawarping.so -> libopencv_cudawarping.so.3.2
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_cudawarping.so.3.2 -> libopencv_cudawarping.so.3.2.0
-rw-r--r-- 1 root root  8731336 Jul 26 13:40 /usr/local/lib/libopencv_cudawarping.so.3.2.0
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_cudev.so -> libopencv_cudev.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_cudev.so.3.2 -> libopencv_cudev.so.3.2.0
-rw-r--r-- 1 root root     8392 Jul 26 11:41 /usr/local/lib/libopencv_cudev.so.3.2.0
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_datasets.so -> libopencv_datasets.so.3.2
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_datasets.so.3.2 -> libopencv_datasets.so.3.2.0
-rw-r--r-- 1 root root   641024 Jul 26 13:50 /usr/local/lib/libopencv_datasets.so.3.2.0
lrwxrwxrwx 1 root root       20 Jul 26 13:59 /usr/local/lib/libopencv_dpm.so -> libopencv_dpm.so.3.2
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_dpm.so.3.2 -> libopencv_dpm.so.3.2.0
-rw-r--r-- 1 root root   138016 Jul 26 13:45 /usr/local/lib/libopencv_dpm.so.3.2.0
lrwxrwxrwx 1 root root       21 Jul 26 13:59 /usr/local/lib/libopencv_face.so -> libopencv_face.so.3.2
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_face.so.3.2 -> libopencv_face.so.3.2.0
-rw-r--r-- 1 root root   171208 Jul 26 13:45 /usr/local/lib/libopencv_face.so.3.2.0
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_features2d.so -> libopencv_features2d.so.3.2
lrwxrwxrwx 1 root root       29 Jul 26 13:59 /usr/local/lib/libopencv_features2d.so.3.2 -> libopencv_features2d.so.3.2.0
-rw-r--r-- 1 root root   727904 Jul 26 13:46 /usr/local/lib/libopencv_features2d.so.3.2.0
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_flann.so -> libopencv_flann.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_flann.so.3.2 -> libopencv_flann.so.3.2.0
-rw-r--r-- 1 root root   458416 Jul 26 13:37 /usr/local/lib/libopencv_flann.so.3.2.0
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_freetype.so -> libopencv_freetype.so.3.2
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_freetype.so.3.2 -> libopencv_freetype.so.3.2.0
-rw-r--r-- 1 root root    37184 Jul 26 13:41 /usr/local/lib/libopencv_freetype.so.3.2.0
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_fuzzy.so -> libopencv_fuzzy.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_fuzzy.so.3.2 -> libopencv_fuzzy.so.3.2.0
-rw-r--r-- 1 root root    55832 Jul 26 13:41 /usr/local/lib/libopencv_fuzzy.so.3.2.0
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_highgui.so -> libopencv_highgui.so.3.2
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_highgui.so.3.2 -> libopencv_highgui.so.3.2.0
-rw-r--r-- 1 root root    71944 Jul 26 13:36 /usr/local/lib/libopencv_highgui.so.3.2.0
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_imgcodecs.so -> libopencv_imgcodecs.so.3.2
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_imgcodecs.so.3.2 -> libopencv_imgcodecs.so.3.2.0
-rw-r--r-- 1 root root  1729688 Jul 26 13:35 /usr/local/lib/libopencv_imgcodecs.so.3.2.0
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_imgproc.so -> libopencv_imgproc.so.3.2
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_imgproc.so.3.2 -> libopencv_imgproc.so.3.2.0
-rw-r--r-- 1 root root  3473544 Jul 26 13:35 /usr/local/lib/libopencv_imgproc.so.3.2.0
lrwxrwxrwx 1 root root       32 Jul 26 13:59 /usr/local/lib/libopencv_line_descriptor.so -> libopencv_line_descriptor.so.3.2
lrwxrwxrwx 1 root root       34 Jul 26 13:59 /usr/local/lib/libopencv_line_descriptor.so.3.2 -> libopencv_line_descriptor.so.3.2.0
-rw-r--r-- 1 root root   208416 Jul 26 13:46 /usr/local/lib/libopencv_line_descriptor.so.3.2.0
lrwxrwxrwx 1 root root       19 Jul 26 13:59 /usr/local/lib/libopencv_ml.so -> libopencv_ml.so.3.2
lrwxrwxrwx 1 root root       21 Jul 26 13:59 /usr/local/lib/libopencv_ml.so.3.2 -> libopencv_ml.so.3.2.0
-rw-r--r-- 1 root root   751992 Jul 26 13:38 /usr/local/lib/libopencv_ml.so.3.2.0
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_objdetect.so -> libopencv_objdetect.so.3.2
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_objdetect.so.3.2 -> libopencv_objdetect.so.3.2.0
-rw-r--r-- 1 root root   418016 Jul 26 13:44 /usr/local/lib/libopencv_objdetect.so.3.2.0
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_optflow.so -> libopencv_optflow.so.3.2
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_optflow.so.3.2 -> libopencv_optflow.so.3.2.0
-rw-r--r-- 1 root root   363696 Jul 26 13:53 /usr/local/lib/libopencv_optflow.so.3.2.0
lrwxrwxrwx 1 root root       33 Jul 26 13:59 /usr/local/lib/libopencv_phase_unwrapping.so -> libopencv_phase_unwrapping.so.3.2
lrwxrwxrwx 1 root root       35 Jul 26 13:59 /usr/local/lib/libopencv_phase_unwrapping.so.3.2 -> libopencv_phase_unwrapping.so.3.2.0
-rw-r--r-- 1 root root    50616 Jul 26 13:54 /usr/local/lib/libopencv_phase_unwrapping.so.3.2.0
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_photo.so -> libopencv_photo.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_photo.so.3.2 -> libopencv_photo.so.3.2.0
-rw-r--r-- 1 root root  1154680 Jul 26 13:42 /usr/local/lib/libopencv_photo.so.3.2.0
lrwxrwxrwx 1 root root       21 Jul 26 13:59 /usr/local/lib/libopencv_plot.so -> libopencv_plot.so.3.2
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_plot.so.3.2 -> libopencv_plot.so.3.2.0
-rw-r--r-- 1 root root    44768 Jul 26 13:44 /usr/local/lib/libopencv_plot.so.3.2.0
lrwxrwxrwx 1 root root       20 Jul 26 13:59 /usr/local/lib/libopencv_reg.so -> libopencv_reg.so.3.2
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_reg.so.3.2 -> libopencv_reg.so.3.2.0
-rw-r--r-- 1 root root   135520 Jul 26 13:38 /usr/local/lib/libopencv_reg.so.3.2.0
lrwxrwxrwx 1 root root       21 Jul 26 13:59 /usr/local/lib/libopencv_rgbd.so -> libopencv_rgbd.so.3.2
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_rgbd.so.3.2 -> libopencv_rgbd.so.3.2.0
-rw-r--r-- 1 root root   551720 Jul 26 13:50 /usr/local/lib/libopencv_rgbd.so.3.2.0
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_saliency.so -> libopencv_saliency.so.3.2
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_saliency.so.3.2 -> libopencv_saliency.so.3.2.0
-rw-r--r-- 1 root root   205568 Jul 26 13:47 /usr/local/lib/libopencv_saliency.so.3.2.0
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_shape.so -> libopencv_shape.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_shape.so.3.2 -> libopencv_shape.so.3.2.0
-rw-r--r-- 1 root root   247448 Jul 26 13:42 /usr/local/lib/libopencv_shape.so.3.2.0
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_stereo.so -> libopencv_stereo.so.3.2
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_stereo.so.3.2 -> libopencv_stereo.so.3.2.0
-rw-r--r-- 1 root root   170448 Jul 26 13:51 /usr/local/lib/libopencv_stereo.so.3.2.0
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_stitching.so -> libopencv_stitching.so.3.2
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_stitching.so.3.2 -> libopencv_stitching.so.3.2.0
-rw-r--r-- 1 root root   710984 Jul 26 13:54 /usr/local/lib/libopencv_stitching.so.3.2.0
lrwxrwxrwx 1 root root       33 Jul 26 13:59 /usr/local/lib/libopencv_structured_light.so -> libopencv_structured_light.so.3.2
lrwxrwxrwx 1 root root       35 Jul 26 13:59 /usr/local/lib/libopencv_structured_light.so.3.2 -> libopencv_structured_light.so.3.2.0
-rw-r--r-- 1 root root   113808 Jul 26 13:55 /usr/local/lib/libopencv_structured_light.so.3.2.0
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_superres.so -> libopencv_superres.so.3.2
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_superres.so.3.2 -> libopencv_superres.so.3.2.0
-rw-r--r-- 1 root root   374776 Jul 26 13:51 /usr/local/lib/libopencv_superres.so.3.2.0
lrwxrwxrwx 1 root root       33 Jul 26 13:59 /usr/local/lib/libopencv_surface_matching.so -> libopencv_surface_matching.so.3.2
lrwxrwxrwx 1 root root       35 Jul 26 13:59 /usr/local/lib/libopencv_surface_matching.so.3.2 -> libopencv_surface_matching.so.3.2.0
-rw-r--r-- 1 root root   367480 Jul 26 13:38 /usr/local/lib/libopencv_surface_matching.so.3.2.0
lrwxrwxrwx 1 root root       21 Jul 26 13:59 /usr/local/lib/libopencv_text.so -> libopencv_text.so.3.2
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_text.so.3.2 -> libopencv_text.so.3.2.0
-rw-r--r-- 1 root root   404304 Jul 26 13:47 /usr/local/lib/libopencv_text.so.3.2.0
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_videoio.so -> libopencv_videoio.so.3.2
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_videoio.so.3.2 -> libopencv_videoio.so.3.2.0
-rw-r--r-- 1 root root   243216 Jul 26 13:36 /usr/local/lib/libopencv_videoio.so.3.2.0
lrwxrwxrwx 1 root root       22 Jul 26 13:59 /usr/local/lib/libopencv_video.so -> libopencv_video.so.3.2
lrwxrwxrwx 1 root root       24 Jul 26 13:59 /usr/local/lib/libopencv_video.so.3.2 -> libopencv_video.so.3.2.0
-rw-r--r-- 1 root root   408144 Jul 26 13:39 /usr/local/lib/libopencv_video.so.3.2.0
lrwxrwxrwx 1 root root       26 Jul 26 13:59 /usr/local/lib/libopencv_videostab.so -> libopencv_videostab.so.3.2
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_videostab.so.3.2 -> libopencv_videostab.so.3.2.0
-rw-r--r-- 1 root root   744080 Jul 26 13:52 /usr/local/lib/libopencv_videostab.so.3.2.0
lrwxrwxrwx 1 root root       28 Jul 26 13:59 /usr/local/lib/libopencv_xfeatures2d.so -> libopencv_xfeatures2d.so.3.2
lrwxrwxrwx 1 root root       30 Jul 26 13:59 /usr/local/lib/libopencv_xfeatures2d.so.3.2 -> libopencv_xfeatures2d.so.3.2.0
-rw-r--r-- 1 root root  2927288 Jul 26 13:52 /usr/local/lib/libopencv_xfeatures2d.so.3.2.0
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_ximgproc.so -> libopencv_ximgproc.so.3.2
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_ximgproc.so.3.2 -> libopencv_ximgproc.so.3.2.0
-rw-r--r-- 1 root root  1149576 Jul 26 13:53 /usr/local/lib/libopencv_ximgproc.so.3.2.0
lrwxrwxrwx 1 root root       27 Jul 26 13:59 /usr/local/lib/libopencv_xobjdetect.so -> libopencv_xobjdetect.so.3.2
lrwxrwxrwx 1 root root       29 Jul 26 13:59 /usr/local/lib/libopencv_xobjdetect.so.3.2 -> libopencv_xobjdetect.so.3.2.0
-rw-r--r-- 1 root root   111552 Jul 26 13:44 /usr/local/lib/libopencv_xobjdetect.so.3.2.0
lrwxrwxrwx 1 root root       23 Jul 26 13:59 /usr/local/lib/libopencv_xphoto.so -> libopencv_xphoto.so.3.2
lrwxrwxrwx 1 root root       25 Jul 26 13:59 /usr/local/lib/libopencv_xphoto.so.3.2 -> libopencv_xphoto.so.3.2.0
-rw-r--r-- 1 root root   255144 Jul 26 13:44 /usr/local/lib/libopencv_xphoto.so.3.2.0
ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$

Did -

export LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/lib

Then changed OPENCV_DIR to /usr/local, it does seem to help, but does not seem to work completely…

ubuntu@tegra-ubuntu:~/work/FromNvidia/gpuMat1$ gst-launch-1.0 nvcamerasrc ! 'video/x-raw(memory:NVMM), width=1280, height=720, format=I420, framerate=120/1' ! nvivafilter customer-lib-name=./lib-gst-custom-opencv_cudaprocess.so cuda-process=true ! 'video/x-raw(memory:NVMM), format=RGBA' ! nvegltransform ! nveglglessink
Setting pipeline to PAUSED ...

Available Sensor modes : 
3864 x 2174 FR=60.000000 CF=0x1009208a10 SensorModeType=4 CSIPixelBitDepth=10 DynPixelBitDepth=10
Pipeline is live and does not need PREROLL ...
Got context from element 'eglglessink0': gst.egl.EGLDisplay=context, display=(GstEGLDisplay)NULL;
Setting pipeline to PLAYING ...
New clock: GstSystemClock

NvCameraSrc: Trying To Set Default Camera Resolution. Selected sensorModeIndex = 0 WxH = 3864x2174 FrameRate = 60.000000 ...

OpenCV Error: Gpu API call (invalid device symbol) in linearRow, file /home/ubuntu/opencv/modules/cudafilters/src/cuda/row_filter.hpp, line 365
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/ubuntu/opencv/modules/cudafilters/src/cuda/row_filter.hpp:365: error: (-217) invalid device symbol in function linearRow

Aborted (core dumped)

Thanks for active help Honey_Patouceul.

Are you running R28.1 ?

Furthermore, I notice

in linearRow, file /home/ubuntu/opencv/modules/cudafilters/src/cuda/row_filter.hpp

that doesn’t refer to the expected include path /usr/local/include…

Have you run

sudo make install

after successful build of opencv-3.2.0 ? (Assuming you had configured with CMAKE_INSTALL_PREFIX=/usr/local).

I did the install of opencv 3.2.0. However, I ran sudo make install again. But do not quite see row_filter.hpp in /usr/local/include

ubuntu@tegra-ubuntu:~/opencv/build$ sudo find / -name row_filter.hpp
/home/ubuntu/opencv/modules/cudafilters/src/cuda/row_filter.hpp
find: ‘/run/user/1000/gvfs’: Permission denied

May be I need to check whether opencv was build with proper CUDA flags ?

Thanks

Probably the trace was embedded at build time, sorry for the confusion.

I’m rebuilding opencv-3.2.0 on my TX2 R28.1 for checking, it will take some time…

It works also with my opencv-3.2.0.
Attached is my opencv-3.2.0 build CMakeCache.txt, you might check for differences with yours.
CMakeCache.txt (310 KB)

Thanks Honey_Patouceul,

This appears to be due to opencv compilation. When I disable cv_process () call in the code, I am able to see image (not sobel processed image). It does not crash.

Could you please give your 3.2.0 CMakeLists.txt and the cmake command ? Such that I use the same options that you used to build 3.2.0 ?

When I diff with you CMakeCache.txt I do see that CUDA_ARCH_BIN:STRING=6.2 for you and it is 5.3 for me.

Thanks

Yes, for TX2 it should be 6.2 (5.3 is for TX1).

I configured with cmake-gui (in package cmake-qt-gui, but installing it may pull a lot of qt and other packages). If you use it, be sure to desactivate WITH_OPENCL* options that it enables. Be sure to check and fix any errors in RED in the console.
For having exactly the same config as me, you may have to install some packages, but I don’t think you need exactly that.

Attached is the CMakeLists.txt from opencv-3.2.0 src directory. It should be the same as yours, unless you have a different opencv-3.2.0 version.
I build in a separate folder than src folder.
CMakeLists.txt (60.3 KB)

Hi Honey_Patouceul,
I was able to compile opencv-3.3.0 and link your code with it. It does not crash anymore like it did before. However I do not see any Sobel/edge video of myself in front of camera. I just see normal video…

Do I need to set few more things/parameters ?

Thanks

Well, probably it has not found your custom lib (check your command line) or one of its libs (set LD_LIBRARY_PATH to have paths to your opencv-3.3.0/lib and cuda libs).
When nvivafilter doesn’t find the provided lib or its dependencies, it silently (unless you set GST_DEBUG to some level) falls back to /usr/lib/aarch64-linux-gnu/libnvsample_cudaprocess.so. This should draw a small rectangle near the top left corner.

You may add a trace with printf in init() function in order to be sure if your lib is used or not, and you should see it in gstreamer output after starting, just after ‘Setting pipeline to PAUSED …’.

Indeed. That was the case. Thanks. Now I have sobel output.

Thanks

Thanks Honey_Patouceul for your help. I am using custom CSI2 cameras from econ-systems accessing them through V4L2. So when I ran everything I got the following error :

WARNING: erroneous pipeline: could not link v4l2src0 to nvivafilter0

I am using this command to access the camera and it works fine:

gst-launch-1.0 v4l2src ! "video/x-raw, format=(string)UYVY, width=(int)3840,height=(int)2160" ! nvvidconv ! "video/x-raw(memory:NVMM),format=(string)I420, width=(int)3840, height=(int)2160" ! nvoverlaysink overlay-w=1920 overlay-h=1080 sync=false

but I got the above error when I’ve added the nvivafilter bit.

This message seems to say that you had removed nvvidconv from pipeline, or inserted nvivafilter before nvvidconv.
As v4l2src outputs into CPU memory, it cannot be linked directly to nvivafilter that expects its input from NVMM memory.

nvvidconv can copy from one memory space to the other one. Try:

gst-launch-1.0 v4l2src ! "video/x-raw, format=(string)UYVY, width=(int)3840,height=(int)2160" ! nvvidconv ! 'video/x-raw(memory:NVMM),format=(string)I420, width=(int)3840, height=(int)2160' ! nvivafilter customer-lib-name=./lib-gst-custom-opencv_cudaprocess.so cuda-process=true ! 'video/x-raw(memory:NVMM), format=RGBA' ! nvoverlaysink overlay-w=1920 overlay-h=1080 sync=false

Thank you again Honey_Patouceul, that did work. I just have a couple more questions:

  1. How can I print out the time it took to capture the frame? Or in other works how can I measure the FPS ?

  2. How can I call the .so lib from my c++ code instead of calling it from gst ?

cheers