open cv cmake can't find png and jpeg - opencv

I downloaded opencv 3.2,and run:
cmake -D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -D PYTHON_EXECUTABLE=$(which python)
-D OPENCV_EXTRA_MODULES_PATH=/home/alex/Software/opencv_contrib/modules
-D WITH_OPENGL=ON
-D WITH_JPPEG=ON
-D WITH_PNG=ON
-D WITH_CUDA=ON
-D ENABLE_FAST_MATH=1
-D WITH_CUBLAS=1 ..
under ubuntu 16.04 got:
- Media I/O:
....
-- JPEG: NO
-- WEBP: build (ver 0.3.1)
-- PNG: NO
........
as you can see that both JPEG and PNG give 'NO',and I hava got libjpeg-dev,libgtk2.0-dev and libpng-dev installed.So how to make opencv to support jpeg and png?

Related

ubuntu) installed opencv with cmake but python couldn`t find cv2 module

i just want to know about this problem.
pkg config show my opencv4 version, but in python3 there`s no module named cv2.
please help me...!
cmake list:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=ON -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D BUILD_PACKAGE=OFF -D BUILD_EXAMPLES=OFF -D WITH_TBB=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.7 -D WITH_CUDA=ON -D WITH_CUBLAS=ON -D WITH_CUFFT=ON -D WITH_NVCUVID=ON -D WITH_IPP=OFF -D WITH_V4L=ON -D WITH_1394=OFF -D WITH_GTK=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_EIGEN=ON -D WITH_FFMPEG=ON -D WITH_GSTREAMER=ON -D BUILD_JAVA=OFF -D BUILD_opencv_python3=ON -D BUILD_opencv_python2=OFF -D BUILD_NEW_PYTHON_SUPPORT=ON -D OPENCV_SKIP_PYTHON_LOADER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.5.1/modules -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D CUDA_ARCH_BIN=8.6 -D CUDA_ARCH_PTX=8.6 -D OpenCL_LIBRARY=/usr/local/cuda-11.7/lib64/libOpenCL.so -D OpenCL_INCLUDE_DIR=/usr/local/cuda-11.7/include/ ..
cuda-11.7 cudnn- so.8 opencv-4.5.1
Did you check the build information before building and installing OpenCV? If not, you can still check the build information using the OpenCV function getBuildInformation(). To find your OpenCV configuration, create a C++ file, add the following code to it, and execute the file:
#include <opencv2/opencv.hpp>
int main(void)
{
std::cout << cv::getBuildInformation() << std::endl;
}
Reference: https://learnopencv.com/get-opencv-build-information-getbuildinformation/
Once you have the build information, check the Python3 options (usually found at the bottom of the output). OpenCV Python bindings have not been generated if the install path is unspecified.
That means OpenCV has to be built again with the proper Python3 addresses.
The following options need to be added to the CMake command:
-D PYTHON_EXECUTABLE=$(which python3)
-D OPENCV_PYTHON3_INSTALL_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
Then, run a clean build, and check the configuration page for the correct Python3 options. A step-by-step guide is posted by learnopencv for installing OpenCV DNN module with GPU support on Linux.

Getting CMake Error with Protobuf Library in the configuration of OpenCV in Raspberry Pi

I followed this tutorial to install OpenCV and all the steps worked until I reached the Install part. I did the following:
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \
-D BUILD_EXAMPLES=ON ..
The command performed several tests and showed the General configuration for OpenCV 3.3.0 but at the end I got the following error:
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Protobuf_LIBRARY
linked by target "opencv_dnn_modern" in directory /home/pi/opencv_contrib-3.3.0/modules/dnn_modern
-- Configuring incomplete, errors occurred!
See also "/home/pi/opencv-3.3.0/build/CMakeFiles/CMakeOutput.log".
See also "/home/pi/opencv-3.3.0/build/CMakeFiles/CMakeError.log".
I have a opencv_contrib-3.3.0 directory though instead of opencv_contrib that's why I included the -3.3.0 in the make.
I solved the issue through the following steps:
Deleting the build folder in the opencv directory
Recreating the build folder: mkdir build
Moving to that build directory: cd build
Adding the following line in the make: -D BUILD_opencv_dnn_modern=OFF
and running it as follows:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_opencv_dnn_modern=OFF \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \
-D BUILD_EXAMPLES=ON ..

Compiling Opencv with Gstreamer, cmake not finding GStreamer

I want to build opencv with GStreamer support.
I built the GStreamer from source (version 1.8.1) following this guide:
http://kacianka.at/?p=145
I have 'gstreamer_build' folder at my home directory and it contains 'bin' folder with these:
gst-device-monitor-1.0
gst-discoverer-1.0 gst-inspect-1.0
gst-launch-1.0 gst-play-1.0
gst-stats-1.0 gst-typefind-1.0
orc-bugreport orcc
I have this path added to my environment variable PATH.
When I use cmake like:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D
CMAKE_INSTALL_PREFIX=/usr/local -D
OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_opencv_python3=ON -D WITH_GSTREAMER=ON -D WITH_FFMPEG=OFF
..
I get the following output clearly indicating that gstreamer is not found:
-- checking for module 'gstreamer-base-1.0'
-- package 'gstreamer-base-1.0' not found
-- checking for module 'gstreamer-video-1.0'
-- package 'gstreamer-video-1.0' not found
-- checking for module 'gstreamer-app-1.0'
-- package 'gstreamer-app-1.0' not found
-- checking for module 'gstreamer-riff-1.0'
-- package 'gstreamer-riff-1.0' not found
-- checking for module 'gstreamer-pbutils-1.0'
-- package 'gstreamer-pbutils-1.0' not found
-- checking for module 'gstreamer-base-0.10'
-- package 'gstreamer-base-0.10' not found
-- checking for module 'gstreamer-video-0.10'
-- package 'gstreamer-video-0.10' not found
-- checking for module 'gstreamer-app-0.10'
-- package 'gstreamer-app-0.10' not found
-- checking for module 'gstreamer-riff-0.10'
-- package 'gstreamer-riff-0.10' not found
-- checking for module 'gstreamer-pbutils-0.10'
-- package 'gstreamer-pbutils-0.10' not found
and this:
Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: NO
-- FFMPEG: NO
-- codec: NO
-- format: NO
-- util: NO
-- swscale: NO
-- resample: NO
-- gentoo-style: NO
-- GStreamer: NO
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- UniCap: NO
-- UniCap ucil: NO
-- V4L/V4L2: Using libv4l1 (ver 1.0.1) / libv4l2 (ver 1.0.1)
-- XIMEA: NO
-- Xine: NO
-- gPhoto2: NO
Can anyone help me with this?
I had the same problem.
gstreamer-base corresponds to libgstbase-1.0.so (or libgstbase-0.10.so), found in package libgstreamer1.0-0 (or libgstreamer0.10-0, as the case may be). Below, we install the '-dev' package.
The other libraries (libgst-video, libgst-app, libgst-riff, libgst-pbutils) I found in package libgstreamer-plugins-base1.0-dev (again, substitute the version you wish to use, either v0.1, or v1.0).
Therefore, the following command should be used to install the missing dependencies:
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
Repeat the cmake command, possibly purging the contents of the build directory beforehand.
The below worked for me if you are developing just a Gstreamer applicaiton
# GStreamer CMake building
cmake_minimum_required(VERSION 3.3)
project(GStreamerHello)
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
find_package(PkgConfig REQUIRED)
if ( NOT (PKGCONFIG_FOUND))
message(FATAL_ERROR "Please Install PPkgConfig: CMake will Exit")
endif()
pkg_check_modules(GST REQUIRED gstreamer-1.0>=1.8)
if ( NOT (GST_FOUND))
message(FATAL_ERROR "Please Install Gstreamer Dev: CMake will Exit")
endif()
set(ENV{PKG_CONFIG_PATH})
include_directories("${GST_INCLUDE_DIRS}")
link_libraries(${GST_LIBRARIES})
add_executable(gstreamerSrvc src/hello_gstreamer.cc)
add_dependencies(gstreamerSrvc vsphere_header )
target_link_libraries(gstreamerSrvc ${GST_LIBRARIES} )
Note - If you need a dev docker for GStreamer it is below; and for your question it has the parts of compiling with OpenCV as well;
More details at https://medium.com/techlogs/compiling-opencv-for-cuda-for-yolo-and-other-cnn-libraries-9ce427c00ff8
FROM nvidia/cuda
# This is a dev image, needed to compile OpenCV with CUDA
# Install Gstreamer and OpenCV Pre-requisite libs
RUN apt-get update -y && apt-get install -y \
libgstreamer1.0-0 \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
gstreamer1.0-doc \
gstreamer1.0-tools \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev
RUN apt-get update -y && apt-get install -y pkg-config \
zlib1g-dev libwebp-dev \
libtbb2 libtbb-dev \
libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev \
cmake
RUN apt-get install -y \
autoconf \
autotools-dev \
build-essential \
gcc \
git
ENV OPENCV_RELEASE_TAG 3.4.5
RUN git clone https://github.com/opencv/opencv.git /var/local/git/opencv
RUN cd /var/local/git/opencv && \
git checkout tags/${OPENCV_RELEASE_TAG}
RUN mkdir -p /var/local/git/opencv/build && \
cd /var/local/git/opencv/build $$ && \
cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_PNG=OFF -D \
BUILD_TIFF=OFF -D BUILD_TBB=OFF -D BUILD_JPEG=ON \
-D BUILD_JASPER=OFF -D BUILD_ZLIB=ON -D BUILD_EXAMPLES=OFF \
-D BUILD_opencv_java=OFF -D BUILD_opencv_python2=ON \
-D BUILD_opencv_python3=OFF -D ENABLE_NEON=OFF -D WITH_OPENCL=OFF \
-D WITH_OPENMP=OFF -D WITH_FFMPEG=OFF -D WITH_GSTREAMER=ON -D WITH_GSTREAMER_0_10=OFF \
-D WITH_CUDA=ON -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda/ -D WITH_GTK=ON \
-D WITH_VTK=OFF -D WITH_TBB=ON -D WITH_1394=OFF -D WITH_OPENEXR=OFF \
-D CUDA_ARCH_BIN=6.0 6.1 7.0 -D CUDA_ARCH_PTX="" -D INSTALL_C_EXAMPLES=OFF -D INSTALL_TESTS=OFF ..
RUN cd /var/local/git/opencv/build && \
make install
# Install other tools you need for development
On Windows there is no "sudo apt install..." I also had all the paths set right in my PATH environment variable, and still had the same problem. I've got this working after setting following CMake Options:
only set "WITH_GSTREAMER" option to True, "WITH_GSTREAMER_0_10" MUST BE FALSE
add new entry "GSTREAMER_DIR"=(path to gstreamer)
for me it was "C:/gstreamer/1.0/x86_64"
I found this solution here
My OpenCV version: 3.4.3
Adding new entry "GSTREAMER_DIR"=(path to gstreamer) worked for me (WITH_GSTREAMER true). Did not have a WITH_GSTREAMER_0_10 in my version.

Install OpenCV for python3

I have followed many manuals/tutorials how to install OpenCV, but all seem to work for my python2.7 instead of python3.4 where I want it. I'm following this tutorial but without using virtualenv. When making the
$cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D BUILD_EXAMPLES=ON \
-D PYTHON_EXECUTABLE=/usr/bin/python3.4 \
-D PYTHON_PACKAGES_PATHS=/usr/local/lib/python3.4/dist-packages/ \
-D PYTHON_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.4/dist-packages/numpy/core/include ..
comand it list both versions:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 3.4.3)
-- Libraries: NO
-- numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: NO
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python (for build): /usr/bin/python2.7
But omits the python_executable flag and uses the python2.7 for building (I checked it worked on python2.7 after continuing with the installation).
How can I make it that it uses python3.4 for the build?
Things I tried:
When running this cmake:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON_EXECUTABLE=$(which python3) ..
It list correctly the libraries:
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 3.4.3)
-- Libraries: NO
-- numpy: /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python (for build): /usr/bin/python2.7
But still list the python2.7 to build for.
Related info:
$whereis python3
python3: /usr/bin/python3.4dm-config /usr/bin/python3.4m /usr/bin/python3.4m-config /usr/bin/python3.4-config /usr/bin/python3 /usr/bin/python3.4-dbg-config /usr/bin/python3.4 /usr/bin/python3.4-dbg /usr/bin/python3.4dm /etc/python3 /etc/python3.4 /usr/lib/python3.0 /usr/lib/python3.5 /usr/lib/python3 /usr/lib/python3.4 /usr/lib/python3.2 /usr/lib/python3.1 /usr/lib/python3.3 /usr/bin/X11/python3.4dm-config /usr/bin/X11/python3.4m /usr/bin/X11/python3.4m-config /usr/bin/X11/python3.4-config /usr/bin/X11/python3 /usr/bin/X11/python3.4-dbg-config /usr/bin/X11/python3.4 /usr/bin/X11/python3.4-dbg /usr/bin/X11/python3.4dm /usr/local/lib/python3.4 /usr/include/python3.4m /usr/include/python3.4 /usr/include/python3.4dm /usr/share/python3 /usr/share/man/man1/python3.1.gz
I found the answer, after removing the CMakeCache.txt rm CMakeCache.txtI rerun the cmake command:
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D PYTHON_EXECUTABLE=/usr/bin/python3.4 \
-D BUILD_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-D INSTALL_PYTHON_EXAMPLES=ON ..
And the output was:
-- Python 2:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3.4 (ver 3.4.3)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)
-- numpy: /usr/local/lib/python3.4/dist-packages/numpy/core/include (ver 1.10.4)
-- packages path: lib/python3.4/dist-packages
--
-- Python (for build): /usr/bin/python3.4
--
So I keep with the instalation:
make -j4
sudo make install
sudo ldconfig

building opencv from trunk makes cv2.so, how to get cv.so?

Simplecv depends on cv.so, but when I build open opencv from trunk I only get cv2.so
I've not heard back from either opencv or Simplecv. Any here have an idea?
Ubuntu 12.10 64bit desktop, build args:
-D CMAKE_BUILD_TYPE=DEBUG \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D BUILD_PYTHON_SUPPORT=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_DOCS=ON
Thanks,
Kent

Resources