[OpenCV4Tegra] "unknown error in function mallocPitch" while trying to initialize GpuMat

Hi all, long time reader, first time writer.

I’ve just started working with a TX1 and I’ve been trying to get OpenCV to use the Tegra GPU while running classifiers. After a while of trying various samples and test to make sure that the GPU is actually doing work, I’ve found a minimal-ish test case to prove to myself that I definitely cant get it running.

Has anyone run into this before? It seems like I’ve fundamentally misconfigured something related to CUDA or opencv4tegra.


#include <iostream>
#include <sstream>

#include <opencv2/core/core.hpp>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"

using namespace std;

int main(int argc, char** argv)
    cv::gpu::GpuMat test;

    test.create(1, 1, CV_8U);
    return 0;

Compilation, plus runtime error:

johnwittrock@tegra0:~/opencv_test$ make
g++ opencv_test.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_calib3d -lopencv_contrib -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -o opencv_test
johnwittrock@tegra0:~/opencv_test$ ./opencv_test
OpenCV Error: Gpu API call (unknown error) in mallocPitch, file /hdd/buildbot/slave_jetson_tx_3/35-O4T-L4T-R24/opencv/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp, line 1134
terminate called after throwing an instance of 'cv::Exception'
  what():  /hdd/buildbot/slave_jetson_tx_3/35-O4T-L4T-R24/opencv/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp:1134: error: (-217) unknown error in function mallocPitch


OpenCV4Tegra installation:

johnwittrock@tegra0:~/opencv_test$ dpkg --list | grep opencv
ii  libopencv4tegra                             2.4.13-17-g5317135                                  arm64        Tegra optimized Open Computer Vision Library
ii  libopencv4tegra-dev                         2.4.13-17-g5317135                                  arm64        Development files for Tegra optimized Open Source Computer Vision Library
ii  libopencv4tegra-repo                        2.4.13-17-g5317135                                  arm64        Repository with Tegra optimized Open Source Computer Vision Library

Hi jwittrock,

Your code works fine on my device. How did you install your opencv4tegra? Are you using jetpack?

Hi jwittrock,

Have you resolved this opencv4tegra issue?
What’s the BSP you’re using?