openCV安装、最基础的openCV程序运行示例【linux】


💙openCV 下载安装


❤️基础环境
❤️下载一个喜欢的版本即可

1-0

❤️极简【无脑】安装

# 解压到服务器目录
unzip opencv-4.5.3

cd opencv-4.5.3/

# 开始安装之旅

mkdir build
cd build/

# root 用户直接运行,会默认编译安装到/usr/local 目录下
cmake ..
make -j16
make install

# 普通用户,没有 /usr/local 写入权限,需要 指定安装路径

make install DESTDIR=/home/Moli/usr/local 


💙openCV 读取保存图像【极简示例】


程序只包含 | 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 下编译运行


命令如下

mkdir build

cd  build/

cmake ..
make

# 生成得到可执行文件 first | 运行即可 

./first 

查看生成的缩放图片【没看错,是在下】

9-8


🚀 VSCode 远程运行该项目示例效果如下


如何使用 VSCode 远程调试 – 运行项目 ,可参考我的这篇博文


VSCode远程连接Linux服务器进行开发调试

5-0


🚀🚀 OpenCV 学习系列博文推荐


🍖安装
🍖openCV Python 系列方法测试运行

9-9
9-8


  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

墨理学AI

不必打赏,关注博主公众号即可

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值