OpenCV can not find library on launch. Backwards compatibility? - c++

I am trying to build and use a piece of C++ code that uses OpenCV. I am working on Linux, working in Code::Blocks (and the code was originally also developed on a Linux platform using C::B).
I followed this to install OpenCV (Ubuntu 12.04 & OpenCV 2.4.3). The project compiles fine, but when I try to execute it, it crashes on launch, with the following message about how it can not find the library:
(file_address): error while loading shared libraries: libopencv_core.so.2.3:
cannot open shared object file: No such file or directory
Process returned 127 (0x7F) execution time : 0.017 s Press ENTER to continue.
I set all the parameters for the linker according to several Code::Blocks install tutorials.
I also checked in /usr/local/lib/ for my libraries (it is the folder I gave to Code::Blocks' compiler); and while I do have a libopencv_core.so, a libopencv_core.so.2.4 and a libopencv_core.2.4.3, I do not have a libopencv_core.so.2.3.
So I'm wondering what the issue is. Is it about backwards compatibility, i.e. do I have to install the exact same version of OpenCV used to develop the original code? (This would be a bit concerning, since I am trying to make a widely-usable library).
Could I force it to use libopencv_core.so.2.4 instead?
EDIT: I managed to make it work by removing everything and reinstalling with a simple apt-get. Sometimes it's the simplest method that works the best! From now on I'll try to apt-get before following installation tutorials. ;)
Have a nice day!

Related

Using SFML for Codeblocks C++ appears ERROR library SFML

I have a problem when I tried to install SFML on Codeblocks. Well, first I install codeblocks: codeblocks-20.03mingw-setup.exe . That's compile correctly after that I download SFML 2.5.1: GCC 5.1.0 TDM (SJLJ) - Code::Blocks - 32-bit.
Following, I extract the SFML file.The problem comes I COPY THE CONTENT OF "BIN" INSIDE OF MY CODEBLOCKS PROJECT. A video helps me to do all of before, I WROTE ALL THE LIBRARIES: GRAPHICS, WINDOW, NETWORK, AUDIO, SYSTEM BUT NOTHING. I show you the error:
cannot find -lsfml-audio-d-2
And continue with network, window,system, graphics
At the ends:
error: ld returned 1 exit status
what's wrong? help me please. I have to make a video game using CODEBLOCKS as soon as I fixed this problem. I'll so thankful for your answers.
On the SFML download website (https://www.sfml-dev.org/download/sfml/2.5.1/), it says:
The compiler versions have to match 100%!
The CodeBlocks 20.03 MinGW installation includes version 8.1.0 of the GCC compiler (as is stated on the download page: http://www.codeblocks.org/downloads/26).
Your downloaded version of SFML thus is only intended to work with version 5.1.0 of GCC, but you have version 8.1.0. This can result in a number of errors.
There are a few possibilities to fix your issue:
You could theoretically compile SFML yourself with your specific compiler, but this option may be quite complicated.
You could use a compiler with the matching version. On the SFML download website, there are some links to the needed compilers. After having installed a compiler, you will have to configure CodeBlocks to detect the new compiler on your system (reference: Adding compiler to code::blocks). Now, in order to add SFML to your project, I would suggest to use this official guide:
https://www.sfml-dev.org/tutorials/2.5/start-cb.php
You could use an environment like MSYS2 (which I use personally) to have a package manager to manage your compiler and libraries installations. This way, your compiler installation and your libraries should work with each other. But in order to use this compiler in CodeBlocks, CodeBlocks would have to be configured.
I would suggest that you refer to option 2 because it probably is the quickest solution.
Feel free to ask if you have any more questions. I know from personal experience that setting up SFML (or any other C++ library) to work with your IDE may be quite tricky.

How to install wxwidgets on Eclipse Mars.2 Mac?

I want to start doing some c++ but need it to be cross platform. I have found wxWidgets as a GUI solution and will use some of their SQL solutions for my program.
I tried searching the internet for how to install wxwidgets on Eclipse Mac but no luck. Haven't found anything that I can wrap my head around it.
wxWidgets is a C++ cross-platform and cross-compiler solution. It means that you don't need to install it. You can just compile it and use it to develop a software.
In order to compile this library, you should have a C/C++ compiler (clang or gcc on OSX/Mac) and their toolchain. Also if you plan to develop for OSX, you shuold have an OSX/Cocoa SDK installed (it is installed automatically with Xcode, have no idea about Eclipse).
In order to do so, you should:
Install C/C++ compiler (either with Xcode or Eclipse or any other IDE you have available).
Download latest wxWidgets release and unpack to you home diectory.
Open up a Terminal and issue following commands:
a. cd ~/wxWidgets
b. mkdir buildMac
c. cd buildMac
d. ../configure --enable-debug --with-cocoa --with-mac-osx-version-min=10.7 && make
e. ./wx-config --cxxflags
f. ./wx-config --libs
Open up Eclipse and start a new C++ project. If you are on OSX you may choose C++ bundle application.
Open the project properties and copy the results of the commands 3e and 3f to the project properties where appropriate. Consult with Eclipse manual/ML/forum to understand where to put that info.
Copy the file ~/wxWidgets/samples/minimal/minimal.cpp to you project directory and add this file to you project. Compile and run the project.
If you get stuck with any of the above instructions or get an error during compilation of either library or your project - don't hesitate to ask either here or open another thread.
Also, you can register on the wxWidgets forum at forums.wxWidets.org and subscribe to the wx-users ML.
Good luck.

OpenCV C++ does not load ANY video on Ubuntu 16.04 under VideoCapture

I installed OpenCV 2.4.13 after installing the required dependencies and I'm running it with Qt Creator 5.7 for programming in C++. Following some tutorials I managed to load still images, process them and so on. But when I try to use the cv::VideoCapture, for example:
cv::VideoCapture cap;
cap.open("<File location/file name>");
or:
cv::VideoCapture("<File location/file name");
cap.isOpened() always return false. Even if I try to ignore this and go further with Mat, read, imshow and so on, the program crashes. I've already tried everything about loading the file: giving a std::string as argument, giving a *char, putting the video file on easier locations, in the project directory and nothing works. I tried with two different .mp4, with a .mov and with the cube4.avi file given in the "samples" folder (from openCV examples). All these files are perfectly played by my VLC. I've already tried in Qt with a QtWidgets project and with a plainCpp project. It never works. After searching about it, I've seen that this bug is very recurrent, but I've just found solutions for Windows, regarding on adding a .dll file to the project. But what should I do on Ubuntu, since Linux uses no dlls?
I figured out how to solve this and I'm here to share with everyone who encounter similar problems. First of all, my FFmpeg installation was for any unknown reason ignored on the OpenCV compilation. Since FFmpeg is needed to read and write videos, OpenCV wasn't able to do these jobs and displayed no error or warning messages about that. Anyway I decided to try everything again from the beginning. Keep in mind: if you just reinstall FFmpeg, it's not going to solve your problems; after that you have to do cmake, compile and install OpenCV again. I downloaded the most recent version of FFmpeg from the repository, compiled and installed it again. I tried to compile OpenCV again, but it was always stuck at about 15% when processing a FFmpeg (Libav) .h file with the message:
<file_name.h> can not be used when making a shared object; recompile with -fPIC
So I searched for it and with some effort I found out that it was necessary to compile the FFmpeg with the following configure line before doing the make:
.\configure --enable-pic --enable-shared
Some ffmpeg installation tutorials include even more commands after "configure". Then I compiled and reinstalled FFmpeg and compiled and reinstalled OpenCV. After that, I was able to load videos (the cap.isOpened() was no longer false), but nonetheless I was getting the following error for any video and they weren't being read:
Assertion desc failed at libswscale/swscale_internal.h:674
The way I found to solve this was downloading the newest stable FFmpeg version instead of the newest on, compiling it again, compiling OpenCV again and then it was successful! Now I can both load and write video files (I haven't tested it with multiple codecs yet). I wonder why they don't launch pre-compiled versions of OpenCV with everything so that we don't need to deal with all these stuffs...
Summarizing everything:
Download the last stable release of FFmpeg. If it doesn't work, try an older one. (I'm using the 2.8.6, the last stable right now).
Unpack it, open the terminal from the ffmpeg folder, compile and install it typing:
.\configure --enable-pic --enable-shared
make
sudo make install
Download OpenCV (if you haven't done it yet), unpack and install it following the official linux installation tutorial:
http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation
I solve the problem by install "opencv3.2.0-dev" instead "opencv3.2.0";
pip install opencv-python is not enough to install OPENCV.

OpenCV3.0 and Qt creator

I need to use OpenCV with Qt creator, and need some help with OpenCV.
My problem occurs when I run any example or .exe made with OpenCV, after I install OpenCV with CMake (and checking WITH_QT in the process).
For example with the examples included in the installation, when I try to open one I get the following error:
http://answers.opencv.org/upfiles/1413994743487541.png
That says: Procedure entry point not found in the dynamic links library
My S.O. is Windows 8.1, 64 bits
I have tried to reinstall Qt and install differents versions, but the error is the same ever.
But, if I install OpenCV with CMake and donĀ“t check WITH_QT, the examples works perfectly.
I dont know what else can I do!
Thanks!

build problems with Qt and opencv on Windows

I would like to create a gui application with Qt, using opencv on Windows XP. I used both Qt and opencv before, but never together. Long story short, I'm unable to get opencv work with Qt.
As on all the forums I searched there are just little pieces of information scattered around, usually with no answer, I summarize here all the steps I've taken.
Downloaded the Qt SDK (4.6.3) for Windows, and used it for some time, successfully.
Downloaded the opencv 2.3.1 megapack for Windows, complete with binaries. I managed to compile my Qt project including opencv successfully, but any opencv function call resulted in a crash. I read on some forums that the binaries in the Windows megapack don't support Qt, and I have to build opencv myself
I downloaded the latest version of CMake (2.8).
I downloaded the source of opencv from here: http://code.opencv.org/svn/opencv/branches/2.3/
I downloaded the source for the version of Qt I had (4.6.3)
I found my old version of visual Studio 2005
I created a VS2005 project with CMake, checking the support for Qt. (WITH_QT checked)
I built opencv in VS2005. It created most of the libraries, but not all. Highgui was among the failed ones. The problem: Qt\4.6.3\src\corelib\global\qconfig.h was not found. There was no qconfig.h at all in the source I downloaded! I found some templates qconfig-large.h, qconfig-small.h etc., so I renamed one of them to qconfig.h. Now I got a screen full of linker errors.
I downloaded the latest Qt source instead (4.8.1). Now there is a source file qbenchmark.h that includes QtTest/qbenchmarkmetric.h which cannot be found.
I gave up, and tried MinGW.
I downloaded the latest MinGW (2011.11.18)
I set CMake to generate a MinGW makefile, but I got the following error:
.
CMake Error at C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-g++.cmake:1 (INCLUDE):
include could not find load file:
C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/Platform/Windows-gcc.cmake
Call Stack (most recent call first):
C:/Program Files/CMake 2.8/share/cmake-2.8/Modules/CMakeCXXInformation.cmake:59 (INCLUDE)
True, there is a Windows-g++.cmake file in the Modules/Platform directory, but it references Windows-gcc.cmake which does not exist!
Is there anyone who managed to build opencv with Qt support on Windows, and if yes, how?
Edit:
The problem is definitely with the Qt source. I managed to generate a MinGW makefile, and the build went all OK until it stopped in src/testlib/qtestsystem.h because there was an include for QtCore/qelapsedtimer.h which file is in a completely different directory! Does Qt release incomplete sources, or did I do something wrong?
Edit2
My torment continues. I cleaned everything and started anew. This time without even trying Visual Studio.
I downloaded the latest Qt libs with source (4.8.1)
I downloaded the latest MinGW (2011.11.18)
With CMake I successfully created a Makefile, and built it with MinGW. I got some shiny new libs (libopencv_core231, etv.). I was very happy, but how wrong I was to celebrate that soon!!
I downloaded the latest Qt SDK (strangely, it was 4.8.0, so I set Qt Creator to use the 4.8.1) and created a test program without opencv to see if it works. It worked!
I tried using opencv, just reading and displaying an image. It didn't work. exited with code -1073741511
I tried running the .exe directly, outside of Qt Creator. It complained of a missing libstdc++-6.dll
I did a search for it, and found on in my MinGW install (c:\mingw\bin, 958 KB), and one in my Qt install (c:\qt\mingw\bin, 793 KB) - this mingw came bundled with Qt.
I tried both, by copying them in the same folder where my .exe is, but neither worked. I got "The procedure entry point _ZNSt9exceptionD2Ev could not be located in the dynamic link library libstdc++-6.dll." with both. This was in debug, so I tried release, and I got a similar error, with some other entry point not found.
I searched the forums, and I found suggestions that I should link libstdc++ statically. I inserted -static-libgcc -static-libstdc++ at the lines QMAKE_LFLAGS = and QMAKE_LFLAGS_DEBUG = in the file c:\Qt\mkspecs\win32-g++\qmake.conf. This had no effect at all, even after restarting Qt Creator and rebuilding. If I don't copy the libstdc++-6.dll, it still requires it.
Of course, my simple test program without opencv runs from the exe without needing any libstdc++-6.dll, so that means my opencv build is responsible? I wanted to build opencv anew, but I cannot find any CMake settings referring to libstdc++ !
It might be a clue:
When using one of the libstdc++-6.dll files, the error about a missing entrypoint mentions QtGui4.dll. I have a debug build, so it should be QtGui*d*4.dll, shouldn't it? Are there different libstdc++s for debug and release? Either way, I tried to build release, but it didn't work either, same error
Is there no single person on this planet who tried using Qt with QtCreator and opencv 2.3 together on Windows xp, and succeeded? From searching all the forums and Qt archives, I could not find anyone. I'm ready to do the development in Linux, but I'll need a Windows release sooner or later anyway.
I'm trying to resist the temptation of the dark side, which whispers into my ears to forget Qt, MinGW, g++, opencv and try to hack together something in Visual Basic. Oh, the horrors!
Just FYI, I went basically through the same nightmare of combining Qt and OpenCV. This was my experience:
I downloaded the Qt SDK 4.7.4 with Qt Creator 2.4.1 and installed it, no problem.
I downloaded and installed OpenCV 2.4.2 and not knowing that it already came with MinGW...
I downloaded the MinGW compiler which of course had a different version than the one which came already with Qt
This completely messed up my CMake, even when I explicitly told CMake to use the Qt gcc.exe and g++.exe it also used some stuff from my freshly installed MinGW. Probably because I eagerly added every directory to my PATH variable. What a fool I was!
CMake was not able to generate any useful files, so I gave up and installed the OpenCV superpack, hoping this would make things easier.
6.I spent hours wondering, why Qt and OpenCV from the superpack didnt work properly together. I never quite understood. I had the same errors that other users describe here, like console programs crashing as soon as some OpenCV was included. The strange thing is, that I could start the executable manually from FileExplorer (I added all .dlls you could think of to the project folder: opencv_core242.dll, opencv_highgui242.dll, QtCore4.dll, QtGui4.dll and so on...) BUT I could not launch my little test program from within the Qt Creator environment.
I analysed if there was a problem with my DLLs using depends.exe and found out that even though I configured everything to be in DEBUG using the MinGW compiler, my program still tried to use QtCore4.dll and not QtCore4d.dll... So my best guess was, that it was mixing debug and release version.
I gave up using the superpack and again tried to use CMAKE first and then build OpenCV using the Qt MinGW version AND making sure to setup everything for Debug mode and enable the QT option. But no luck with that so far
I stopped using MinGW and switched over to MSVC2010, which works better. However I am still not able to debug the program since the MSVC2010 debugger engine seems to be missing. I dont really know how to manually add this but I am still working on it
So what I can definitely tell is that using Qt and OpenCV for somebody who has little experience is far from trivial!
You should build OpenCV from source, as you already did, it is no hassle. Note that recent versions of OpenCV can be built with and w/o Qt. Highgui optionally uses Qt! It is your choice if you build with or without Qt.
I used Qt libraries together with OpenCV for long time now. I never went for the SDK, instead I used the libs which are built for corresponding VS version. See here: http://qt.nokia.com/downloads/downloads#qt-lib
You can have it for VS2008 and VS2010, but earlier versions are also available built for VS2005. Old versions of Visual Studio suck so hard, why use them anyway.
Then I never had problems pulling it together in a CMake project. It goes along the lines of:
find_package(OpenCV)
find_package(Qt4 ${VOLE_MINIMUM_QT_VERSION} COMPONENTS QtCore QtGui)
find_package(Qt4 ${VOLE_MINIMUM_QT_VERSION} COMPONENTS QtOpenGL)
...
qt4_wrap_cpp(moc_sources ${vole_module_moc_sources})
qt4_wrap_ui(uic_sources ${vole_module_ui_sources})
qt4_add_resources(rcc_sources ${vole_module_rcc_sources})
You know, the usual stuff.
Five man weeks later you may probably get it run under Windows, while under GNU/Linux it is three commands in the shell.
You might have an easier time configuring Qt Creator with OpenCV. This post shows how to achieve that, step-by-step! It displays several screenshots to aid in the process too.