sudo apt install -y g++ make wget unzip
sudo apt install -y libssl-dev build-essential
sudo apt install -y pkg-config
CMake安裝
方法一(源碼安裝)下載地址:https://cmake.org/download/
進(jìn)入cmake目錄cd cmake-***
執(zhí)行:
./bootstrap
編譯構(gòu)造:
make
安裝:
sudo make install
檢查:
1.查看cmake版本:cmake --version
2.查看cmake位置:which cmake
sudo apt-get install -y cmake
下載OpenCV-4.6.0官網(wǎng)鏈接
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff5.dev libswscale-dev libjasper-dev
可能遇到的問(wèn)題下載依賴報(bào)錯(cuò),鏡像源問(wèn)題。
下列軟件包有未滿足的依賴關(guān)系:
libc6-dev : 依賴: libc6 (= 2.27-3ubuntu1.6) 但是 2.35-0ubuntu3 正要被安裝
依賴: libc-dev-bin (= 2.27-3ubuntu1.6)
參考博客:最新ubuntu22.04 下列軟件包有未滿足的依賴關(guān)系 解決方案
1.sudo gedit /etc/apt/sources.list
2.將如下內(nèi)容復(fù)制進(jìn)去:
#阿里源
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
3.更新鏡像源
sudo apt-get update
sudo apt-get upgrade
4.重復(fù)安裝嘗試
編譯安裝OpenCVbuild
目錄cd opencv-4.6.0
mkdir -p build
cd build
cmake
命令:cmake -DCMAKE_BUILD_TYPE=Release \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local ..
sudo make -j 4
使用4個(gè)線程進(jìn)行編譯,可以一定程度上加快編譯速度
sudo make install
環(huán)境配置參考博客
sudo gedit /etc/ld.so.conf.d/opencv.conf
/usr/local/lib
sudo ldconfig
sudo gedit /etc/bash.bashrc
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc
opencv4.pc文件的默認(rèn)路徑:/usr/local/lib/pkgconfig/opencv4.pc
.若此目錄下沒(méi)有,可以使用以下命令搜索sudo find / -iname opencv4.pc
執(zhí)行:sudo gedit /etc/profile.d/pkgconfig.sh
可能為空文件,在文件中加入PKG_CONFIG_PATH
下面一行代碼
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
保存并退出,source激活:source /etc/profile
pkg-config --modversion opencv4
如下圖,安裝成功:
新建文件夾digital
創(chuàng)建文件:
touch CMakeLists.txt
mkdir -p build
mkdir -p img
mkdir -p src
源碼放在src目錄下
#include#include#includeusing namespace std;
using namespace cv;
Mat src;
int main(int argc, char ** argv)
{
src = imread("/home/luffy/digital/img/luffy14.jpg");//這里是你的圖片
if (src.empty())
{
cout<< "沒(méi)有讀取到圖像"<< endl;
return -1;
}
imshow("hello", src);
waitKey(0);
return 0;
}
編寫(xiě)CMakeLists.txt文件供參考:
cmake_minimum_required(VERSION 2.8)
project( digital )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( demo src/demo.cpp )
add_executable( dctimg src/dctimg.cpp )
add_executable( rgbdctimg src/rgbdctimg.cpp )
target_link_libraries( demo ${OpenCV_LIBS} )
target_link_libraries( dctimg ${OpenCV_LIBS} )
target_link_libraries( rgbdctimg ${OpenCV_LIBS} )
編譯運(yùn)行cd build
cmake ..
make
./demo # 執(zhí)行
Over
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧