Linux下使用VSCode开发OpenCV程序

摘要:
linkid=830387“版本”:任务:https://linkid=830385“版本”“类型”:“请求”:“程序”:“参数”:“环境”:[{”description“:”text“:”version“:

在Linux下使用VSCode开发OpenCV程序,并使用cmake编译

创建项目

打开vscode,选择File->Open Folder

VSCode配置

这里需要配置launch.json, tasks.json, c_cpp_properties.json三个文件;

launch.json配置

点击左侧Debug, 选择Add Configure,就生成launch.json

使用下面脚本替换即可:

{
    // 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": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
  }

tasks.json配置

使用快捷键, Shirt+Ctrl+P,输入

>Tasks:Configure Default Build Task

选择后,即可打开tasks.json文件;

将以下内容拷贝进去即可:

{
    // 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": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build"
        }
    ]
  }

c_cpp_properties.json配置

使用快捷键, Shirt+Ctrl+P,输入

>C/C++: Edit Configurations(JSON)

选择后,即可打开c_cpp_properties.json;

然后将下面内容拷贝进去,保存即可:

{
    "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
}

编写CMakeFiles .txt文件

工作目录下新建CMakeFiles.txt文件,将下面内容拷贝进去:

cmake_minimum_required(VERSION 3.0)
project(cmake_usage)

set(cmake_minimum_required 11)

# for opencv
find_package(OpenCV 4.0.0 REQUIRED)
message("OpenCV version: ${OpenCV_VERSION}")

include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIB_DIR})

add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

编写main.cpp

工作目录下新建main.cpp文件,将下面内容拷贝进去:

#include <iostream>
#include <stdlib.h>

#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
    // Load the image
    Mat img = imread("/home/chen/dataset/lena.jpg");

    cout << img.rows << endl;
    cout << img.cols << endl;
    return 0;
    
}

编译程序

在工作目录下打开终端:

mkdir build
cd build
cmake ..
make

执行:

./cmake_usage

即可打印输出信息;

免责声明:文章转载自《Linux下使用VSCode开发OpenCV程序》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇linux下执行python错误: bad interpreter: No such file or directoryWindows 安装nginx并开机启动下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

PHP 原生实现MVC框架

2017-6-5 由于工作需要 打算自己实现一个简单的  MVC框架以完成工作需求   初步定义 框架需要完成的工作 1.单入口的路由功能 2.文件的自动载入 3.流水ID的加密以及自动解密 4.MVC文件夹模式 5.通用模板的引用     单入口的路由实现   项目接口的 public 目录中存在一个index.php 文件 作为 项目的唯一入口   文...

Apache用户认证方法汇总(转载)

简介:这是Apache用户认证方法汇总(转载)的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。 frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=322022' scrolling='no'> Apache用户认证方法汇总 一.基本的Apac...

Django 语法笔记

Django 语法创建项目框架 django-admin startproject 项目名 创建子app 业务分化,可以优化团队合作,可以明确找锅 python manage.py startapp 子app名 启动项目 python manage.py runserver 项目目录结构 __init__.py: 声明当前文件夹为一个可导入的包 se...

(转)windows shell 编程

第一章 Windows Shell是什么 一个操作系统外壳的不错的定义是它是一个系统提供的用户界面,它允许用户执行公共的任务,如访问文件系统,导出执行程序,改变系统设置等。MS-DOS有一个Command.COM扮演着这个角色。然而Windows已经有了图形界面环境,他的外壳程序也就必然是图形方式的。在Windows95以前,默认的Windows Shel...

android的项目文件介绍

1.res目录存放Android的各种资源文件,比如layout存放布局文件main.xml,values存放各种xml格式的资源文件,字符串资源strings.xml,颜色资源文件:colors.xml;尺寸资源文件:dimens.xml.drawlable-ldpi,drawlable-mdpi,drawlable-hdpi则分别用于存放小、中、大三种...

.deb文件打包

最近因项目需要,需要把文件夹打包为.deb格式的包,幸亏一位朋友帮忙指导了我一个晚上,才得以完成,这里再次对他表示感谢。 整理打包流程如下: 请先参考此博客内容,了解deb文件打包 如何制作Deb包和相应的软件仓库,其实这个很简单。这里推荐使用dpkg来进行deb包的创建、编辑和制作。 首先了解一下deb包的文件结构: deb 软件包里面的结构:它具有D...