/* This is AGAST and OAST, an optimal and accelerated corner detector
based on the accelerated segment tests
Below is the original copyright and the references */
/*
Copyright (C) 2010 Elmar Mair
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
*Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
*Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
*Neither the name of the University of Cambridge nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
The references are:
* Adaptive and Generic Corner Detection Based on the Accelerated Segment Test,
Elmar Mair and Gregory D. Hager and Darius Burschka
and Michael Suppa and Gerhard Hirzinger ECCV 2010
URL: http://www6.in.tum.de/Main/ResearchAgast
*/
#include "agast_score.hpp"
#ifdef _MSC_VER
#pragma warning( disable : 4127 )
#endif
namespace cv
{
void makeAgastOffsets(int pixel[16], int rowStride, int type)
{
static const int offsets16[][2] =
{
{-3, 0}, {-3, -1}, {-2, -2}, {-1, -3}, {0, -3}, { 1, -3}, { 2, -2}, { 3, -1},
{ 3, 0}, { 3, 1}, { 2, 2}, { 1, 3}, {0, 3}, {-1, 3}, {-2, 2}, {-3, 1}
};
static const int offsets12d[][2] =
{
{-3, 0}, {-2, -1}, {-1, -2}, {0, -3}, { 1, -2}, { 2, -1},
{ 3, 0}, { 2, 1}, { 1, 2}, {0, 3}, {-1, 2}, {-2, 1}
};
static const int offsets12s[][2] =
{
{-2, 0}, {-2, -1}, {-1, -2}, {0, -2}, { 1, -2}, { 2, -1},
{ 2, 0}, { 2, 1}, { 1, 2}, {0, 2}, {-1, 2}, {-2, 1}
};
static const int offsets8[][2] =
{
{-1, 0}, {-1, -1}, {0, -1}, { 1, -1},
{ 1, 0}, { 1, 1}, {0, 1}, {-1, 1}
};
const int (*offsets)[2] = type == AgastFeatureDetector::OAST_9_16 ? offsets16 :
type == AgastFeatureDetector::AGAST_7_12d ? offsets12d :
type == AgastFeatureDetector::AGAST_7_12s ? offsets12s :
type == AgastFeatureDetector::AGAST_5_8 ? offsets8 : 0;
CV_Assert(pixel && offsets);
int k = 0;
for( ; k < 16; k++ )
pixel[k] = offsets[k][0] + offsets[k][1] * rowStride;
}
// 16 pixel mask
template<>
int agast_cornerScore<AgastFeatureDetector::OAST_9_16>(const uchar* ptr, const int pixel[], int threshold)
{
int bmin = threshold;
int bmax = 255;
int b_test = (bmax + bmin) / 2;
short offset0 = (short) pixel[0];
short offset1 = (short) pixel[1];
short offset2 = (short) pixel[2];
short offset3 = (short) pixel[3];
short offset4 = (short) pixel[4];
short offset5 = (short) pixel[5];
short offset6 = (short) pixel[6];
short offset7 = (short) pixel[7];
short offset8 = (short) pixel[8];
short offset9 = (short) pixel[9];
short offset10 = (short) pixel[10];
short offset11 = (short) pixel[11];
short offset12 = (short) pixel[12];
short offset13 = (short) pixel[13];
short offset14 = (short) pixel[14];
short offset15 = (short) pixel[15];
while(true)
{
const int cb = *ptr + b_test;
const int c_b = *ptr - b_test;
if(ptr[offset0] > cb)
if(ptr[offset2] > cb)
if(ptr[offset4] > cb)
if(ptr[offset5] > cb)
if(ptr[offset7] > cb)
if(ptr[offset3] > cb)
if(ptr[offset1] > cb)
if(ptr[offset6] > cb)
if(ptr[offset8] > cb)
goto is_a_corner;
else
if(ptr[offset15] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
if(ptr[offset13] > cb)
if(ptr[offset14] > cb)
if(ptr[offset15] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if(ptr[offset8] > cb)
if(ptr[offset9] > cb)
if(ptr[offset10] > cb)
if(ptr[offset6] > cb)
goto is_a_corner;
else
if(ptr[offset11] > cb)
if(ptr[offset12] > cb)
if(ptr[offset13] > cb)
if(ptr[offset14] > cb)
if(ptr[offset15] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if(ptr[offset10] > cb)
if(ptr[offset11] > cb)
if(ptr[offset12] > cb)
if(ptr[offset8] > cb)
if(ptr[offset9] > cb)
if(ptr[offset6] > cb)
goto is_a_corner;
else
if(ptr[offset13] > cb)
if(ptr[offset14] > cb)
if(ptr[offset15] > cb)
goto is_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
goto is_not_a_corner;
else
if(ptr[offset1] > cb)
if(ptr[offset13] > cb)
if(ptr
win10环境下vscode运行opencv(C++)(解压即用)-2号包
需积分: 0 29 浏览量
更新于2022-12-17
3
收藏 926.73MB ZIP 举报
在Windows 10环境下,Visual Studio Code (VSCode) 是一款强大的源代码编辑器,尤其适合C++开发。OpenCV(开源计算机视觉库)则是一个广泛应用于图像处理和计算机视觉领域的库,它提供了丰富的功能,如图像读取、处理、特征检测等。本教程将介绍如何在VSCode中配置环境,以便运行已经编译好的OpenCV库。
1. **安装VSCode**
你需要在官方网站下载并安装VSCode。确保你下载的是适用于Windows 10的版本。安装过程中遵循默认设置即可。
2. **安装C++扩展**
在VSCode中,打开扩展视图(View > Extensions 或者使用快捷键 `Ctrl+Shift+X`)。搜索“C/C++”扩展,并安装由Microsoft提供的官方C/C++扩展,这个扩展提供了对C++语言的良好支持,包括语法高亮、代码提示和调试功能。
3. **配置VSCode工作区**
创建一个新的文件夹作为你的项目工作区,然后在VSCode中打开它(File > Open Folder 或者 `Ctrl+O`)。在这个文件夹中,你可以创建C++源代码文件(例如:`main.cpp`)。
4. **配置OpenCV**
你已经有一个名为“sources”的压缩子文件,其中可能包含了编译好的OpenCV库。解压该文件到你的项目工作区中,这样可以方便地引用OpenCV库。同样,"build"文件可能包含编译时所需的额外资源或配置文件。
5. **配置C++编译器**
在VSCode中,打开用户设置(File > Preferences > Settings 或者 `Ctrl+,`),找到"C/C++: Intellisense Engine",将其设置为"Default",这将启用增强型代码补全功能。
6. **配置编译路径**
在`.vscode`目录下创建一个名为`c_cpp_properties.json`的文件,用于指定头文件和库文件的路径。例如:
```json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/sources/include/**" // OpenCV头文件路径
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe", // 根据你的编译器路径进行修改
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
```
7. **配置构建任务**
同样在`.vscode`目录下,创建一个名为`tasks.json`的文件,定义编译任务,如下:
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-I${workspaceFolder}/sources/include", // 引入OpenCV头文件
"-L${workspaceFolder}/sources/lib", // 指定OpenCV库文件路径
"-lopencv_core",
"-lopencv_imgproc",
// 添加更多OpenCV库,根据需要
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe"
],
"problemMatcher": ["$gcc"]
}
]
}
```
如果你使用的是Visual C++,请修改`command`为`cl.exe`,并添加相应的链接参数。
8. **调试配置**
在`.vscode`目录下创建`launch.json`文件,定义调试配置:
```json
{
"version": "0.2.0",
"configurations": [
{
"name": "GDB调试",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe", // 如果你使用的是GDB,请指定路径,对于Visual Studio,使用"MIEngine"
"setupCommands": [
{
"description": "启用C++的自动完成",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build" // 使用之前定义的构建任务
}
]
}
```
9. **运行与调试**
现在,你可以在`main.cpp`中编写使用OpenCV的C++代码,利用VSCode的代码补全功能。保存文件后,按下`Ctrl+Shift+B`执行构建任务,然后使用`F5`启动调试。确保正确引入OpenCV库,并使用`#include <opencv2/opencv.hpp>`。
10. **示例代码**
一个简单的OpenCV示例代码可能如下:
```cpp
#include <opencv2/opencv.hpp>
#include <iostream>
int main() {
cv::Mat img = cv::imread("example.jpg");
if (img.empty()) {
std::cerr << "无法读取图像!" << std::endl;
return -1;
}
cv::imshow("Image", img);
cv::waitKey(0);
return 0;
}
```
通过以上步骤,你应该能在VSCode中顺利运行和调试使用OpenCV的C++程序了。记住,每次更改编译配置或添加新的OpenCV模块时,都需要更新`c_cpp_properties.json`和`tasks.json`。同时,确保你的系统环境变量正确设置了OpenCV库的位置,以便在其他项目中也能轻松使用。

LuZelin
- 粉丝: 5822
最新资源
- [信息与通信]第四章-混凝土配合比设计知识课件.ppt
- 基于单片机的分时计费智能电度表的设计.docx
- 第01章--电子商务概述ppt课件.ppt
- 具有丰富的数据类型是C语言的一个特色数据类型丰富意电子教案.ppt
- 嵌入式Linux差分插补数控系统关键技术研究的开题报告.docx
- HTML5-Canvas实现玫瑰曲线和心形图案的代码实例.doc
- csc2000综合自动化系统在变电所的应用.docx
- 光机电一体化PLC实训室建设最终方案.doc
- 基于互联网+的体脂秤产品设计造型探究.docx
- 人防通信设备维护方案.docx
- 《面向对象的程序设计语言——C》课件--第2章资料讲解.ppt
- 2023年基于遗传算法的机器人路径规划MATLAB源码.doc
- 基于盈亏平衡的企业电子商务战略影响因素探析.docx
- S7-200-PLC的指令系统顺序控制(2).ppt
- 浅谈互联网+背景下的初中物理实验教学的实践.docx
- 基于信息化建设视角下的图书管理策略探究.docx