个人备案做视频网站,wordpress连接数据库出错,网站制作系统,网络整合营销1. 安装依赖
opencv中的一些图像、视频相关的功能需要一些依赖#xff0c;因此在安装opencv之前需要先安装这些依赖#xff1b;在使用apt安装相关依赖时#xff0c;会出现无法安装的情况#xff0c;这时可以用aptitude来降级安装。
名称apt package 名称功能编译系统buil…1. 安装依赖
opencv中的一些图像、视频相关的功能需要一些依赖因此在安装opencv之前需要先安装这些依赖在使用apt安装相关依赖时会出现无法安装的情况这时可以用aptitude来降级安装。
名称apt package 名称功能编译系统build-essential cmake pkg-config生成 OpenCV图像库libpng-dev libjpeg-dev提供各类图像格式的编解码OpenBLASlibopenblas-dev利用 CPU 向量运算指令为大量算法提供加速。Eigen3libeigen3-dev提供线性代数相关算法支持Intel TBBlibtbb-dev在 Intel CPU 上提供高性能并发计算支持FFMPEGlibavcodec-dev libavformat-dev libswscale-dev提供视频编解码能力GStreamerlibgstreamer-plugins-base1.0-dev libgstreamer1.0-dev提供流媒体处理能力GTKlibgtk-3-dev libcanberra-gtk-module libcanberra-gtk3-module图形化用户界面
2. 安装opencv
2.1 从源码安装
参考在 Linux 系统中编译安装 OpenCV - 知乎
2.2 直接安装
参考 OpenCV 的最简安装方式Linux - 知乎
3. 验证
新建一个文件命名为test.cc:
#include iostream
#include opencv2/opencv.hpp
#include opencv2/imgproc.hpp
#include opencv2/highgui.hppint main(int argc, char **argv)
{auto img_path argv[1];cv::Mat img cv::imread(img_path);if(img.empty()){std::cout----------image read error!--------------std::endl;return 0;}cv::Scalar color;color[0]0;color[1]0;color[2]255;// 红色cv::Rect rec1;rec1cv::Rect(10,10,500,500);cv::rectangle(img, rec1,color,100,-1,0);cv::imwrite(result.jpg, img);cv::namedWindow(image, cv::WINDOW_NORMAL);cv::imshow(image, img);cv::waitKey(0);// std::countimg.empty()std::endl;std::coutdone!std::endl;return 0;
}编写CMakeLists.txt
# cmake needs this line
cmake_minimum_required(VERSION 3.1)# Define project name
project(opencv_example_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
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(opencv_example test_cv.cc)# Link your application with OpenCV libraries
target_link_libraries(opencv_example PRIVATE ${OpenCV_LIBS})
在同级目录下新建build文件夹并进入编译运行
cd build
cmake ..
make -j8
./opencv_example
如果没有报错则说明安装成功。
若有报错大部分情况都是因为缺少相应依赖通过第1步中的方法安装即可。