compile gpu samples at ubuntu by terminal [duplicate] - opencv

Recently I'm learning openCV. I followed the tutorial on openCV website.
http://docs.opencv.org/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html#howtoscanimagesopencv
However, when I compile my code using following command
g++ loadImage.cpp -o loadImage
the command line shows:
fatal error: 'opencv2/core/core.hpp' file not found
#include <opencv2/core/core.hpp>
^
I installed openCV with brew, I think it is OK. Then I use emacs to edit and g++ compile my code directly, is that the problem? I searched some similar problems but they refer to xCode environment. Thanks for your help!

You need to tell g++ where it can find the header files. I recommend you setup either eclipse or any other IDE that can handle that stuff for you (like Qt Creator or many others). You can follow the setup guides for OpenCV for instructions, if needed.
[edit: note that I know that emacs can also be setup to handle things like include and library paths, but I have no idea how, hence my recommendation for a full scale IDE]
You can also specify the path to the includes on the command line with -I, then it should also work. Example:
g++ -I/path/to/OpenCV-2.4.9/build/include loadImage.cpp -o loadImage
There are environment variables you can set so you don't have to specify this for every call (see this page for a complete list, specifically CPATH and it's variants might be of interest.

So I find an answer myself, using cmake! How did I miss that..
http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage

Related

avoid using sudo to use z3++.h as a lib

I am using the z3prover first time, after reading most of related answers, I have noticed that I need to try: sudo make install .How could I skip the link z3 in /usr/bin and /usr/lib to use z3++.h in my own c++ project. (bcs I have noticed not everyone has the sudoer, I hope my code would goes well without sudoer.
You do need to compile the z3 source code if you want to be able to use it in your C/C++ projects. Compiling it will give you the library to link against. If you just download the source code, you can find the headers but you cannot link and hence cannot create your own executables.
But doing so does not require sudo access at all. The proper way to do so is actually explained in the https://github.com/Z3Prover/z3 page, right in the README. Roughly, they go like this:
python scripts/mk_make.py --prefix=/home/leo
cd build
make
make install
Note in the prefix parameter of the first line you tell z3 where to install everything. Change that path to a place where you have write-access. This way you do not need sudo access.
In order to compile your project successfully, you need to tell your compiler where to look for dynamic libraries and header files. Ask separately if you run into issues.
If you use GCC as the compiler you should add -I option for your project as follows :
g++ -Iz3_path/include -Lz3_path/lib -lz3

How to set OpenCv Environment Variable and Path Variable on a Mac?

I am doing a tutorial on how to install and use Opencv with Cmake. I have gotten through to a step that says Set OpenCV_DIR environment variable to path to Opencv install folder and the directly after Set Path variable where Opencv is installed. I am lost and all the tutorials / solutions I have looked at seem outdated or do not work. Please could someone show me how to do this. Thanks so much for any help.
If you are using Windows, the quick way is to open CMake GUI application and change the variable wherever you want. For a Mac/Linux machine, command line might be your best choice, and this thread will be really helpful for you.

How to do digital image processing using opencv on Eclipse

I am new to Digital Image Processing and want to do it using OpenCV on Eclipse. I just want to know how can i start doing it and how i can configure opencv and eclipse using CMAKE . Please suggest me some good tutorial.Also please help me with adding opencv include files and library in Eclipse.
I am using Eclipse Juno.
on Windows 7.
Thanks.
Your best bet is to begin with the OpenCV documentation. Their Getting Started tutorial should be your first stop. They have another strategy with a custom FindOpenCV.cmake file as documented here but I would suggest sticking with the strategy outlined in Getting Started.
In terms of eclipse, cmake generates IDE related metadata for you and Kitware does provide an eclipse CDT generator, documented here. Two important things to keep in mind. First cmake actually generates the eclipse metadata which you then import as an existing project. Second, the example they give is intended to work with Unix makefiles:
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../certi_src
If you are using windows you'll want to choose an appropriate generator instead of "Unix Makefiles"

CMake-CPack Package Installation Path Nightmare

I've been frustrated by the the CMake-CPack for almost one week.
The bad thing is the CMake-CPack online documentation does not document this part well.
After googling, I found this variables to use:
CPACK_PACKAGING_PREFIX # NOT documented
CMAKE_INSTALL_PREFIX # Documented, but the behavior seems weird
CPACK_INSTALL_PREFIX # NOT documented
CPACK_PACKAGE_INSTALL_DIRECTORY # Documented, but this variable does NOT work as the online document described
CPACK_PACKAGING_INSTALL_PREFIX # NOT documented
What I am trying to do is: package a Debian package using fakeroot make package, when the package is installed by sudo dpkg -i MyProgramPackageName, install it to /usr/local, with a subdirectory MyProgramPackageName. That is, all files should be installed under /usr/local/MyProgramPackageName-V.1.2.3.
I've been trying (CMake 2.8.3 and CMake 2.8.5) to tune these variables. I tried so many combinations, but failed.
The only way succeeded is:
Set(CPACK_PACKAGING_INSTALL_PREFIX /usr/local/MyProgramPackageName-V.1.2.3)
But this variable is NOT even documented, and the behavior cannot be guaranteed. If you are confused with my question, please advise me when to use CPACK_PACKAGE_INSTALL_DIRECTORY? because the documentation description about this variable is really attractive, and it is really what I want, but I just could not make it working.
Please advise me.
Peter
I didn't find any documentation to support this, but I did find some bug reports and email archives that seem to suggest that the following is what you should be doing:
set(CPACK_SET_DESTDIR true)
set(CPACK_INSTALL_PREFIX /opt/MySuperAwesomePrefix-v.1.2.3)
If CPACK_INSTALL_PREFIX is not set, it will default to CMAKE_INSTALL_PREFIX. Now relative paths from install(... DESTINATION dest) will end up as CPACK_INSTALL_PREFIX/dest inside your package file. This worked when I tried to generate a deb file.
The paths used by the CPACK are taken from the INSTALL directives in your CMakeLists.txt files. This allows the result package to mirror what a 'make install' would do. This keeps the CPACK configuration to a minimum.
So, from an example CMakeLists.txt file:
INSTALL(TARGETS ${APPLICATION} DESTINATION bin)
This will install to /usr/bin or /usr/local/bin. If you wanted to place it in a subdirectory you could do it here:
INSTALL(TARGETS ${APPLICATION} DESTINATION bin/myappdir)
Or entirely different directory:
INSTALL(TARGETS ${APPLICATION} DESTINATION /opt/foo/bar)

cmake: default include path on unix

I'm using cmake and make to compile a project using an external library (speex).
This library is found by the find_library command in my CMakeLists.txt.
The only problem is: the default include path of cmake does not include /usr/local/include/, that is the location of speex's headers.
I do not want to add /usr/local/include/ to the search path in the CMakeLists.txt because it would (I suppose) generate an error on windows where such path doesn't exist.
Moreover, that would be a dirty trick, I'm not quite fond of this solution.
Do you know a solution to this problem which would be portable and clean ?
Thank you for your time.
Try using a full-blown speex find module, either created from scratch, or based on something found with http://www.google.com/search?q=findspeex.cmake
Punt the configuration to the user via the command line, e.g.
cmake -DSPEEX_PATH=/usr/local/include
Use the PATH argument of find_library to specify other places to search. If the path doesn't exist it shouldn't produce an error.

Resources