I using python opencv3.2 in ubuntu14.04,install follow open-python 3.2.0.7 : Python Package Index, and installed by pip but still get error when call cv2.imshow()
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /io/opencv/modules/highgui/src/window.cpp, line 583
, so I try build opencv 3.2.0 followed Install OpenCV 3.0 and Python 2.7+ on Ubuntu,but i didn't see the cv2.so after make install
CMake: cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
where i can find cv2.so ?
Sounds like CMake never found your Python dev libararies and/or numpy libraries.
Be sure to sudo apt install libpython2.7-dev and sudo pip install numpy then specify to CMake where these libraries are using the flags:
-D PYTHON2_INCLUDE_DIR=/usr/include/python2.7 \
-D PYTHON2_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython2.7.so \
-D PYTHON2_NUMPY_INCLUDE_DIRS=/usr/lib/python2.7/dist-packages/numpy/core/include \
-D PYTHON2_PACKAGES_PATH=/usr/lib/python2.7/dist-packages
The above is for python 2.7 only.
then build and install:
make -j$(nproc)
sudo make -j$(nproc) install
The cv2.so file should now reside in your python site-packages or dist-packages folder.
Related
I'm trying to run a cmake project using conan as a package manager where the project is compiled in a docker container. I'm using Clion's docker integration support as outlined here.
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(FormatOutput CXX)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
add_definitions("-std=c++11")
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake"
"${CMAKE_BINARY_DIR}/conan.cmake"
TLS_VERIFY ON)
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_configure(REQUIRES fmt/9.1.0
GENERATORS cmake_find_package)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE .
BUILD missing
REMOTE conancenter
SETTINGS ${settings})
find_package(fmt)
add_executable(main main.cpp)
target_link_libraries(main fmt::fmt)
Dockerfile
FROM debian:sid
RUN DEBIAN_FRONTEND="noninteractive" apt-get update && apt-get -y install tzdata
RUN apt-get update \
&& apt-get install -y build-essential \
gcc \
g++ \
gdb \
clang \
make \
ninja-build \
cmake \
autoconf \
automake \
libtool \
valgrind \
locales-all \
dos2unix \
rsync \
tar \
python3 \
python3-dev \
python3-pip \
&& apt-get clean
RUN pip install conan
ENV CONAN_USER_HOME=/.conan_docker
RUN mkdir $CONAN_USER_HOME && chmod 777 $CONAN_USER_HOME
docker-compose.yml
version: "3.4"
services:
clion-cpp-env:
image: clion/debian/cpp-env:1.0
build: .
platform: linux/amd64
cap_add:
- SYS_PTRACE
ports:
- 2222:22
volumes:
- "/tmp/conan_docker:/.conan_docker"
restart: on-failure
Clion Docker Toolchain Configuration
Build output
-- Conan: Using autogenerated Findfmt.cmake
-- Found fmt: 9.1.0 (found version "9.1.0")
-- Library fmtd found /.conan_docker/.conan/data/fmt/9.1.0/_/_/package/0d8b943d676dc202f180a2598d04457e173d7b97/lib/libfmtd.a
-- Found: /.conan_docker/.conan/data/fmt/9.1.0/_/_/package/0d8b943d676dc202f180a2598d04457e173d7b97/lib/libfmtd.a
-- Library fmtd found /.conan_docker/.conan/data/fmt/9.1.0/_/_/package/0d8b943d676dc202f180a2598d04457e173d7b97/lib/libfmtd.a
-- Found: /.conan_docker/.conan/data/fmt/9.1.0/_/_/package/0d8b943d676dc202f180a2598d04457e173d7b97/lib/libfmtd.a
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/docker_conan/cmake-build-debug-docker
[Finished]
Output on trying to run executable
====================[ Build | main | Debug-Docker ]=============================
/usr/bin/cmake --build /tmp/docker_conan/cmake-build-debug-docker --target main -j 6
ninja: error: '/.conan_docker/.conan/data/fmt/9.1.0/_/_/package/0d8b943d676dc202f180a2598d04457e173d7b97/lib/libfmtd.a', needed by 'main', missing and no known rule to make it
While the local compilation builds and runs without complaints, on compiling with the Docker toolchain on Clion, I'm able to build but not run the executable. Apparently the library is not found where conan installed it previously. How do I make this work?
Thanks to #Alan Birtles suggestion, the flaw in my approach was that the volumes/mount information was missing from my container instance.
Although I'd mentioned it in my docker-compose.yml file, it's likely that Clion is not running the docker container via docker-compose, and instead using the docker run command internally instead.
Thus, one needs to append to one's Docker Container Settings: the following volume mount information:
-v /path/to/localmachine/conan-docker:/conan_docker
I'm new to cmake, and could't figure out how to achieve this after a few days.
I'm trying to build a C++ project that depends on OpenCV using cmake, but I want cmake to clone and install it like this. I found a project's CMakeFile that I'm using as reference to accomplish this.So I have this:
main.cpp:
#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
std::cout << "OpenCV Version: " + cv::getVersionString() << std::endl;
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(cv_playground)
set(CMAKE_CXX_STANDARD 14)
find_package(Git REQUIRED)
include(ExternalProject)
# OpenCV
set(OPENCV_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/opencv)
ExternalProject_Add(opencv
GIT_REPOSITORY https://github.com/opencv/opencv
GIT_TAG 68942affdbc4677aa845bc4307d4752182324a0e # 4.0.0-alpha
SOURCE_DIR opencv
BINARY_DIR opencv-build
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${OPENCV_INSTALL_LOCATION}
)
include_directories(${OPENCV_INSTALL_LOCATION}/include/opencv4)
link_directories(${OPENCV_INSTALL_LOCATION}/lib)
add_executable(cv_playground main.cpp)
add_dependencies(cv_playground opencv)
target_link_libraries(cv_playground opencv_core opencv_dnn opencv_features2d opencv_flann opencv_highgui opencv_imgcodecs)
But when building the project I get a lot of undefined references (pthread, gz, dlopen/dlclose, itt_domain_create_ptr, etc)
I would like to know how to fix those undef refs, I already installed pthread, zlib, etc but I don't know how to make cmake to use them. I tried to add them in the target_link_libraries for example but still gives me the same errors:
CMakeLists.txt (note the CMAKE_DL_LIBS in target_link_libraries):
cmake_minimum_required(VERSION 3.12)
project(cv_playground)
set(CMAKE_CXX_STANDARD 14)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
find_package(Git REQUIRED)
include(ExternalProject)
# OpenCV
set(OPENCV_INSTALL_LOCATION ${CMAKE_BINARY_DIR}/opencv)
ExternalProject_Add(opencv
GIT_REPOSITORY https://github.com/opencv/opencv
GIT_TAG 68942affdbc4677aa845bc4307d4752182324a0e # 4.0.0-alpha
SOURCE_DIR opencv
BINARY_DIR opencv-build
CMAKE_ARGS
-DWITH_OPENGL=OFF
-DCMAKE_INSTALL_PREFIX=${OPENCV_INSTALL_LOCATION}
)
include_directories(${OPENCV_INSTALL_LOCATION}/include/opencv4)
link_directories(${OPENCV_INSTALL_LOCATION}/lib)
add_executable(cv_playground main.cpp)
add_dependencies(cv_playground opencv)
target_link_libraries(cv_playground Threads::Threads ${CMAKE_DL_LIBS} opencv_core opencv_dnn opencv_features2d opencv_flann opencv_highgui opencv_imgcodecs)
Error message (still get undefined reference to dlopen, dlclose, ...)
[ 90%] Linking CXX executable cv_playground
/home/syonekura/CLionProjects/cv_playground/cmake-build-debug/opencv/lib/libopencv_core.a(system.cpp.o): In function `cv::TLSData<cv::(anonymous namespace)::ThreadID>::createDataInstance() const':
system.cpp:(.text._ZNK2cv7TLSDataINS_12_GLOBAL__N_18ThreadIDEE18createDataInstanceEv+0x37): undefined reference to `__itt_thread_set_name_ptr__3_0'
/home/syonekura/CLionProjects/cv_playground/cmake-build-debug/opencv/lib/libopencv_core.a(opencl_core.cpp.o): In function `GetHandle(char const*)':
opencl_core.cpp:(.text._ZL9GetHandlePKc+0x7): undefined reference to `dlopen'
opencl_core.cpp:(.text._ZL9GetHandlePKc+0x1e): undefined reference to `dlsym'
opencl_core.cpp:(.text._ZL9GetHandlePKc+0x53): undefined reference to `dlclose'
/home/syonekura/CLionProjects/cv_playground/cmake-build-debug/opencv/lib/libopencv_core.a(opencl_core.cpp.o): In function `opencl_check_fn(int)':
opencl_core.cpp:(.text._ZL15opencl_check_fni+0x3f): undefined reference to `dlsym'
So I've had quite a few issues with this myself. Cmake should essentially be used just to build the OpenCV library. Provided you're using an ubuntu machine you want to do this:
# Update and upgrade packages
sudo apt-get -y update
sudo apt-get -y upgrade
# Remove any existing versions of x264
sudo apt-get remove x264 libx264-dev
# Install OS Libraries
# Install Dependencies
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm gfortran git
sudo apt-get -y install libjpeg8-dev libjasper-dev libpng12-dev
# Used for Ubuntu 16.04
sudo apt-get -y install libtiff5-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt-get -y install libxine2-dev libv4l-dev
sudo apt-get -y install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev libtbb-dev
sudo apt-get -y install libatlas-base-dev
sudo apt-get -y install libfaac-dev libmp3lame-dev libtheora-dev
sudo apt-get -y install libvorbis-dev libxvidcore-dev
sudo apt-get -y install libopencore-amrnb-dev libopencore-amrwb-dev
sudo apt-get -y install x264 v4l-utils
# Install Optional Dependencies
sudo apt-get -y install libprotobuf-dev protobuf-compiler
sudo apt-get -y install libgoogle-glog-dev libgflags-dev
sudo apt-get -y install libgphoto2-dev libeigen3-dev libhdf5-dev doxygen
# Download OpenCV from Github
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 3.3.0
cd ..
# Download opencv_contrib from Github
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout 3.3.0
cd ..
# Compile and Install OpenCV with contrib
# Create build directory inside opencv directory
cd opencv
mkdir build
cd build
# Run CMake with the following options
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D WITH_TBB=ON \
-D WITH_V4L=ON \
-D WITH_QT=ON \
-D WITH_OPENGL=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
# Compile and Install
make -j4
sudo make install
sudo sh -c 'echo "/usr/local/lib" >> /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
You can cherry pick the parts that are most relevant, but essentially what this entails is making the OpenCV library available to your project. You can then either use a make file to make your project, or you can run a command as so:
c++ pkg-config --cflags opencv filename.cpp pkg-config --libs opencv -o filename
This creates an executable called filename
I'm using an ubuntu terminal to run a cmake .
But, the boost libraries couldn't be found.
The following Boost libraries could not be found:
boost_program_options
boost_signals
boost_serialization
boost_unit_test_framework
With commands like:
cmake . -DBoost_USE_STATIC_LIBS=ON
The problem persist, also, if I use a location boost_unit_test_framework I'm not getting any result.
How I can install those references?
You can use apt-get command (requires sudo)
sudo apt-get install libboost-all-dev
How to Install boost on Ubuntu?
If you do not want to install all Boost libraries, you can install selectively what you need.
For example, for boost_unit_test_framework you can do:
sudo apt install libboost-test-dev
And the others would be:
sudo apt install libboost-program-options-dev libboost-serialization-dev libboost-signals-dev
I trying to use kinect on OPENCV and I realized that openni is the best library for kinect
but I could not find the latest version of it(Because the site is closed)
and i am using openni1.5.4 nite1.5.2 sensorkinect5.1.2.1 and opencv2.4.9 in ubuntu14.04LST
kinect installed correctly and i can run sample project from openni folder
now i want to use openni in opencv project, like this
VideoCapture sensor1;
sensor1.open(CV_CAP_OPENNI);
but It doesn't work and I noticed this error can be from cmake variable so i remake opencv build files with
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_OPENNI=ON ..
and in terminal i can see
OpenNI: YES (ver 1.5.4, build 0)
-- OpenNI PrimeSensor Modules: YES (/usr/lib/libXnCore.so)
but when i use
cout << cv::getBuildInformation();
in my project , i get this
OpenNI: NO
OpenNI PrimeSensor Modules: NO
Where is the problem and What is the solution?
I thank you in advance
Finally the problem was solved
i installed libfreenect like this
mkdir -p ~/Developer/Work
cd ~/Developer/Work
git clone https://github.com/OpenKinect/libfreenect
cd libfreenect
git checkout tags/v0.3.0
NOTE: Tested with libfreenect stable release v0.3.0
Build and install:
cd ~/Developer/Work/libfreenect mkdir build cd build cmake .. -D BUILD_OPENNI2_DRIVER=ON make sudo make install
cd ~/Developer/Work/libfreenect
mkdir build
cd build
cmake .. -D BUILD_OPENNI2_DRIVER=ON
make
sudo make install
Add to library path:
sudo nano /etc/ld.so.conf.d/custom.conf
Add
/usr/local/lib/ /usr/local/lib/OpenNI2-FreenectDriver/
And
sudo ldconfig
Test with glview:
sudo glview
in cmake i use BUILD_OPENNI2_DRIVER=ON but i didn't install openni2 , i use openni1.5.4
and Be sure to use a computer not VMware (i couldn't get stream on VMware)
So I downloaded FFmpeg from svn. Compiled and installed into system. in /usr/local it created ./lib and ./include. one with includes and one with libs in form of *.a files.
I downloaded eclipse Helios for C++ and created new simple project. I included ffmpeg headers into my C++ file. in project properties in C/C++Build in settings I declared ffmpeg libs (Library search path was declared)
I wrote some simple code that calls functions from headers.
But for all ffmpeg functions I used it gave me errors of eclipse not seeing ffmpeg.
So I wonder - how to connect ffmpeg libs to my project (or may be there is any way to compile ffmpeg not into .a and it would work with .so)?
I had the same problem on my ubuntu 12.04 and I fixed it by compiling ffmpeg and x264 in this way:
I removed the folders of ffmpeg and x264 and then typed this in the terminal:
sudo apt-get remove ffmpeg x264
sudo apt-get autoremove
and then
sudo apt-get update
sudo apt-get upgrade
then
sudo apt-get install make automake g++ bzip2 python unzip patch subversion ruby build-essential git-core checkinstall yasm texi2html libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libvdpau-dev libvorbis-dev libvpx-dev libx11-dev libxfixes-dev libxvidcore-dev zlib1g-dev
installing x264
sudo git clone git://git.videolan.org/x264.git
cd x264
sudo ./configure --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ..
installing libvpx
sudo wget http://webm.googlecode.com/files/libvpx-v0.9.7-p1.tar.bz2
sudo tar xvjf libvpx-v0.9.7-p1.tar.bz2
cd libvpx-v0.9.7-p1
sudo ./configure --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ..
check if /etc/ld.so.conf contains the lines /usr/lib and /usr/local/lib. if not then add them and save it
then run
sudo ldconfig
installing ffmpeg
sudo wget http://ffmpeg.org/releases/ffmpeg-0.8.10.tar.bz2
sudo tar xvjf ffmpeg-0.8.10.tar.bz2
cd ffmpeg-0.8.10
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-shared --prefix=/usr/local
sudo make
sudo make install
cd ..
sudo ldconfig
in your project you should include the headers in this way:
#include<libavformat/avformat.h>
#include<libavcodec/avcodec.h>
In eclipse you should add the ffmpeg libraries to your project: avutil, avformat, avcodec, m, z ... by going to project->properties->C/C++->Build->Settings->GCC C++-> Linker->Libraries
I hope this works for you
You need to link them with your code. Use -l and -L gcc command line parameters in your make file, or edit the properties for your Eclipse project (go to the project properties->C/C++->Build->Settings->GCC C++-> Linker->Libraries.
if the includes and libraries that you want are in /usr/local/include and /usr/local/lib respectively, seems that you are covered with include and library paths (these directories are in the default search path usually).
Verify that you didn't use lib... when specifying the library that you want to link to, this is prepended by default, e.g. to use libabc.a just specify abc in the library list of the project settings.
If you are getting compile errors (not linker errors), make sure libav* folders reside in /usr/local/include and you include ffmpeg headers with their folder names.
#include libavformat/avformat.h
#include libavcodec/avcodec.h
// ...
You have to define /usr/local/include as an include directory and not libav* folders inside. This is needed because ffmpeg headers themselves reference other headers this way.
This is dependent on platform.
You have to properly configure the ffmpeg libraries with all the right flags mingw/or cygwin. you would get .a files recognizable by eclipse.
as littleadv says you must configure the path to the ffmeg libraries. in the project ->build properties- include(ffmpeg folderand your mingw/cygwin local include ) and linker settings avformat avcodec avfilter avdevice swscale postproc .
Do not forget to set the path variable in your os. Eclipse takes this. Path should point to lib and include /local mingw/cygwin.