Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
bbba2a06
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
bbba2a06
编写于
7月 13, 2011
作者:
A
Ana Huaman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added pointPolygonTest_demo code for tutorials
上级
fbfddbd3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
83 addition
and
0 deletion
+83
-0
samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp
.../tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp
+83
-0
未找到文件。
samples/cpp/tutorial_code/ShapeDescriptors/pointPolygonTest_demo.cpp
0 → 100644
浏览文件 @
bbba2a06
/**
* @function pointPolygonTest_demo.cpp
* @brief Demo code to use the pointPolygonTest function...fairly easy
* @author OpenCV team
*/
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using
namespace
cv
;
using
namespace
std
;
/**
* @function main
*/
int
main
(
int
argc
,
char
**
argv
)
{
/// Create an image
const
int
r
=
100
;
Mat
src
=
Mat
::
zeros
(
Size
(
4
*
r
,
4
*
r
),
CV_8UC1
);
/// Create a sequence of points to make a contour:
vector
<
Point2f
>
vert
(
6
);
vert
[
0
]
=
Point
(
1.5
*
r
,
1.34
*
r
);
vert
[
1
]
=
Point
(
1
*
r
,
2
*
r
);
vert
[
2
]
=
Point
(
1.5
*
r
,
2.866
*
r
);
vert
[
3
]
=
Point
(
2.5
*
r
,
2.866
*
r
);
vert
[
4
]
=
Point
(
3
*
r
,
2
*
r
);
vert
[
5
]
=
Point
(
2.5
*
r
,
1.34
*
r
);
/// Draw it in src
for
(
int
j
=
0
;
j
<
6
;
j
++
)
{
line
(
src
,
vert
[
j
],
vert
[(
j
+
1
)
%
6
],
Scalar
(
255
),
3
,
8
);
}
/// Get the contours
vector
<
vector
<
Point
>
>
contours
;
vector
<
Vec4i
>
hierarchy
;
Mat
src_copy
=
src
.
clone
();
findContours
(
src_copy
,
contours
,
hierarchy
,
RETR_TREE
,
CHAIN_APPROX_SIMPLE
);
/// Calculate the distances to the contour
Mat
raw_dist
(
src
.
size
(),
CV_32FC1
);
for
(
int
j
=
0
;
j
<
src
.
rows
;
j
++
)
{
for
(
int
i
=
0
;
i
<
src
.
cols
;
i
++
)
{
raw_dist
.
at
<
float
>
(
j
,
i
)
=
pointPolygonTest
(
contours
[
0
],
Point2f
(
i
,
j
),
true
);
}
}
double
minVal
;
double
maxVal
;
minMaxLoc
(
raw_dist
,
&
minVal
,
&
maxVal
,
0
,
0
,
Mat
()
);
minVal
=
abs
(
minVal
);
maxVal
=
abs
(
maxVal
);
/// Depicting the distances graphically
Mat
drawing
=
Mat
::
zeros
(
src
.
size
(),
CV_8UC3
);
for
(
int
j
=
0
;
j
<
src
.
rows
;
j
++
)
{
for
(
int
i
=
0
;
i
<
src
.
cols
;
i
++
)
{
if
(
raw_dist
.
at
<
float
>
(
j
,
i
)
<
0
)
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
0
]
=
255
-
(
int
)
abs
(
raw_dist
.
at
<
float
>
(
j
,
i
))
*
255
/
minVal
;
}
else
if
(
raw_dist
.
at
<
float
>
(
j
,
i
)
>
0
)
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
2
]
=
255
-
(
int
)
raw_dist
.
at
<
float
>
(
j
,
i
)
*
255
/
maxVal
;
}
else
{
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
0
]
=
255
;
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
1
]
=
255
;
drawing
.
at
<
Vec3b
>
(
j
,
i
)[
2
]
=
255
;
}
}
}
/// Create Window and show your results
char
*
source_window
=
"Source"
;
namedWindow
(
source_window
,
CV_WINDOW_AUTOSIZE
);
imshow
(
source_window
,
src
);
namedWindow
(
"Distance"
,
CV_WINDOW_AUTOSIZE
);
imshow
(
"Distance"
,
drawing
);
waitKey
(
0
);
return
(
0
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录