(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
Related
I want to begin writing saying that I know that this topic has been talked about multiple times. I can see several posts with similar titles as I'm typing this now. The reason that I'm asking this question once again is because I've tried what those posts stay, and it still won't work. I've copied a simple script that upscales an image using opencv in C++ to begin the learning journey and to make a script that I hope to use in the future very often, maybe even share on GitHub. With that being said, here's more detail about my issue.
In my IDE, Visual Studio Code, my include path has been set to "/opt/homebrew/Cellar/opencv/4.6.0/include/opencv4/".
I've tried using the -I arguments, -l arguments, whatever this is: "pkg-config --cflags --libs opencv4", but none of that worked.
The only time that I could get it to work is using the following command, but even then, g++ returned: fatal error: too many errors emitted, stopping now [-ferror-limit=] 41 warnings and 20 errors generated.
Here's the program that I have:
#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main() {
Mat frame = imread("/Users/karsoneskind/Desktop/Programming/C++/ibootimformer/tests/image.jpg");
namedWindow("Output", 0);
namedWindow("Input", 0);
Mat output;
resize(frame, output, Size(1000, 200), 0, 0);
imshow("Output", output);
imshow("Input", frame);
waitKey(0);
}
Edit: This is the command in terminal I used to try to compile the code:
g++ test.cpp -o test pkg-config --cflags --libs opencv4
Is there a way to output monochrome TIFF files in OpenCV with group 4 compression?
This is the command to do it with imagemagick/graphicsmagick
'gm convert '.$file.' -type bilevel -monochrome -compress group4 '.$output
OpenCV version 4.5.1
update
# g++ -Wall -O3 -std=c++17 main.cpp -o main `pkg-config opencv4 --cflags --libs` -ltiff
find doesn't return anything
root#x:/usr/include/opencv4/opencv2# find . -name "*tif*"
code
#include <tiffio.h>
#include <opencv4/opencv2/opencv.hpp>
std::vector<int> params = {cv::IMWRITE_TIFF_COMPRESSION, COMPRESSION_CCITTFAX4};
cv::imwrite(_output, src_bin, params);
error
[ WARN:0] global ../modules/imgcodecs/src/grfmt_tiff.cpp (914)
writeLibTiff OpenCV TIFF(line 914): failed TIFFSetField(tif,
TIFFTAG_PREDICTOR, predictor) imwrite_('out.tif'): can't write data:
OpenCV(4.5.1) ../modules/imgcodecs/src/grfmt_tiff.cpp:914: error:
(-2:Unspecified error) OpenCV TIFF: failed TIFFSetField(tif,
TIFFTAG_PREDICTOR, predictor) in function 'writeLibTiff'
OpenCV uses libtiff (link). If you call cv.imwrite (link) you can pass additional parameters.
For group 4 compression the docs say that you have to pass the IMWRITE_TIFF_COMPRESSION flag (link) with value COMPRESSION_CCITTFAX4 (link).
Example:
#include <tiffio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
vector<int> params = {IMWRITE_TIFF_COMPRESSION, COMPRESSION_CCITTFAX4};
bool success = imwrite("image.tif", img, params);
Update
Well, this is how it should work. But it seems that opencv4 currently has one or more issues in writing Group 4 TIFF. Btw it's the same when you try the python-lib. This known issue deals with a predictor tag that is wrongly added by opencv. I applied the fix to my local build but after that one more issue came up missing a conversion of the 8bit Mat to 1bit/sample for group4. So my recommendation is:
Workaround
Instead you can use the GraphicsMagick API Magick++.
#include <opencv2/opencv.hpp>
#include <Magick++.h>
using namespace cv;
using namespace Magick;
int main(int argc, char* argv[]) {
InitializeMagick("");
Mat img = imread("img.png");
Image image(img.cols, img.rows, "BGR", CharPixel, (char *)img.data);
image.compressType(CompressionType::Group4Compression);
image.write("img.tif");
return(0);
}
I have been troubled by the problem these days. I want to write opencv-3.0.0 programs with C language in the terminal of my ubuntu 14.04 in the VM. While, in early days, I have installed Qt. Now, In order that my program is not affected by the Qt library function, I shielded the path variables of Qt in the /etc/bash.bashrc file. A simple example is as follows:
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat img = imread("cornea.jpg");
imshow("src, img");
waitKey(0);
return 0;
}
Then I compile it with gcc-5.3.0 by using this command:
g++ test.cpp -o test pkg-config opencv --cflags --libs opencv
And then I have the result:
/usr/bin/ld: warning: libicui18n.so.54, needed by //home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicuuc.so.54, needed by //home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libicudata.so.54, needed by //home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5, not found (try using -rpath or -rpath-link)
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_clone_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘uenum_next_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘u_strToLower_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getStandardName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_setAttribute_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_setMillis_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_strcoll_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_setSubstChars_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_getTimeZoneDisplayName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_openCountryTimeZones_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_fromUnicode_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_open_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getDefaultName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_open_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_inDaylightTime_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucol_getSortKey_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getAvailableName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_get_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_openTimeZoneIDEnumeration_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_getDSTSavings_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_open_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_openTimeZones_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_toUnicode_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘u_strToUpper_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘u_errorName_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘uenum_close_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_countAvailable_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getMaxCharSize_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_getAlias_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucal_getDefaultTimeZone_54’未定义的引用
//home/lmk/Qt5.5.0/5.5/gcc/lib/libQt5Core.so.5:对‘ucnv_compareNames_54’未定义的引用
collect2: error: ld returned 1 exit status
The backticks in command line pkg-config opencv --cflags --libs opencv is invisible.I have not got the reason now.
Why this error is related to Qt. And can you help me solve it?
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.
As of late I have been getting the following error whenever I try to compile any program that uses the open cv libraries, I use g++ to compile:
g++ Example.cpp -o Ex `pkg-config opencv --cflags --libs`
No matter the content of the file (I have checked with programs that worked a couple of weeks ago) I always get the following error:
/usr/lib64/libX11.so.6: undefined reference to `xcb_poll_for_reply64'
/usr/lib64/libX11.so.6: undefined reference to `xcb_wait_for_reply64'
Do you have any idea of what might be the cause? (and how to fix it)
An example program that fails to compile:
#include "path/opencv2/highgui/highgui.hpp"
#include "path/opencv/highgui.h"
using namespace cv;
int main (int argc, char * argv[])
{
Mat image = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE) ;
return 0;
}
Add -lxcb to your command line (this will instruct the linker linking w/ the xcb library). Please make sure the 64b version of xcb is in the linker path (you can always put it explicitly via the -L switch)
The error was caused by some changes done to the libX11.so.6, talked with the FE machines support and they fixed it.