Unable to use opencv cuda calls - c++

After a fresh install of jetpack on my tk1 board I found myself unable to use opencv's gpu calls. I'm using opencv 2.4.12
OpenCV Error: Gpu API call (CUDA driver version is insufficient for CUDA runtime version) in copy, file /hdd/buildbot/slave_jetson_tx_2/35-O4T-L4T-Jetson-L/opencv/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp, line 877
Error: /hdd/buildbot/slave_jetson_tx_2/35-O4T-L4T-Jetson-L/opencv/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp:877: error: (-217) CUDA driver version is insufficient for CUDA runtime version in function copy
Here's the output of nvcc -V
ubuntu#tegra-ubuntu:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2014 NVIDIA Corporation
Built on Wed_Nov_12_15:57:57_CST_2014
Cuda compilation tools, release 6.5, V6.5.30
.bashrc
# Add CUDA bin & library paths:
export PATH=/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
# Add CUDA bin & library paths:
export PATH=/usr/local/cuda/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export LD_LIBRARY_PATH=/usr/local/cuda/lib:
NOTE: I installed cuda 7.0 before and without installing it I simply installed the deb file with the 6.5. The nvcc -V shows I'm using 6.5 but could it possibly still be using the 7.0?
Here is what I'm trying to compile and the compile command I used
g++ `pkg-config --cflags opencv` Fix.cpp -o Saliency `pkg-config --libs opencv`
#include <iostream>
#include "opencv2/opencv.hpp"
#include "opencv2/gpu/gpu.hpp"
int main (int argc, char* argv[])
{
try
{
cv::Mat src_host = cv::imread("file.png", CV_LOAD_IMAGE_GRAYSCALE);
cv::gpu::GpuMat dst, src;
src.upload(src_host);
cv::gpu::threshold(src, dst, 128.0, 255.0, CV_THRESH_BINARY);
cv::Mat result_host(dst);
cv::imshow("Result", result_host);
cv::waitKey();
}
catch(const cv::Exception& ex)
{
std::cout << "Error: " << ex.what() << std::endl;
}
return 0;
}

Adding CW answer to get this off the unanswered list. According to OP's comment, this advice seems to have led to a solution:
"CUDA driver version is insufficient for CUDA runtime version" means just what it says. You have a mismatched environment.
My guess would be that you built your OpenCV when you had a more recent CUDA toolkit version installed (say, 7.0), and then when you installed the jetpack, things reverted (CUDA driver, CUDA runtime, CUDA toolkit) to effectively 6.5 versions. This means any libraries (say, OpenCV libs) built against CUDA 7.0 are no longer usable.
My guess would be that you need to rebuild OpenCV against your current environment.

Related

Can't cross-compile opencv linux-arm on c++ for RPI

(This is the first time I ask question in stackoverflow. And I'm not fluent in English. sorry for not asking clearly)
I am trying to cross-compile opencv based c++ code on Ubuntu(using virtual box) and try to use it on RPI 4.
I use Ubuntu 16.04(using virtual box) and downloaded OpenCV 4.0.1 refer to this site https://webnautes.tistory.com/1030?category=704653
And I down loaded cross-compiiler by sudo apt-get install git gcc-arm-linux-gnueabihf make ncurses-dev build-essential
After that I wrote c++ code like this.
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int ac, char** av){
Mat img =imread("/home/laboman/ex/ex.jpeg", 0);
Mat img_edge;
Canny(img, img_edge, 50, 200);
imshow("original", img);
imshow("img_edge", img_edge);
waitkey(0);
return 0;
}
It works well when I just compile it on Ubuntu.
But when I tried to cross-compile it
arm-linux-gnueabihf-gcc -o qwer /home/laboman/ex/ex.cpp $(pkg-config opencv4 --libs --cflags) -std=c++11
it came out with an error
/usr/local/lib/libopencv_gapi.so: file not recognized: File format not recognized
collect2: error: ld returned 1 exit status
First, I thought there are no libopencv_gapi.so on /usr/local/lib but there were on that file.
I think the problem is that arm-linux cannot cognize(I'm not sure this is right word) the opencv when cross-compiling.
Don't know how cross-compiling can cognize the opencv.
Please tell me what I have to do?
P.S. I also tried old version of OpenCV OpenCV 2.4.9.1

Where do I get standard library headers when compiling for arm cortex m4 using clang?

When using clang++ to build a simple hello world application, clang can't find standard library files. Should I point clang to arm-none-eabi for those files?
I'm using the clang binary downloaded from the llvm website.
#include <stdio.h>
int main(void)
{
printf("Hello World");
return 0;
}
Build Command:
clang++ -c -target arm-none-eabi -mcpu=cortex-m4 main.cpp
The above fails to locate stdio.h
Ultimately I'm going to be doing all of this using cmake on both windows and linux but I figure baby steps...

Ubuntu 16.04, Nvidia toolkit 8.0 RC, darknet compilation error: expected a ";"

I am compiling Darknet on Ubuntu 16.04 with GPU support.
Nvidial toolkit version 8.0 RC
And I get stuck with error:
nvcc --gpu-architecture=compute_52 --gpu-code=compute_52 -DOPENCV `pkg-config --cflags opencv` -DGPU -I/usr/local/cuda/include/ --compiler-options "-Wall -Wfatal-errors -Ofast -DOPENCV -DGPU" -c ./src/convolutional_kernels.cu -o obj/convolutional_kernels.o
/usr/local/cuda/include/surface_functions.h(134): error: expected a ";"
/usr/local/cuda/include/surface_functions.h(135): error: expected a ";"
/usr/local/cuda/include/surface_functions.h(136): error: expected a ";"
/usr/local/cuda/include/surface_functions.h at error lines has something like this:
template<> __device__ __cudart_builtin__ char surf1Dread(surface<void, cudaSurfaceType1D> surf, int x, enum cudaSurfaceBoundaryMode mode) asm("__surf1Dread_char") ;
Any advice ?
So it happens when your environment uses different versions of nvcc binary and cuda includes files during compilation process.
Darknet is using /usr/local/cuda/include/ as its include path
but relys on you PATH when executing nvcc binary. And it could belong to your another cuda installation in the system.
To avoid this force your shell to search for nvcc in the /usr/local/cuda/bin/nvcc.
This could be done either by hacking nvcc path in the Makefile:
replace NVCC=nvcc with NVCC=/usr/local/cuda/bin/nvcc
or by modyfying PATH variable for make command (simpler and session related)
PATH=/usr/local/cuda/bin:$PATH make
If you have several versions of CUDA installed and need them (like me), I recommend adding the following to your (BASH) RC:
# DARKNET
export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda8.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
Source your RC ('. ~/.bashrc') and complilation works!
This error is because of nvcc version 7.5
Looks like Cuda toolkit 8.0 RC installation via deb files does not have nvcc version 8
I have reinstalled cuda via cuda_8.0.27_linux.run installed and it works for me now

Premake not working with g++ on Linux?

Premake Version: 4.3 (downloaded here)
When running make on Linux, I get the following error: "g++: x86_64: No such file or directory." Upon removing the $(ARCH) from CFLAGS, make works fine.
Red Hat:
System Version ("cat /etc/redhat-release"): Red Hat Enterprise Linux Server release 6.5 (Santiago)
Kernel Version ("uname -r"): 2.6.32-431.11.2.el6.x86_64
"uname -p": x86_64
"uname -m": x86_64
C++ compiler: g++
Ubuntu:
System Version ("cat /etc/issue"): Ubuntu 12.04.5 LTS
Kernel Version ("uname -r"): 3.2.0-67-generic
"uname -p": x86_64
"uname -m": x86_64
C++ compiler: g++
I've also run the same program successfully on Mac.
Mac:
System Version: OS X 10.10 (14A389)
Kernel Version: Darwin 14.0.0
"uname -p": i386
"uname -m": x86_64
C++ compiler: clang
premake4.lua
solution "Hello"
configurations { "Debug", "Release" }
configuration { "Debug" }
defines { "_DEBUG", "DEBUG" }
flags { "Symbols", "ExtraWarnings" }
configuration { "Release" }
defines { "NDEBUG" }
flags { "Optimize" }
project "hello"
kind "ConsoleApp"
language "C++"
location "."
files { "hello.cpp" }
hello.cpp is the standard hello world program.
Is there a reason for the $(ARCH)? From looking at the documentation for both clang and g++, it does not seem like providing just the architecture type without a flag is a compiler option. Am I missing something?
That $(ARCH) variable has been in the generated makefiles for quite some time, but it appears it has outlived its usefulness. I have removed it for now; if there is still a need to inject flags into the build we can find a safer name.
You can get a fixed version from the Premake 4.x BitBucket repository.

OpenCv + mac os x + qt creator = strange linking bug?

I'm trying to build simple OpenCV app using qt creator on Mac Os X 10.9. So i've installed OpenCv and Qt4 using brew:
brew install opencv
brew install qt4
and then downloaded qt creator. Than i've made simple project - main.cpp:
#include <QCoreApplication>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat m;
m = Mat(2, 3, 4);
cv::threshold(m, m, 123, 200, 1);
m = cv::imread("asdasd", 1); //problem is here!
return a.exec();
}
and .pro file:
QT += core
QT -= gui
TARGET = opencv_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
LIBS += -L/usr/local/lib \
-lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_objdetect \
-lopencv_calib3d
INCLUDEPATH += /usr/local/include/opencv
DEPENDPATH += /usr/local/include/opencv/include
INCLUDEPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/include
DEPENDPATH += $$PWD/../../../usr/local/lib
Now the weird part - if i comment this line: m = cv::imread("asdasd", 1); //problem is here! and build project, everything is fine - it will compile and link without any problem. So it seems that .dylib files are ok, because i can use OpenCV functions - Mat object constructor and threshold function. But! If i don't comment line with imread i get this error: :-1: błąd:symbol(s) not found for architecture x86_64 or to be more precise:
Undefined symbols for architecture x86_64: "cv::imread(std::string
const&, int)", referenced from:
_main in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see
invocation)
Generally the problem is just a part of bigger problem - i'm trying to build much bigger project using qt creator, but linker can't find some(but not all!) functions. In project which uses lot of OpenCV functions linker has got problems only with:
cv::VideoCapture::VideoCapture(std::string const&)
cv::destroyWindow(std::string const&)
cv::CascadeClassifier::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, int, int, cv::Size_<int>, cv::Size_<int>)
cv::CascadeClassifier::CascadeClassifier(std::string const&)
cv::imshow(std::string const&, cv::_InputArray const&)
In this project i'm using much more functions (mostly basic image processing - threshold, image copying, drawing basic primitives, finding contours) and linker can handle them without any problem.
What i've already tried - building OpenCv and Qt4(only using build brew install qt4 --from-source) from sources. I've builded OpenCv using this tutorial - http://sadeepj.blogspot.com/2012/03/installing-and-configuring-opencv-to.html I've also tried a lot of CMAKE options - -DCMAKE_OSX_ARCHITECTURES=x86_64 or i386 and -DCMAKE_CXX_FLAGS="-stdlib=libc++". I've also tried to build it using gcc(defautt compiler is clang) version 4.2, but it failed(building failed).
i've tried with OpenCV 2.4.8 and 2.4.2.
Also i've tried to set:
CMAKE_CXX_FLAGS += -std=c++11
CMAKE_CXX_FLAGS += -stdlib=stdlibc++
Still no luck.
I've checked whether builded .dylib files are x86_64:
/usr/local/lib[master]$ lipo -info libopencv_core.dylib Non-fat file:
libopencv_core.dylib is architecture: x86_64
and whether highgui file contains any information about imread function(i know that it is not a proof that it export this function):
/usr/local/lib[master]$ nm libopencv_highgui.dylib | grep imread
00000000000069b0 T __ZN2cv6imreadERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEi
0000000000006ac0 t __ZN2cvL7imread_ERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEEiiPNS_3MatE
Information which might be important: Mac OS X 10.9, 64 bit.
/usr/local/lib[master]$ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
/usr/local/lib[master]$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Btw - isn't it strange that running gcc --version in fact runs clang ?
So the question is - what can i do to compile and build it? Should i try using gcc or maybe something else will solve this problem? Also - if someone could upload his libraries and share a link it, so i could try with them it would be great. Any solution that will solve this problem will be fine for me - i can build everything from source, use any compiler, linker, etc.. - just help me make it working and i will be happy :)
Ok - finally after 4 days of searching i've solved this problem. Generally solution is simple - just add:
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.9
to you .pro file. If don't want to add it to every .pro file you can set it "globally" - just set it in this file:
Qt5.2.0/5.2.0-rc1/clang_64/mkspecs/macx-clang/qmake.conf
More information about this bug/problem:
Qt5.1/Qt5.2 + Mac OS 10.9 (Mavericks) + XCode 5.0.2, Undefined symbols for architecture x86_64
http://qt-project.org/forums/viewthread/35646/ <-- mostly here
//edit:
This solution only works with CLang, no luck with gcc.