macOS Monterey --> fatal error: 'opencv2/videoio.hpp' file not found - c++

I am trying to build opencv on macOS for a CPP capstone project but when I try to compile like so:
cmake -D CMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -D BUILD_opencv_objdetect=OFF -D BUILD_opencv_video=OFF -D BUILD_opencv_videoio=OFF -D BUILD_opencv_features2d=OFF -D BUILD_opencv_flann=OFF -D BUILD_opencv_highgui=OFF -D BUILD_opencv_ml=OFF -D BUILD_opencv_photo=OFF -D BUILD_opencv_python=OFF -D BUILD_opencv_shape=OFF -D BUILD_opencv_stitching=OFF -D BUILD_opencv_superres=OFF -D BUILD_opencv_ts=OFF -D BUILD_opencv_videostab=OFF ..
make -j8
I am getting the following error:
[ 98%] Built target opencv_model_diagnostics
make[2]: *** No rule to make target `zlib', needed by `lib/python3/cv2.cpython-39-darwin.so'. Stop.
make[2]: *** Waiting for unfinished jobs....
[ 98%] Building CXX object modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o
In file included from /Users/username/Projects/opencv/opencv/modules/python/src2/cv2.cpp:11:
In file included from /Users/username/Projects/opencv/opencv/build/modules/python_bindings_generator/pyopencv_generated_include.h:50:
/Users/username/Projects/opencv/opencv/modules/gapi/include/opencv2/gapi/streaming/cap.hpp:26:10: fatal error: 'opencv2/videoio.hpp' file not found
#include "opencv2/videoio.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make: *** [all] Error 2
I did follow at first the instruction from opencv but make step fails at:
[ 36%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/int8layers/layers_common.avx512_skx.cpp.o
[ 36%] Linking CXX shared library ../../lib/libopencv_dnn.dylib
[ 36%] Built target opencv_dnn
make: *** [all] Error 2
Any help is highly appreciated.

Related

Compiling OpenCV errors

I trying to install opencv on my raspberry pi 3b+. Iam basing on tutorial from pyimagesearch.Iam on Step #5: Compile and Install OpenCV. I got errors after I execute make command. On 15% I got errors like on the screen.
Errors:
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/fully_connected_layer.cpp.o
/home/pi/opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp: In member function ‘bool OutputMediaStream_FFMPEG::open(const char*, int, int, double)’:
/home/pi/opencv-3.1.0/modules/videoio/src/cap_ffmpeg_impl.hpp:2207:30: warning: ignoring return value of ‘int avformat_write_header(AVFormatContext*, AVDictionary**)’, declared with attribute warn_unused_result [-Wunused-result]
avformat_write_header(oc_, NULL);
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:154: modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:4209: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/im2col.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/layers_common.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/lrn_layer.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/mvn_layer.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/pooling_layer.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/reshape_layer.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/slice_layer.cpp.o
[ 22%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/softmax_layer.cpp.o
[ 23%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/layers/split_layer.cpp.o
[ 23%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THDiskFile.cpp.o
[ 23%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THFile.cpp.o
[ 23%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/THGeneral.cpp.o
[ 23%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/src/torch/torch_importer.cpp.o
[ 23%] Building CXX object modules/dnn/CMakeFiles/opencv_dnn.dir/opencl_kernels_dnn.cpp.o
[ 23%] Linking CXX shared library ../../lib/libopencv_dnn.so
[ 23%] Built target opencv_dnn
make: *** [Makefile:163: all] Error 2
When my cmake looks like:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules \
-D ENABLE_PRECOMPILED_HEADERS=OFF \
-D WITH_TBB=OFF \
-D BUILD_EXAMPLES=ON ..
I got errors like:
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/build.make:154: modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_ffmpeg.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:4209: modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
I will be greateful for any advice.
Okey, I handled the problem. My solution was to install brand new Raspberry Pi Buster image on sd card. Then I installed opencv basing on another tutorial from pyimagesearch.

how to build kate with cmake?

Dear stackoverflow users,
I'm trying to compile kate from source but I'm getting an error with a not declared variable.
So far these are the commands I'm using:
#! /bin/bash
cmake \
-D CMAKE_BUILD_TYPE=RelWithDebInfo \
-D CMAKE_INSTALL_PREFIX=~/kde/usr \
-D KDE_INSTALL_USE_QT_SYS_PATHS:BOOL=ON \
-D TARGET_include_directories:PATH="/usr/include/x86_64-linux-gnu/qt5/" \
-D Qt5_INCLUDE_DIRS:PATH="/usr/include/x86_64-linux-gnu/qt5/" \
-D Qt5_LIBRARY_DIRS:PATH="/usr/lib/x86_64-linux-gnu/qt5/" \
../kate/
make
make install
Please find below the error during compiling: I think it has to be related with not including some path file that should be there which declares the variable QWidgetAction, however I'm not sure why, since I installed all required packages as per the website.
(qtbase5-dev qtscript5-dev extra-cmake-modules plasma-framework-dev libkf5crash-dev libkf5config-dev libkf5activities-dev kinit-dev kdoctools-dev libkf5i18n-dev libkf5parts-dev libkf5guiaddons-dev libkf5iconthemes-dev libkf5jobwidgets-dev kio-dev libkf5texteditor-dev libkf5windowsystem-dev libkf5xmlgui-dev libgit2-dev).
The reason I'm compiling it is because I messed up with my original installed kate and I just can't load back all plugins, since my /.config kate folder is gone. Please any help is appreciated.
[ 69%] Automatic moc for target katecloseexceptplugin [ 69%] Built
target katecloseexceptplugin_automoc [ 71%] Built target
katecloseexceptplugin [ 71%] Automatic moc for target
katesqlplugin [ 71%] Built target katesqlplugin_automoc [
71%] Building CXX object addons/katesql/CMakeFiles/katesqlplugin.dir
/katesqlview.cpp.o
/home/pablo/kde/kate/addons/katesql/katesqlview.cpp: In member
function ‘void KateSQLView::setupActions()’:
/home/pablo/kde/kate/addons/katesql/katesqlview.cpp:141:3: error:
‘QWidgetAction’ was not declared in this scope QWidgetAction
*wa = new QWidgetAction(this); ^ /home/pablo/kde/kate/addons/katesql/katesqlview.cpp:141:18: error:
‘wa’ was not declared in this scope QWidgetAction *wa =
new QWidgetAction(this);
^ /home/pablo/kde/kate/addons/katesql/katesqlview.cpp:141:27: error:
expected type-specifier before ‘QWidgetAction’
QWidgetAction wa = new QWidgetAction(this);
^ addons/katesql/CMakeFiles/katesqlplugin.dir/build.make:96: recipe for
target
'addons/katesql/CMakeFiles/katesqlplugin.dir/katesqlview.cpp.o' failed
make[2]:
[addons/katesql/CMakeFiles/katesqlplugin.dir/katesqlview.cpp.o]
Error 1 CMakeFiles/Makefile2:2439: recipe for target
'addons/katesql/CMakeFiles /katesqlplugin.dir/all' failed
make[1]: * [addons/katesql/CMakeFiles/katesqlplugin.dir/all] Error 2
Makefile:138: recipe for target 'all' failed make: *** [all]
Error 2
QWidgetAction is a part of Qt. Have you got the Qt libraries and headers properly in your path?
Header: #include

OpenCV linking error

The same error first occured in the middle of the build when linking another shared library. Then I've added BUILD_SHARED_LIBS=OFF so now it occurs at the very end only. The last two options were also added in hope of fixing it. Using LinuxMint 17.
[ 99%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/deblurring.cpp.o
[ 99%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/motion_stabilizing.cpp.o
Linking CXX static library ../../lib/libopencv_videostab.a
[ 99%] Built target opencv_videostab
[ 99%] Generating pyopencv_generated_include.h, pyopencv_generated_funcs.h, pyopencv_generated_types.h, pyopencv_generated_type_reg.h, pyopencv_generated_ns_reg.h
Scanning dependencies of target opencv_python2
[ 99%] Building CXX object modules/python2/CMakeFiles/opencv_python2.dir/__/src2/cv2.cpp.o
Linking CXX shared module ../../lib/cv2.so
/usr/bin/ld: //usr/local/lib/libavformat.a(allformats.o): relocation R_X86_64_32 against `ff_a64_muxer' can not be used when making a shared object; recompile with -fPIC
//usr/local/lib/libavformat.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/cv2.so] Error 1
make[1]: *** [modules/python2/CMakeFiles/opencv_python2.dir/all] Error 2
make: *** [all] Error 2
Command:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=/home/serj/work/beautytorch/venv/bin/python \
-D BUILD_EXAMPLES=OFF \
-D BUILD_SHARED_LIBS=OFF \
-D CMAKE_CXX_FLAGS=-fPIC \
-D WITH_IPP=OFF \
..
It is ffmpeg which should have been compiled with -fPIC. enter link description here I had ffmpeg compiled from sources. After deinstallation, opencv links fine.

No rule to make target 'TBB_ENV_LIB_DEBUG-NOTFOUND', needed by 'lib/libopencv_core.so.3.2.0

I'm trying to build opencv with the following CMAKE options:
cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/home/luca/Dropbox/SURFSPM/opencvInstall -D OPENCV_EXTRA_MODULES_PATH=/home/luca/ParallelOpenCV/opencv_contrib/modules -D WITH_TBB=ON -D WITH_OPENMP=ON -D ENABLE_PROFILING=ON ..
Notice that in RELEASE mode OpenCV is correctly compiled with all the other options. However, at 43% it returns this error:
[ 42%] Built target pch_Generate_opencv_perf_optflow
[ 42%] Built target pch_Generate_opencv_test_optflow
[ 43%] Generating precomp.hpp.gch/opencv_structured_light_DEBUG.gch
Scanning dependencies of target opencv_core
[ 43%] Built target pch_Generate_opencv_test_phase_unwrapping
make[2]: *** No rule to make target 'TBB_ENV_LIB_DEBUG-NOTFOUND', needed by 'lib/libopencv_core.so.3.2.0'. Stop.
make[2]: *** Waiting for unfinished jobs....
[ 43%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o
cc1plus: warning: /home/luca/ParallelOpenCV/opencv/build/modules/core/precomp.hpp.gch/opencv_core_Release.gch: created with -gnone, but used with -gdwarf-2
[ 43%] Built target pch_Generate_opencv_test_stitching
[ 43%] Built target pch_Generate_opencv_phase_unwrapping
[ 43%] Built target pch_Generate_opencv_test_structured_light
[ 43%] Built target pch_Generate_opencv_perf_stitching
[ 43%] Built target pch_Generate_opencv_stitching
[ 43%] Built target pch_Generate_opencv_structured_light
CMakeFiles/Makefile2:2161: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2
I think that this is Intel TBB related, but I've installed it (in fact it works with the RELEASE version and I don't know how to solve this.
Like #Tsyvarev's comment hints, indeed the configuration phase fails to pickup a debug library version.
I've gotten success setting the original setting:
TBB_ENV_LIB_DEBUG:FILEPATH=TBB_ENV_LIB_DEBUG-NOTFOUND
To the same value as TBB_ENV_LIB:FILEPATH
//Path to a library.
TBB_ENV_LIB:FILEPATH=/usr/lib/x86_64-linux-gnu/libtbb.so
//Path to a library.
TBB_ENV_LIB_DEBUG:FILEPATH=/usr/lib/x86_64-linux-gnu/libtbb.so

building opencv fail on Qiana

I encountered the problem during compiling OpenCV. Error message said that I don't have Eigen. However, I do have one in my /usr/local/include directory. Also, I ran CMake with option below.
CMake:
cmake -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 CUDA_GENERATION=Auto USE_EIGEN=/usr/local/include/Eigen ..
Compiling OpenCV(by make):
[ 75%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.o
/home/gom7745/IR/opencv-2.4.11/modules/contrib/src/rgbdodometry.cpp:65:47: fatal error: unsupported/Eigen/MatrixFunctions: No such file or directory
# include <unsupported/Eigen/MatrixFunctions>
^
compilation terminated.
make[2]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.o] Error 1
make[1]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/all] Error 2
make: *** [all] Error 2
Does anyone have any idea about this? Thanks!!
Building it with -DWITH_EIGEN=OFF solved the issue for me.
here cmake is unable to find unsupported/Eigen/MatrixFunctions. First find where Eigen is installed, in my case it was located at /usr/local/include/eigen3. Now locate your rgbdodometry.cpp file, in my case it was in /opencv_contrib/modules/rgbd/src. Open the cpp file and modify the previous line with something like
"/usr/local/include/eigen3/unsupported/Eigen/MatrixFunctions"