pkg-config --modversion opencvPackage opencv was not found in the pkg-config search path.Perhaps y

此方法针对使用源码安装了opencv,出现No package 'opencv' found的小伙伴

 pkg-config --cflags --libs opencv
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
nvidia@nvidia-desktop:/usr/local/lib$ sudo mkdir pkgconfig
[sudo] password for nvidia:
nvidia@nvidia-desktop:/usr/local/lib$ cd pkgconfig
nvidia@nvidia-desktop:/usr/local/lib/pkgconfig$ sudo touch opencv.pc
nvidia@nvidia-desktop:/usr/local/lib/pkgconfig$ vi opencv.pc
nvidia@nvidia-desktop:/usr/local/lib/pkgconfig$ sudo vi opencv.pc
nvidia@nvidia-desktop:/usr/local/lib/pkgconfig$ export  PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
nvidia@nvidia-desktop:/usr/local/lib/pkgconfig$  pkg-config --cflags --libs opencv
-I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core
opencv.pc内容如下

prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: opencv
Description: The opencv library
Version:4.1.0
Cflags: -I${includedir}/opencv4
Libs: -L${libdir} -lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann  -lopencv_core
~

nvidia@nvidia-desktop:~/Nano/OpenCV4.1/opencv-4.1.0/samples/cpp/example_cmake/build$ sudo cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Found CUDA: /usr/local/cuda (found suitable exact version "10.2")
-- Found OpenCV: /usr/local (found version "4.1.0")
-- OpenCV library status:
--     config: /usr/local/lib/cmake/opencv4
--     version: 4.1.0
--     libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_cudaarithm;opencv_cudabgsegm;opencv_cudacodec;opencv_cudafeatures2d;opencv_cudafilters;opencv_cudaimgproc;opencv_cudalegacy;opencv_cudaobjdetect;opencv_cudaoptflow;opencv_cudastereo;opencv_cudawarping;opencv_cudev;opencv_datasets;opencv_dnn_objdetect;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hfs;opencv_img_hash;opencv_line_descriptor;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
--     include path: /usr/local/include/opencv4
-- Configuring done
-- Generating done
-- Build files have been written to: /home/nvidia/Nano/OpenCV4.1/opencv-4.1.0/samples/cpp/example_cmake/build
nvidia@nvidia-desktop:~/Nano/OpenCV4.1/opencv-4.1.0/samples/cpp/example_cmake/build$ sudo make
Scanning dependencies of target opencv_example
[ 50%] Building CXX object CMakeFiles/opencv_example.dir/example.cpp.o
[100%] Linking CXX executable opencv_example
[100%] Built target opencv_example
nvidia@nvidia-desktop:~/Nano/OpenCV4.1/opencv-4.1.0/samples/cpp/example_cmake/build$ ls
CMakeCache.txt  CMakeFiles  cmake_install.cmake  Makefile  opencv_example
nvidia@nvidia-desktop:~/Nano/OpenCV4.1/opencv-4.1.0/samples/cpp/example_cmake/build$ ./opencv_example
Built with OpenCV 4.1.0
VIDEOIO ERROR: V4L: can't open camera by index 0
No capture

你可能感兴趣的:(nvidia,jetson_nx,opencv,计算机视觉,人工智能)