0
点赞
收藏
分享

微信扫一扫

【第2章 Node.js基础】2.7 Node.js 的流(一) 可读流

皮皮球场 2023-11-18 阅读 28

Linux安装OpenCV并配置VSCode环境


安装OpenCV环境

安装必需工具

# cmake	  ->   构建工具
# g++	  ->   c++编译器
# unzip	  ->   zip文件解压工具
# libgtk2.0-dev pkg-config是图形界面支持的工具,不安装执行程序时会报错
sudo apt update && sudo apt install -y cmake g++ libgtk2.0-dev pkg-config wget unzip

下载并解压OpenCV库(Opencv Core Modules和opencv_contrib)

# 进入到安装目录,创建opencv父目录
cd ~	# 安装目录自选,如进入到根目录下的子目录,后面的命令前均需要添加sudo
mkdir opencv && cd opencv
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.x.zip
unzip opencv.zip
unzip opencv_contrib.zip
# 删除安装包
sudo rm -rf opencv*.zip

创建构建目录,进行构建

# 在opencv目录下创建build文件
mkdir -p build && cd build
# 配置构建的 opencv-4.x 和 opencv_contrib-4.x 项目的路径,
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.x/modules ../opencv-4.x
# 构建当前目录下的CMake项目,--build 指定编译生成的文件存放目录,其中就包括可执行文件,. 表示存放到当前目录
cmake --build .

验证构建结果

ls bin
ls lib

在这里插入图片描述
在这里插入图片描述

ls OpenCVConfig*.cmake
ls OpenCVModules.cmake

在这里插入图片描述

安装

sudo make install

在这里插入图片描述

按照默认设置,opencv会被安装到 /usr/local 目录下,所有的文件会被复制到以下位置:

/usr/local/bin - executable files
/usr/local/lib - libraries (.so)
/usr/local/cmake/opencv4 - cmake package
/usr/local/include/opencv4 - headers
/usr/local/share/opencv4 - other files (e.g. trained cascades in XML format)

验证安装结果

cd ~/opencv-4.x/samples/cpp/example_cmake	# 进入opencv核心库文件夹的samples下的cpp的案例文件中
# 构建
cmake .
# 编译并生成可执行文件
make
# 执行文件
./opencv_example

在这里插入图片描述

配置VSCode环境

创建项目文件

#include<opencv2/opencv.hpp>
using namespace cv;
int main()
{
    Mat srcImage=imread("1.jpg");
    imshow("Origin",srcImage);
    waitKey(0);
    return 0;
}

在这里插入图片描述

在这里插入图片描述

修改配置信息

在这里插入图片描述

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceRoot}/${fileBasenameNoExtension}.main.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
}
 

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "type": "shell",
      "command": "g++",
      "args": [
        "-g",
        "-std=c++11",
        "${file}",
        "-o",
        "${fileBasenameNoExtension}.main.out",
        "-I",
        "/usr/local/include",
        "-I",
        "/usr/local/include/opencv4",
        "-I",
        "/usr/local/include/opencv4/opencv2",
        "-L",
        "/usr/local/lib",
        "-l",
        "opencv_core",
        "-l",
        "opencv_imgproc",
        "-l",
        "opencv_imgcodecs",
        "-l",
        "opencv_video",
        "-l",
        "opencv_ml",
        "-l",
        "opencv_highgui",
        "-l",
        "opencv_objdetect",
        "-l",
        "opencv_flann",
        "-l",
        "opencv_imgcodecs",
        "-l",
        "opencv_photo",
        "-l",
        "opencv_videoio"
      ],
      "problemMatcher": {
        "owner": "cpp",
        "fileLocation": [
          "relative",
          "${workspaceFolder}"
        ],
        "pattern": [
          {
            "regexp": "^([^\\\\s].*)\\\\((\\\\d+,\\\\d+)\\\\):\\\\s*(.*)$",
            "file": 1,
            "location": 2,
            "message": 3
          }
        ]
      },
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

在这里插入图片描述

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                // 添加头文件查找路径
                "/usr/include",
                "/usr/local/include/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "/usr/bin/cpp",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

执行程序

在这里插入图片描述

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.8.0-dev) /usr/local/opencv/opencv-4.x/modules/highgui/src/window.cpp:1272: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
举报

相关推荐

Node.js——初识Node.js

Node——Node.js基础

【Node.js】初识 Node.js

Node.js基础

Node.JS - 基础

node.js(2)

0 条评论