??openCV 下載安裝
??基礎(chǔ)環(huán)境
- 操作系統(tǒng):Ubuntu 18.04.5
- 編程工具:bash shell
- VScode
- 基礎(chǔ)的 gcc、G++ 安裝
??下載一個(gè)喜歡的版本即可
??極簡(jiǎn)【無(wú)腦】安裝
# 解壓到服務(wù)器目錄
unzip opencv-4.5.3
cd opencv-4.5.3/
# 開始安裝之旅
mkdir build
cd build/
# root 用戶直接運(yùn)行临梗,會(huì)默認(rèn)編譯安裝到/usr/local 目錄下
cmake ..
make -j16
make install
# 普通用戶扛禽,沒(méi)有 /usr/local 寫入權(quán)限闸英,需要 指定安裝路徑
make install DESTDIR=/home/Moli/usr/local
??openCV 讀取保存圖像【極簡(jiǎn)示例】
程序只包含 | example.cpp 和 CMakeLists.txt 即可
??example.cpp
#include "opencv2/core.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/videoio.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
cout << "Built with OpenCV " << CV_VERSION << endl;
Mat src = cv::imread("../conda.png");
// cv::imshow("src", src);
// waitKey(0);
// 圖像縮放
int width{256}, height{256};
cv::resize(src, src, cv::Size(width, height));
cv::imwrite("256src.png", src);
return 0;
}
??CMakeLists.txt
配置 OpenCV_DIR 路徑【openCV build 目錄即可】
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Define project name
project(first_墨理_project)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
set(OpenCV_DIR /home/墨理/project/project21Next/vscodeFirst/opencv-4.5.3/build)
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(first example.cpp)
# Link your application with OpenCV libraries
target_link_libraries(first PRIVATE ${OpenCV_LIBS})
??Linux 下編譯運(yùn)行
命令如下
mkdir build
cd build/
cmake ..
make
# 生成得到可執(zhí)行文件 first | 運(yùn)行即可
./first
查看生成的縮放圖片【沒(méi)看錯(cuò)席函,是在下】
博主簡(jiǎn)介:軟件工程碩士滩援、已畢業(yè)、馬上 10w 讀者 粉絲
- ?? 計(jì)算機(jī)視覺:超分重建、圖像修復(fù)独榴、目標(biāo)檢測(cè)、風(fēng)格遷移 等領(lǐng)域 稍有所學(xué)
- ?? AI 工程化:Ncnn奕枝、MNN棺榔、TensorRT 正在 學(xué)習(xí)
- ?? C++、Python隘道、Java 略懂一二
喜歡請(qǐng)關(guān)注 墨理學(xué)AI
取經(jīng)路上症歇,讓墨理學(xué)AI 陪你暢享更多有趣AI