change macports installation makefile - opencv

how can I change the cmake file provided with the package? I am having troubles with OpenCV and found one possible solution:
So you can edit cmake/OpenCVDetectionVTK.cmake.
At line 6, change "vtkRenderingOpenGL" to "vtkRenderingOpenGL2".
But where do I change that if I am using port install?

If you look on directory up (out of directory build whether you create it) you will see the "cmake/"
Mine is look like this:
3rdparty CONTRIBUTING.md README.md build data include platforms
CMakeLists.txt LICENSE apps cmake doc modules samples
Open cmake then you will find it.
I hope this help you.

Related

Opencv 3 install directory name

I just built opencv version 3.3.1 from source and I'm trying to link the libraries in a CMakeLists.txt file. In order to do that I need to know the install location.
It looks like I found it to be located at /usr/local/include. What is throwing me off is there are two "opencv" titled folders in this directory, one is name open "opencv" the other is named "opencv2". However there is no "opencv3" folder, but when I run $opencv_version in my terminal I get output "3.3.1-dev". So I know I've successfully installed opencv version 3, however I don't see a similarly named directory.
When looking at my make install output I see lines like:
Installing: /usr/local/include/opencv2/highgui/highgui.hpp
-- Installing: /usr/local/include/opencv2/highgui/highgui_c.h
-- Installing: /usr/local/lib/libopencv_superres.so.3.4.1
-- Up-to-date: /usr/local/lib/libopencv_superres.so.3.4
so it looks like I'm installing opencv version 3 with a directory named "opencv2". Did the engineers who made opencv version 3 really name their install directory opencv2???
I just would like confirmation to make sure I'm not crazy.
The short answer is yes.
I set the install directory for opencv in my make file as "/usr/local/include/opencv2" and the library was found. Also thanks to api55 for confirming my suspensions.

How do I install clang-format without root privileges and without installing LLVM?

I have clang-format version 3.8.0 (tags/RELEASE_380/final) in my ~/bin folder on a Fedora machine with no root privileges. It works, but it is very old and I'd like to upgrade. I just want the clang-format tool, so I would like to avoid going through the full installation process for LLVM or clang if I can avoid it. I assume I can avoid it, since my old clang-format works without either of those installed. I don't remember how clang-format got in my ~/bin directory, and I can't figure out how to update it.
The first thing I tried was following this post which said I should be able to download a prebuilt binary from this page (I tried http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-x86_64-linux-gnu-Fedora27.tar.xz), then just set up a symlink to bin/clang-format. This did not work for me. When I type /path/to/bin/clang-format --help I get the error error while loading shared libraries: libtinfo.so.6: cannot open shared object file: No such file or directory.
The next thing I tried is downloading the clang source code and compiling that with
mkdir build && cd build && CC=$(which gcc) CXX=$(which g++) cmake ..
but when I did I got the error
CMake Error at CMakeLists.txt:36 (message):
llvm-config not found -- LLVM_CONFIG-NOTFOUND
Which I guess means I'd need to install the LLVM to go this route?
Any help getting an updated clang-format (vesion 5.0 at minimum) without root access would be appreciated. Bonus points for minimal installation (i.e. no clang or llvm).
=== EDIT ===
By downloading a bunch of different versions of prebuilt binaries, I've discovered that older versions (<4.0) have clang-formats that work out of the box, but at 4.0 and up give the same error about libtinfo. I guess that means I'll have to live with older versions unless I want to go through a painful installation process.
When you download llvm 6.0, make sure the directory structure is as follows:
llvm
|-->tools
|----->clang
|----> tools
|----> extra
If you just want to build clang-format, then you can cd into
llvm-build-dir/tools/clang/tools/extra/clang-format and then execute make -j8 all
later you can make a symbolic link in your /bin folder

How to prepend CMAKE_INSTALL_PREFIX when its provided at build-time?

I have a few libraries that I build in succession. Some depend on others. For example:
libfoo.so depends on libbar.so
And, I don't want to have to deploy these things system-wide on the build machine. In my cmake file I have something like the following:
find_library(FOO_LIB foo /usr/lib64 /usr/lib /usr/local/lib)
On the build machine I normally give it a CMAKE_INSTALL_PREFIX flag at compile-time. Is there a way to do something like this:
find_library(FOO_LIB foo ${CMAKE_INSTALL_PREFIX}/lib /usr/lib64 /usr/lib /usr/local/lib)
if the flag is provided, but use the first version if it isn't provided?
please forgive my noobish-ness with respect to cmake
[clarification] Each library is built by a separate CMakeLists.txt file.
If you have one cmake-project which include other cmake-projects (with your libraries and applications), you can use target names to link libraries: target_link_libraries(app foo bar)
If you build your libraries cmake project separately - it's not good way, I think, but you still have two options:
deploy your libraries before build app;
put already built libraries to third_party catalog and find it them (e.g. writing specific FindXXXX.cmake file which try to locate your libraries in third_party catalog first).

Open CV using Cmake

I am working on a harr detecttion project. I want to generate the exe files using the .cpp files that come with Opencv. I am using CMake for it. When I try to do that I am getting an error like this. Don`t know how to solve it.
CMake Error at CMakeLists.txt:7 (ocv_check_dependencies):
Unknown CMake command "ocv_check_dependencies".
Configuring incomplete, errors occurred!
Source link: C:/opencv/apps/haartraining
Destination link: D:/build
Please help me.
I was working on some image processing that involves Haar detection. And i was having a hard time trying to configure with Cmake at first but i finally found manual configuration tutorial with out using Cmake or else. It has helped me a lot and you can get it here. I hope it will work perfect as it worked for me too. Click here -> http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/. The tutorial uses open CV 2.3.1 but it will work perfect for recent versions too with the need for Cmake ore else.If you more questions, hit me up and i will explain.Good luck!
It looks like You need to compile the whole library with build examples option enabled (if You are using windows then I bet You use graphic cmake interface, so it shouldn't be a problem), and then You will find the .exe in bin directory,
or You would need to include OpenCVModule.cmake file found in cmake catalogue to CMake file You are trying to use for the build.
I didn't test the second option myself, but it looks like CMake file You are trying to use does not load all macros needed for it to run, but macros are loaded when the root library CMake file is used.

Could not find module FindOpenCV.cmake ( Error in configuration process)

I wrote a CMakeLists.txt for a project in C++, which uses OpenCV libraries. When I try to create the project using cmake, I get the next configuration problem:
CMake Error at CMakeLists.txt:15 (find_package):
Could not find module FindOpenCV.cmake or a configuration file for package
OpenCV.
Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
directory containing a CMake configuration file for OpenCV. The file will
have one of the following names:
OpenCVConfig.cmake
opencv-config.cmake
The fact is that I have an environment variable for the path which I use in Visual Studio with no problems. If I don't include OpenCV, then I can configure and generate with no problem, but I need to solve the problem. I don't understand why cmake cannot find the OpenCV path or how to fix it.
I also used the recommendations mentioned in this link:
FindOpenCV.cmake
Does anybody had this problem too?
The error you're seeing is that CMake cannot find a FindOpenCV.cmake file, because cmake doesn't include one out of the box. Therefore you need to find one and put it where cmake can find it:
You can find a good start here. If you're feeling adventurous you can also write your own.
Then add it somewhere in your project and adjust CMAKE_MODULE_PATH so that cmake can find it.
e.g., if you have
CMakeLists.txt
cmake-modules/FindOpenCV.cmake
Then you should do a
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
In your CMakeLists.txt file before you do a find_package(OpenCV)
If you are on Linux, you just need to fill the OpenCV_DIR variable with the path of opencv (containing the OpenCVConfig.cmake file)
export OpenCV_DIR=<path_of_opencv>
apt-get install libopencv-dev
export OpenCV_DIR=/usr/share/OpenCV
the header of cpp file should contain:
#include
#include "opencv2/highgui/highgui.hpp"
#include
#include
not original cv.h
find / -name "OpenCVConfig.cmake"
export OpenCV_DIR=/path/found/above
I had this exact same problem. I fixed it by adding the following line to my FindOpenCV.cmake file. Put it anywhere at the top before the rest of the code.
set (OpenCV_DIR /home/cmake/opencv/compiled) #change the path to match your complied directory of opencv
Basically you are telling FindOpenCV.cmake where to find opencv files assuming the other compilation can find the FindOpenCV.cmake
I faced the same error. In my case this "OpenCVConfig.cmake" file is located in /usr/local/share/OpenCV. In CMakeLists.txt add the line
set(OpenCV_DIR /usr/local/share/OpenCV)
as suggested by the error message.
if you are on windows, you can add opencv path to OpenCV_DIR yourself.
(OpenCV_DIR is in the red region)
the path is like "D:/opencv244/build".
you can find file "OpenCVConfig.cmake" under the path.
Another possibility is to denote where you can find OpenCV_DIR in the CMakeLists.txt file. For example, the following cmake scripts work for me:
cmake_minimum_required(VERSION 2.8)
project(performance_test)
set(OpenCV_STATIC ON)
set(OpenCV_CUDA OFF)
set(OpenCV_DIR "${CMAKE_SOURCE_DIR}/../install")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})
file(GLOB my_source_files ./src/*)
add_executable( performance_test ${my_source_files})
target_link_libraries(performance_test ${OpenCV_LIBS})
Just to remind that you should set OpenCV_STATIC and OpenCV_CUDA as well before you invoke OpenCVConfig.cmake. In my case the built library is static library that does not use CUDA.
On my Fedora machine, when I typed "make" I got an error saying it could not find "cv.h". I fixed this by modifying my "OpenCVConfig.cmake" file.
Before:
SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib64")
After:
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
SET(OpenCV_LIB_DIR "/usr/lib64")
I am using Windows and get the same error message. I find another problem which is relevant.
I defined OpenCV_DIR in my path at the end of the line. However when I typed "path" in the command line, my OpenCV_DIR was not shown. I found because Windows probably has a limit on how long the path can be, it cut my OpenCV_DIR to be only part of what I defined. So I removed some other part of the path, now it works.
I had the same error, I use windows. I add "C:\opencv\build" (opencv folder) to path at the control pannel.
So, That's Ok!!
For me (on Ubuntu), I just run:
sudo apt-get install libopencv-dev
Followed #hugh-pearse 's and #leszek-hanusz 's answers, with a little tweak. I had installed opencv from ubuntu 12.10 repository (libopencv-)* and had the same problem. Couldn't solve it with export OpenCV_DIR=/usr/share/OpenCV/ (since my OpenCVConfig.cmake whas there). It was solved when I also changed some lines on the OpenCVConfig.cmake file:
# ======================================================
# Include directories to add to the user project:
# ======================================================
# Provide the include directories to the caller
#SET(OpenCV_INCLUDE_DIRS "${OpenCV_INSTALL_PATH}/include/opencv;${OpenCV_INSTALL_PATH}/include")
SET(OpenCV_INCLUDE_DIRS "/usr/include/opencv;/usr/include/opencv2")
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
# ======================================================
# Link directories to add to the user project:
# ======================================================
# Provide the libs directory anyway, it may be needed in some cases.
#SET(OpenCV_LIB_DIR "${OpenCV_INSTALL_PATH}/lib")
SET(OpenCV_LIB_DIR "/usr/lib")
LINK_DIRECTORIES(${OpenCV_LIB_DIR})
And that worked on my Ubuntu 12.10. Remember to add the target_link_libraries(yourprojectname ${OpenCV_LIBS}) in your CMakeLists.txt.
When you install the libraries in the c drive (windows). the CMakeLists.txt shoud be looking like below:
cmake_minimum_required(VERSION 3.0.0)
project(test_opencv VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test_opencv main.cpp)
target_link_libraries(test_opencv ${OPENCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
finding the package and include directories
when building the project in VS code. Run the visual studio code with admin rights as the OpenCV is installed inside C drive.

Resources