Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
34081146
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,发现更多精彩内容 >>
提交
34081146
编写于
5月 27, 2015
作者:
M
Maxim Kostin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added video face detection. Restructured code.
Signed-off-by:
N
Maxim Kostin
<
v-maxkos@microsoft.com
>
上级
8bc21fc2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
78 addition
and
24 deletion
+78
-24
samples/winrt_universal/VideoCaptureXAML/video_capture_xaml/video_capture_xaml.Shared/main.cpp
...AML/video_capture_xaml/video_capture_xaml.Shared/main.cpp
+78
-24
未找到文件。
samples/winrt_universal/VideoCaptureXAML/video_capture_xaml/video_capture_xaml.Shared/main.cpp
浏览文件 @
34081146
...
...
@@ -28,22 +28,42 @@
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/videoio/cap_winrt.hpp>
// Switch definitions below to apply different filters
// TODO: add UX controls to manipulate filters at runtime
//#define COLOR
#define CANNY
//#define FACES
using
namespace
cv
;
namespace
video_capture_xaml
{
// forward declaration
void
cvFilterColor
(
Mat
&
frame
);
void
cvFilterCanny
(
Mat
&
frame
);
void
cvDetectFaces
(
Mat
&
frame
);
CascadeClassifier
face_cascade
;
String
face_cascade_name
=
"Assets/haarcascade_frontalface_alt.xml"
;
void
cvMain
()
{
VideoCapture
cam
;
//initializing frame counter used by face detection logic
long
frameCounter
=
0
;
// loading classifier for face detection
face_cascade
.
load
(
face_cascade_name
);
// open the default camera
VideoCapture
cam
;
cam
.
open
(
0
);
Mat
edges
;
Mat
frame
;
// process frames
...
...
@@ -51,37 +71,71 @@ namespace video_capture_xaml {
{
// get a new frame from camera - this is non-blocking per spec
cam
>>
frame
;
frameCounter
++
;
// don't reprocess the same frame again
//
nb
if commented then flashing may occur
// if commented then flashing may occur
if
(
!
cam
.
grab
())
continue
;
// image processing calculations here
// nb Mat frame is in RGB24 format (8UC3)
// select processing type 1 or 2
#if 0
// image manipulation example #1
// write color bar at row 100 for 200 rows
auto ar = frame.ptr(100);
int bytesPerPixel = 3;
int adjust = (int)(((float)30 / 100.0f) * 255.0);
for (int i = 0; i < 640 * 100 * bytesPerPixel;)
{
ar[i++] = adjust; // R
i++; // G
ar[i++] = 255 - adjust; // B
// Mat frame is in RGB24 format (8UC3)
// select processing type
#if defined COLOR
cvFilterColor
(
frame
);
#elif defined CANNY
cvFilterCanny
(
frame
);
#elif defined FACES
// processing every other frame to reduce the load
if
(
frameCounter
%
2
==
0
)
{
cvDetectFaces
(
frame
);
}
#else
// image processing example #2
// apply 'canny' filter
cvtColor
(
frame
,
edges
,
COLOR_RGB2GRAY
);
GaussianBlur
(
edges
,
edges
,
Size
(
7
,
7
),
1.5
,
1.5
);
Canny
(
edges
,
edges
,
0
,
30
,
3
);
cvtColor
(
edges
,
frame
,
COLOR_GRAY2RGB
);
#endif
// important step to get XAML image component updated
winrt_imshow
();
}
}
// image processing example #1
// write color bar at row 100 for 200 rows
void
cvFilterColor
(
Mat
&
frame
)
{
auto
ar
=
frame
.
ptr
(
100
);
int
bytesPerPixel
=
3
;
int
adjust
=
(
int
)(((
float
)
30
/
100.0
f
)
*
255.0
);
for
(
int
i
=
0
;
i
<
640
*
100
*
bytesPerPixel
;)
{
ar
[
i
++
]
=
adjust
;
// R
i
++
;
// G
ar
[
i
++
]
=
255
-
adjust
;
// B
}
}
// image processing example #2
// apply edge detection aka 'canny' filter
void
cvFilterCanny
(
Mat
&
frame
)
{
Mat
edges
;
cvtColor
(
frame
,
edges
,
COLOR_RGB2GRAY
);
GaussianBlur
(
edges
,
edges
,
Size
(
7
,
7
),
1.5
,
1.5
);
Canny
(
edges
,
edges
,
0
,
30
,
3
);
cvtColor
(
edges
,
frame
,
COLOR_GRAY2RGB
);
}
// image processing example #3
// detect human faces
void
cvDetectFaces
(
Mat
&
frame
)
{
Mat
faces
;
std
::
vector
<
cv
::
Rect
>
facesColl
;
cvtColor
(
frame
,
faces
,
COLOR_RGB2GRAY
);
equalizeHist
(
faces
,
faces
);
face_cascade
.
detectMultiScale
(
faces
,
facesColl
,
1.1
,
2
,
0
|
CV_HAAR_SCALE_IMAGE
,
cv
::
Size
(
1
,
1
));
for
(
unsigned
int
i
=
0
;
i
<
facesColl
.
size
();
i
++
)
{
auto
face
=
facesColl
[
i
];
cv
::
rectangle
(
frame
,
face
,
cv
::
Scalar
(
0
,
255
,
255
),
3
);
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录