????????OpenCV是一个跨平台的计算机视觉和机器学习软件库,基于Apache2.0许可(开源)发行。它可以在Linux、Windows、Android和Mac OS操作系统上运行。OpenCV由一系列C函数和少量C++类构成,同时提供了Python、Ruby、MATLAB等语言的接口。这个库实现了图像处理和计算机视觉方面的很多通用算法,主要倾向于实时视觉应用。OpenCV也提供对于C#、Ch、Ruby,GO的支持。
????????OpenCV可用于开发实时的图像处理、计算机视觉以及模式识别程序,该程序库也可以使用英特尔公司的IPP进行加速处理。OpenCV-Python是OpenCV的Python API,结合了OpenCV C++API和Python语言的最佳特性。所有OpenCV数组结构都转换为Numpy数组。
sudo apt update
sudo apt install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev libv4l-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran
????????现在zip文件:opencv-4.8.1
unzip??opencv-4.8.1.zip
cd opencv-4.8.1
mkdir build
cd build
cmake ..?
make -j8
sudo make install
(1) sudo gedit /etc/ld.so.conf
(2)添加内容
????????include /etc/ld.so.conf.d/*.conf
????????include /usr/local/lib(3)sudo ldconfig
?????install后使用pkg-config --modversion opencv4查看版本,提示缺少opencv4.pc这个配置信息文件
?sudo vim /usr/local/lib/pkgconfig/opencv4.pc
拷贝下面的内容,版本号修改成安装的版本号
prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/libName: opencv
Description: The opencv library
Version:4.8.1
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
sudo gedit /etc/bash.bashrc
????????末尾添加
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
source /etc/bash.bashrc
pkg-config --modversion opencv4
cmake_minimum_required(VERSION 3.10)
project(opencv_test)
# 检查OpenCV库
find_package(OpenCV REQUIRED)
# 打印opencv库的相关信息
if(OpenCV_FOUND)
message(STATUS "OpenCV library status:")
message(STATUS "version: ${OpenCV_VERSION}")
message(STATUS "include path: ${OpenCV_INCLUDE_DIRS}")
else()
message(FATAL_ERROR "OpenCV library not found")
endif()
# 添加头文件
include_directories(${OpenCV_INCLUDE_DIRS})
# 链接库
link_libraries(${OpenCV_LIBS})
add_executable(opencv_test gray_test.cpp)
// 图片的读取和显示
// 导入opencv头文件
#include "opencv2/opencv.hpp"
#include <iostream>
int main(int argc, char** argv)
{
// 读取图片,mat是matrix的缩写,是一个矩阵,类似与numpy ndarray
cv::Mat image = cv::imread("./cat.jpg");
// 判断是否读取成功
if (image.empty())
{
std::cout << "无法读取图片 " << std::endl;
return 1;
}
// 打印图片高度和宽度
std::cout << "图片高度: " << image.rows << " 宽度: " << image.cols << std::endl;
// 打印图片data
// 以Numpy的方式打印
// std::cout << "图片data: " << cv::format(image, cv::Formatter::FMT_NUMPY) << std::endl;
// 以python list的方式打印
// std::cout << "图片data: " << cv::format(image, cv::Formatter::FMT_PYTHON) << std::endl;
// 创建一个灰度图
cv::Mat gray;
// 转换为灰度图
cv::cvtColor(image, gray, cv::COLOR_BGR2GRAY);
// 保存
cv::imwrite("./gray.jpg", gray);
return 0;
}
(1)cmake -S . -B build
????????可以看到opencv的版本是4.8.1
(2)cmake --build build
????????编译好的可执行文件在build目录下:opencv_test
(3)mv ./build/opencv_test ./
(4)./opencv_test
?????????到此,RK3588安装新版的Opencv和C++调用opencv就完成了,之前是熟悉python,现在C++版本的内容慢点开始学习吧。