opencv c++安装踩坑记录 file cannot create directory: /usr/local/include/opencv2. Maybe need administrative privileges
前言
最近深度学习Ultra-Fast-Lane-Detection/INSTALL.md at master · cfzd/Ultra-Fast-Lane-Detection (github.com)需要安装opencv c++
,于是准备安装。于是按照OpenCV: Installation in Linux官网一顿操作,好像是成功了。但是在安装成功,进行软链接的时候
# First you need to install OpenCV C++.
# After installation, make a soft link of OpenCV include path.
ln -s /usr/local/include/opencv4/opencv2 /usr/local/include/opencv2
失败,提示已经存在文件夹,不会解决。于是删除opencv编译过程中的文件,尝试第二种方式,还是失败。于是百度去安装了。
安装过程
来源:Ubuntu18.04下opencv的安装及应用_风吹麦甜的博客-CSDN博客_ubuntu18.04安装opencv
额外的问题:
-
在
sudo make install
提示:root@yf407:/home/swx/Desktop/opencv-3.4.14/build# sudo make install [ 0%] Built target gen-pkgconfig [ 4%] Built target libtiff [ 13%] Built target libwebp [ 16%] Built target libjasper [ 24%] Built target IlmImf [ 30%] Built target libprotobuf [ 31%] Built target quirc [ 31%] Built target ittnotify [ 39%] Built target opencv_core [ 46%] Built target opencv_imgproc [ 47%] Built target opencv_imgcodecs [ 48%] Built target opencv_videoio [ 49%] Built target opencv_highgui [ 50%] Built target opencv_ts [ 53%] Built target opencv_test_core [ 55%] Built target opencv_perf_core [ 55%] Built target opencv_flann [ 55%] Built target opencv_test_flann [ 59%] Built target opencv_perf_imgproc [ 63%] Built target opencv_test_imgproc [ 64%] Built target opencv_ml [ 65%] Built target opencv_test_ml [ 67%] Built target opencv_photo [ 68%] Built target opencv_test_photo [ 68%] Built target opencv_perf_photo [ 69%] Built target opencv_video [ 70%] Built target opencv_perf_video [ 71%] Built target opencv_test_video [ 77%] Built target opencv_dnn [ 78%] Built target opencv_perf_dnn [ 79%] Built target opencv_test_dnn [ 81%] Built target opencv_features2d [ 81%] Built target opencv_perf_features2d [ 83%] Built target opencv_test_features2d [ 83%] Built target opencv_perf_imgcodecs [ 84%] Built target opencv_test_imgcodecs [ 84%] Built target opencv_shape [ 84%] Built target opencv_test_shape [ 84%] Built target opencv_test_videoio [ 84%] Built target opencv_perf_videoio [ 86%] Built target opencv_calib3d [ 87%] Built target opencv_perf_calib3d [ 90%] Built target opencv_test_calib3d [ 90%] Built target opencv_test_highgui [ 91%] Built target opencv_objdetect [ 92%] Built target opencv_test_objdetect [ 92%] Built target opencv_perf_objdetect [ 93%] Built target opencv_stitching [ 93%] Built target opencv_test_stitching [ 94%] Built target opencv_perf_stitching [ 95%] Built target opencv_superres [ 96%] Built target opencv_test_superres [ 96%] Built target opencv_perf_superres [ 97%] Built target opencv_videostab [ 97%] Built target opencv_test_videostab [ 98%] Built target opencv_traincascade [ 99%] Built target opencv_createsamples [ 99%] Built target opencv_annotation [ 99%] Built target opencv_visualisation [100%] Built target opencv_interactive-calibration [100%] Built target opencv_version Install the project... -- Install configuration: "Release" -- Up-to-date: /usr/local/share/licenses/opencv3/opencl-headers-LICENSE.txt CMake Error at cmake_install.cmake:45 (file): file cannot create directory: /usr/local/include/opencv2. Maybe need administrative privileges. Makefile:61: recipe for target 'install' failed make: *** [install] Error 1
提示没有权限,百度之后是加
sudo
,但是已经是root用户了,而且已经sudo了,行不通。那就自己解决:-
手动创建
/usr/local/include/opencv2.
,还是如此提示。 -
进入
/usr/local/include/
,看到了一个文件opencv2
,目前2022年6月1日,因此这就是前几天创建的,很奇怪,于是索性删掉,神奇的事情发生了,再次执行命令就成功了。之后软链接也成功了!!!个人猜测应该是最开始安装opencv 4.x失败导致产生的遗留文件产生的这个问题。(python3.7) swx@yf407:/usr/local/include$ ll total 176 drwxr-xr-x 2 root root 4096 Jun 1 09:58 ./ drwxr-xr-x 14 root root 4096 Apr 14 18:58 ../ -rw-r--r-- 1 root root 5777 Dec 27 2007 lauxlib.h -rw-r--r-- 1 root root 22299 Feb 12 2008 luaconf.h -rw-r--r-- 1 root root 11688 Jan 14 2012 lua.h -rw-r--r-- 1 root root 191 Dec 23 2004 lua.hpp -rw-r--r-- 1 root root 1026 Dec 27 2007 lualib.h -rw-r--r-- 1 root root 1292 Mar 3 10:56 ms-erref.h -rw-r--r-- 1 root root 1952 Mar 3 10:56 ms-fscc.h -rw-r--r-- 1 root root 23075 Mar 3 10:56 ms-rdpbcgr.h -rw-r--r-- 1 root root 3413 Mar 3 10:56 ms-rdpeclip.h -rw-r--r-- 1 root root 1018 Mar 3 10:56 ms-rdpedisp.h -rw-r--r-- 1 root root 4620 Mar 3 10:56 ms-rdpefs.h -rw-r--r-- 1 root root 2174 Mar 3 10:56 ms-rdpegdi.h -rw-r--r-- 1 root root 1400 Mar 3 10:56 ms-rdpele.h -rw-r--r-- 1 root root 1029 Mar 3 10:56 ms-rdperp.h -rw-r--r-- 1 root root 2835 Mar 3 10:56 ms-smb2.h lrwxrwxrwx 1 root root 34 May 27 09:07 opencv2 -> /usr/local/include/opencv4/opencv2 -rw-r--r-- 1 root root 4020 Mar 3 10:56 painter.h -rw-r--r-- 1 root root 1218 Mar 3 10:56 rfxcodec_common.h -rw-r--r-- 1 root root 1028 Mar 3 10:56 rfxcodec_decode.h -rw-r--r-- 1 root root 4158 Mar 3 10:56 rfxcodec_encode.h -rw-r--r-- 1 root root 5400 Mar 3 10:56 xrdp_client_info.h -rw-r--r-- 1 root root 9108 Mar 3 10:56 xrdp_constants.h -rw-r--r-- 1 root root 4684 Mar 3 10:56 xrdp_rail.h -rw-r--r-- 1 root root 1638 Mar 3 10:56 xrdp_sockets.h
-