Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
df0108d1
提交
df0108d1
authored
4月 16, 2015
作者:
Anthony Minessale
提交者:
Michael Jerris
5月 28, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-7515: add more features to mod_cv
上级
7cdf1617
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
284 行增加
和
137 行删除
+284
-137
mod_cv.cpp
src/mod/applications/mod_cv/mod_cv.cpp
+268
-136
switch_core_video.c
src/switch_core_video.c
+16
-1
没有找到文件。
src/mod/applications/mod_cv/mod_cv.cpp
浏览文件 @
df0108d1
...
@@ -88,13 +88,14 @@ struct overlay {
...
@@ -88,13 +88,14 @@ struct overlay {
float
xo
;
float
xo
;
float
yo
;
float
yo
;
float
shape_scale
;
float
shape_scale
;
int
scale_w
;
int
scale_h
;
int
zidx
;
int
zidx
;
switch_img_position_t
abs
;
switch_img_position_t
abs
;
};
};
typedef
struct
cv_context_s
{
typedef
struct
cv_context_s
{
IplImage
*
rawImage
;
IplImage
*
rawImage
;
IplImage
*
yuvImage
;
CascadeClassifier
*
cascade
;
CascadeClassifier
*
cascade
;
CascadeClassifier
*
nestedCascade
;
CascadeClassifier
*
nestedCascade
;
int
w
;
int
w
;
...
@@ -130,20 +131,93 @@ static int clear_overlay(cv_context_t *context, int idx)
...
@@ -130,20 +131,93 @@ static int clear_overlay(cv_context_t *context, int idx)
return
0
;
return
0
;
}
}
context
->
overlay
[
idx
]
->
png_path
=
NULL
;
context
->
overlay
[
idx
]
->
png_path
=
NULL
;
context
->
overlay
[
idx
]
->
nick
=
NULL
;
context
->
overlay
[
idx
]
->
nick
=
NULL
;
switch_img_free
(
&
context
->
overlay
[
idx
]
->
png
);
switch_img_free
(
&
context
->
overlay
[
idx
]
->
png
);
memset
(
context
->
overlay
[
idx
],
0
,
sizeof
(
struct
overlay
));
memset
(
context
->
overlay
[
idx
],
0
,
sizeof
(
struct
overlay
));
context
->
overlay
[
idx
]
->
shape_scale
=
1
;
context
->
overlay_count
--
;
context
->
overlay_count
--
;
for
(
x
=
idx
+
1
;
x
<
i
;
x
++
)
{
for
(
x
=
idx
+
1
;
x
<
i
;
x
++
)
{
context
->
overlay
[
x
-
1
]
=
context
->
overlay
[
x
];
context
->
overlay
[
x
-
1
]
=
context
->
overlay
[
x
];
memset
(
context
->
overlay
[
x
],
0
,
sizeof
(
struct
overlay
));
memset
(
context
->
overlay
[
x
],
0
,
sizeof
(
struct
overlay
));
context
->
overlay
[
x
]
->
shape_scale
=
1
;
}
}
return
idx
-
1
>
0
?
idx
-
1
:
0
;
return
idx
-
1
>
0
?
idx
-
1
:
0
;
}
}
static
int
add_text
(
cv_context_t
*
context
,
const
char
*
nick
,
const
char
*
fg
,
const
char
*
bg
,
const
char
*
font_face
,
int
font_size
,
const
char
*
text
)
{
uint32_t
i
=
context
->
overlay_count
;
switch_rgb_color_t
fgcolor
,
bgcolor
;
int
x
=
0
,
width
=
0
,
is_new
=
1
;
switch_img_txt_handle_t
*
txthandle
=
NULL
;
for
(
x
=
0
;
x
<
i
;
x
++
)
{
if
(
context
->
overlay
[
x
]
&&
context
->
overlay
[
x
]
->
png
)
{
if
(
!
zstr
(
nick
))
{
if
(
!
zstr
(
context
->
overlay
[
x
]
->
nick
)
&&
!
strcmp
(
context
->
overlay
[
x
]
->
nick
,
nick
))
{
i
=
x
;
is_new
=
0
;
break
;
}
}
else
{
if
(
strstr
(
context
->
overlay
[
x
]
->
png_path
,
text
))
{
if
(
!
zstr
(
nick
)
&&
(
zstr
(
context
->
overlay
[
x
]
->
nick
)
||
strcmp
(
nick
,
context
->
overlay
[
x
]
->
nick
)))
{
context
->
overlay
[
x
]
->
nick
=
switch_core_strdup
(
context
->
pool
,
nick
);
}
i
=
x
;
is_new
=
0
;
break
;
}
}
}
}
if
(
is_new
)
{
context
->
overlay_count
++
;
if
(
!
zstr
(
nick
))
{
context
->
overlay
[
i
]
->
nick
=
switch_core_strdup
(
context
->
pool
,
nick
);
}
}
if
(
!
font_size
)
{
font_size
=
24
;
}
if
(
!
font_face
)
{
font_face
=
"FreeMono.ttf"
;
}
if
(
!
fg
)
{
fg
=
"#cccccc"
;
}
if
(
!
bg
)
{
bg
=
"#142e55"
;
}
width
=
(
int
)
(
float
)(
font_size
*
0.75
f
*
strlen
(
text
));
switch_color_set_rgb
(
&
fgcolor
,
fg
);
switch_color_set_rgb
(
&
bgcolor
,
bg
);
switch_img_free
(
&
context
->
overlay
[
i
]
->
png
);
context
->
overlay
[
i
]
->
png
=
switch_img_alloc
(
NULL
,
SWITCH_IMG_FMT_I420
,
width
,
font_size
*
2
,
1
);
switch_img_fill
(
context
->
overlay
[
i
]
->
png
,
0
,
0
,
context
->
overlay
[
i
]
->
png
->
d_w
,
context
->
overlay
[
i
]
->
png
->
d_h
,
&
bgcolor
);
switch_img_txt_handle_create
(
&
txthandle
,
font_face
,
fg
,
bg
,
font_size
,
0
,
NULL
);
switch_img_txt_handle_render
(
txthandle
,
context
->
overlay
[
i
]
->
png
,
font_size
/
2
,
font_size
/
2
,
text
,
NULL
,
fg
,
bg
,
0
,
0
);
switch_img_txt_handle_destroy
(
&
txthandle
);
return
i
;
}
static
int
add_overlay
(
cv_context_t
*
context
,
const
char
*
png_path
,
const
char
*
nick
)
static
int
add_overlay
(
cv_context_t
*
context
,
const
char
*
png_path
,
const
char
*
nick
)
{
{
uint32_t
i
=
context
->
overlay_count
;
uint32_t
i
=
context
->
overlay_count
;
...
@@ -159,6 +233,9 @@ static int add_overlay(cv_context_t *context, const char *png_path, const char *
...
@@ -159,6 +233,9 @@ static int add_overlay(cv_context_t *context, const char *png_path, const char *
}
}
}
else
{
}
else
{
if
(
strstr
(
context
->
overlay
[
x
]
->
png_path
,
png_path
))
{
if
(
strstr
(
context
->
overlay
[
x
]
->
png_path
,
png_path
))
{
if
(
!
zstr
(
nick
)
&&
(
zstr
(
context
->
overlay
[
x
]
->
nick
)
||
strcmp
(
nick
,
context
->
overlay
[
x
]
->
nick
)))
{
context
->
overlay
[
x
]
->
nick
=
switch_core_strdup
(
context
->
pool
,
nick
);
}
return
x
;
return
x
;
}
}
}
}
...
@@ -181,9 +258,7 @@ static int add_overlay(cv_context_t *context, const char *png_path, const char *
...
@@ -181,9 +258,7 @@ static int add_overlay(cv_context_t *context, const char *png_path, const char *
context
->
overlay
[
i
]
->
png_path
=
new_png_path
;
context
->
overlay
[
i
]
->
png_path
=
new_png_path
;
if
(
!
zstr
(
nick
))
{
if
(
!
zstr
(
nick
))
{
context
->
overlay
[
i
]
->
nick
=
switch_core_strdup
(
context
->
pool
,
nick
);
context
->
overlay
[
i
]
->
nick
=
switch_core_strdup
(
context
->
pool
,
nick
);
}
}
if
(
!
context
->
overlay
[
i
]
->
shape_scale
)
context
->
overlay
[
i
]
->
shape_scale
=
1
;
r
=
(
int
)
i
;
r
=
(
int
)
i
;
}
else
{
}
else
{
context
->
overlay
[
i
]
->
png_path
=
NULL
;
context
->
overlay
[
i
]
->
png_path
=
NULL
;
...
@@ -236,6 +311,7 @@ static void uninit_context(cv_context_t *context)
...
@@ -236,6 +311,7 @@ static void uninit_context(cv_context_t *context)
context
->
overlay
[
i
]
->
png_path
=
NULL
;
context
->
overlay
[
i
]
->
png_path
=
NULL
;
context
->
overlay_count
=
0
;
context
->
overlay_count
=
0
;
memset
(
context
->
overlay
[
i
],
0
,
sizeof
(
struct
overlay
));
memset
(
context
->
overlay
[
i
],
0
,
sizeof
(
struct
overlay
));
context
->
overlay
[
i
]
->
shape_scale
=
1
;
}
}
switch_core_destroy_memory_pool
(
&
context
->
pool
);
switch_core_destroy_memory_pool
(
&
context
->
pool
);
...
@@ -256,6 +332,7 @@ static void init_context(cv_context_t *context)
...
@@ -256,6 +332,7 @@ static void init_context(cv_context_t *context)
for
(
int
i
=
0
;
i
<
MAX_OVERLAY
;
i
++
)
{
for
(
int
i
=
0
;
i
<
MAX_OVERLAY
;
i
++
)
{
context
->
overlay
[
i
]
=
(
struct
overlay
*
)
switch_core_alloc
(
context
->
pool
,
sizeof
(
struct
overlay
));
context
->
overlay
[
i
]
=
(
struct
overlay
*
)
switch_core_alloc
(
context
->
pool
,
sizeof
(
struct
overlay
));
context
->
overlay
[
i
]
->
abs
=
POS_NONE
;
context
->
overlay
[
i
]
->
abs
=
POS_NONE
;
context
->
overlay
[
i
]
->
shape_scale
=
1
;
}
}
create
=
1
;
create
=
1
;
...
@@ -461,45 +538,63 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
...
@@ -461,45 +538,63 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
{
{
cv_context_t
*
context
=
(
cv_context_t
*
)
user_data
;
cv_context_t
*
context
=
(
cv_context_t
*
)
user_data
;
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
int
i
;
if
(
!
switch_channel_ready
(
channel
))
{
if
(
!
switch_channel_ready
(
channel
))
{
return
SWITCH_STATUS_FALSE
;
return
SWITCH_STATUS_FALSE
;
}
}
if
(
frame
->
img
)
{
if
(
!
frame
->
img
)
{
return
SWITCH_STATUS_SUCCESS
;
}
if
(
context
->
cascade
)
{
switch_event_t
*
event
;
if
((
frame
->
img
->
d_w
!=
context
->
w
||
frame
->
img
->
d_h
!=
context
->
h
)
&&
context
->
rawImage
)
{
if
((
frame
->
img
->
d_w
!=
context
->
w
||
frame
->
img
->
d_h
!=
context
->
h
)
&&
context
->
rawImage
)
{
cvReleaseImage
(
&
context
->
rawImage
);
cvReleaseImage
(
&
context
->
rawImage
);
cvReleaseImage
(
&
context
->
yuvImage
);
}
}
if
(
!
context
->
rawImage
)
{
if
(
!
context
->
rawImage
)
{
context
->
rawImage
=
cvCreateImage
(
cvSize
(
frame
->
img
->
d_w
,
frame
->
img
->
d_h
),
IPL_DEPTH_8U
,
3
);
context
->
rawImage
=
cvCreateImage
(
cvSize
(
frame
->
img
->
d_w
,
frame
->
img
->
d_h
),
IPL_DEPTH_8U
,
3
);
context
->
yuvImage
=
cvCreateImage
(
cvSize
(
frame
->
img
->
d_w
,
frame
->
img
->
d_h
),
IPL_DEPTH_8U
,
3
);
switch_assert
(
context
->
rawImage
);
switch_assert
(
context
->
rawImage
);
switch_assert
(
context
->
rawImage
->
width
*
3
==
context
->
rawImage
->
widthStep
);
switch_assert
(
context
->
rawImage
->
width
*
3
==
context
->
rawImage
->
widthStep
);
}
}
//printf("context->rawImage: %dx%d stride: %d size: %d color:%s\n", context->rawImage->width, context->rawImage->height, context->rawImage->widthStep, context->rawImage->imageSize, context->rawImage->colorModel);
libyuv
::
I420ToRGB24
(
frame
->
img
->
planes
[
0
],
frame
->
img
->
stride
[
0
],
libyuv
::
I420ToRGB24
(
frame
->
img
->
planes
[
0
],
frame
->
img
->
stride
[
0
],
frame
->
img
->
planes
[
1
],
frame
->
img
->
stride
[
1
],
frame
->
img
->
planes
[
1
],
frame
->
img
->
stride
[
1
],
frame
->
img
->
planes
[
2
],
frame
->
img
->
stride
[
2
],
frame
->
img
->
planes
[
2
],
frame
->
img
->
stride
[
2
],
(
uint8_t
*
)
context
->
rawImage
->
imageData
,
context
->
rawImage
->
widthStep
,
(
uint8_t
*
)
context
->
rawImage
->
imageData
,
context
->
rawImage
->
widthStep
,
context
->
rawImage
->
width
,
context
->
rawImage
->
height
);
context
->
rawImage
->
width
,
context
->
rawImage
->
height
);
detectAndDraw
(
context
);
if
(
context
->
cascade
)
{
switch_event_t
*
event
;
detectAndDraw
(
context
);
if
(
context
->
detected
.
simo_count
>
20
)
{
if
(
context
->
detected
.
simo_count
>
20
)
{
if
(
!
context
->
detect_event
)
{
if
(
!
context
->
detect_event
)
{
context
->
detect_event
=
1
;
context
->
detect_event
=
1
;
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"primary"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"start"
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%u"
,
context
->
detected
.
simo_count
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
detected
.
avg
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
detected
.
last_score
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Unique-ID"
,
switch_core_session_get_uuid
(
session
));
//switch_channel_event_set_data(channel, event);
DUMP_EVENT
(
event
);
switch_event_fire
(
&
event
);
}
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_primary"
);
}
}
else
{
if
(
context
->
detected
.
simo_miss_count
>=
20
)
{
if
(
context
->
detect_event
)
{
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"primary"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"primary"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"st
art
"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"st
op
"
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%u"
,
context
->
detected
.
simo_count
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%u"
,
context
->
detected
.
simo_count
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
detected
.
avg
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
detected
.
avg
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
detected
.
last_score
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
detected
.
last_score
);
...
@@ -508,154 +603,157 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
...
@@ -508,154 +603,157 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
DUMP_EVENT
(
event
);
DUMP_EVENT
(
event
);
switch_event_fire
(
&
event
);
switch_event_fire
(
&
event
);
}
}
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_primary"
);
}
}
else
{
if
(
context
->
detected
.
simo_miss_count
>=
20
)
{
if
(
context
->
detect_event
)
{
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"primary"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"stop"
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%u"
,
context
->
detected
.
simo_count
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
detected
.
avg
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
detected
.
last_score
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Unique-ID"
,
switch_core_session_get_uuid
(
session
));
//switch_channel_event_set_data(channel, event);
DUMP_EVENT
(
event
);
switch_event_fire
(
&
event
);
}
memset
(
context
->
shape
,
0
,
sizeof
(
context
->
shape
[
0
])
*
MAX_SHAPES
);
memset
(
context
->
shape
,
0
,
sizeof
(
context
->
shape
[
0
])
*
MAX_SHAPES
);
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_off_primary"
);
reset_stats
(
&
context
->
nestDetected
);
reset_stats
(
&
context
->
detected
);
}
context
->
detect_event
=
0
;
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_off_primary"
);
reset_stats
(
&
context
->
nestDetected
);
reset_stats
(
&
context
->
detected
);
}
}
context
->
detect_event
=
0
;
}
}
if
(
context
->
nestedCascade
&&
context
->
detected
.
simo_count
>
20
)
{
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"CHECKING: %d %d %f %d
\n
"
,
context
->
nestDetected
.
itr
,
context
->
nestDetected
.
last_score
,
context
->
nestDetected
.
avg
,
context
->
nestDetected
.
above_avg_simo_count
);
if
(
context
->
nestedCascade
&&
context
->
detected
.
simo_count
>
20
)
{
if
(
context
->
nestDetected
.
simo_count
>
20
&&
context
->
nestDetected
.
last_score
>
context
->
nestDetected
.
avg
&&
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"CHECKING: %d %d %f %d
\n
"
,
context
->
nestDetected
.
itr
,
context
->
nestDetected
.
last_score
,
context
->
nestDetected
.
avg
,
context
->
nestDetected
.
above_avg_simo_count
);
context
->
nestDetected
.
above_avg_simo_count
>
5
)
{
if
(
!
context
->
nest_detect_event
)
{
if
(
context
->
nestDetected
.
simo_count
>
20
&&
context
->
nestDetected
.
last_score
>
context
->
nestDetected
.
avg
&&
context
->
nest_detect_event
=
1
;
context
->
nestDetected
.
above_avg_simo_count
>
5
)
{
if
(
!
context
->
nest_detect_event
)
{
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
context
->
nest_detect_event
=
1
;
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"nested"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"start"
);
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%d"
,
context
->
nestDetected
.
simo_count
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"nested"
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
nestDetected
.
avg
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"start"
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
nestDetected
.
last_score
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%d"
,
context
->
nestDetected
.
simo_count
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Unique-ID"
,
switch_core_session_get_uuid
(
session
));
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
nestDetected
.
avg
);
//switch_channel_event_set_data(channel, event);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
nestDetected
.
last_score
);
DUMP_EVENT
(
event
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Unique-ID"
,
switch_core_session_get_uuid
(
session
));
switch_event_fire
(
&
event
);
//switch_channel_event_set_data(channel, event);
}
DUMP_EVENT
(
event
);
switch_event_fire
(
&
event
);
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_nested"
);
}
}
}
else
if
(
context
->
nestDetected
.
above_avg_simo_count
==
0
)
{
if
(
context
->
nest_detect_event
)
{
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_nested"
);
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
}
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"nested"
);
}
else
if
(
context
->
nestDetected
.
above_avg_simo_count
==
0
)
{
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"stop"
);
if
(
context
->
nest_detect_event
)
{
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%d"
,
context
->
nestDetected
.
simo_count
);
if
(
switch_event_create_subclass
(
&
event
,
SWITCH_EVENT_CUSTOM
,
MY_EVENT_VIDEO_DETECT
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
nestDetected
.
avg
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Type"
,
"nested"
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
nestDetected
.
last_score
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Disposition"
,
"stop"
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Unique-ID"
,
switch_core_session_get_uuid
(
session
)
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Simo-Count"
,
"%d"
,
context
->
nestDetected
.
simo_count
);
//switch_channel_event_set_data(channel, event
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Average"
,
"%f"
,
context
->
nestDetected
.
avg
);
DUMP_EVENT
(
event
);
switch_event_add_header
(
event
,
SWITCH_STACK_BOTTOM
,
"Detect-Last-Score"
,
"%u"
,
context
->
nestDetected
.
last_score
);
switch_event_fire
(
&
event
);
switch_event_add_header_string
(
event
,
SWITCH_STACK_BOTTOM
,
"Unique-ID"
,
switch_core_session_get_uuid
(
session
)
);
}
//switch_channel_event_set_data(channel, event);
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_off_nested"
);
DUMP_EVENT
(
event
);
reset_stats
(
&
context
->
nestDetected
);
switch_event_fire
(
&
event
);
}
}
switch_channel_execute_on
(
channel
,
"execute_on_cv_detect_off_nested"
);
context
->
nest_detect_event
=
0
;
reset_stats
(
&
context
->
nestDetected
)
;
}
}
context
->
nest_detect_event
=
0
;
}
}
}
}
}
int
w
=
context
->
rawImage
->
width
;
int
h
=
context
->
rawImage
->
height
;
if
(
context
->
debug
||
!
context
->
overlay_count
)
{
libyuv
::
RGB24ToI420
((
uint8_t
*
)
context
->
rawImage
->
imageData
,
w
*
3
,
frame
->
img
->
planes
[
0
],
frame
->
img
->
stride
[
0
],
frame
->
img
->
planes
[
1
],
frame
->
img
->
stride
[
1
],
frame
->
img
->
planes
[
2
],
frame
->
img
->
stride
[
2
],
context
->
rawImage
->
width
,
context
->
rawImage
->
height
);
}
int
w
=
context
->
rawImage
->
width
;
int
abs
=
0
;
int
h
=
context
->
rawImage
->
height
;
if
(
context
->
debug
||
!
context
->
overlay_count
)
{
for
(
i
=
0
;
i
<
context
->
overlay_count
;
i
++
)
{
libyuv
::
RGB24ToI420
((
uint8_t
*
)
context
->
rawImage
->
imageData
,
w
*
3
,
if
(
context
->
overlay
[
i
]
->
abs
!=
POS_NONE
)
{
frame
->
img
->
planes
[
0
],
frame
->
img
->
stride
[
0
],
abs
++
;
frame
->
img
->
planes
[
1
],
frame
->
img
->
stride
[
1
],
frame
->
img
->
planes
[
2
],
frame
->
img
->
stride
[
2
],
context
->
rawImage
->
width
,
context
->
rawImage
->
height
);
}
}
}
if
(
context
->
overlay_count
&&
context
->
detect_event
&&
context
->
shape
[
0
].
cx
)
{
if
(
context
->
overlay_count
&&
(
abs
||
context
->
detect_event
&&
context
->
shape
[
0
].
cx
))
{
int
i
;
for
(
i
=
0
;
i
<
context
->
overlay_count
;
i
++
)
{
struct
overlay
*
overlay
=
context
->
overlay
[
i
];
for
(
i
=
0
;
i
<
context
->
overlay_count
;
i
++
)
{
int
x
=
0
,
y
=
0
;
struct
overlay
*
overlay
=
context
->
overlay
[
i
];
switch_image_t
*
img
=
NULL
;
int
x
=
0
,
y
=
0
;
int
scale_w
=
0
,
scale_h
=
0
;
switch_image_t
*
img
=
NULL
;
int
xo
=
0
,
yo
=
0
;
int
scale_w
=
0
,
scale_h
=
0
;
int
shape_w
,
shape_h
;
int
xo
=
0
,
yo
=
0
;
int
cx
,
cy
;
int
shape_w
,
shape_h
;
int
cx
,
cy
;
if
(
context
->
overlay
[
i
]
->
abs
==
POS_NONE
&&
!
context
->
detect_event
&&
!
context
->
shape
[
0
].
cx
)
{
continue
;
shape_w
=
context
->
shape
[
0
].
w
;
}
shape_h
=
context
->
shape
[
0
].
h
;
shape_w
=
context
->
shape
[
0
].
w
;
shape_h
=
context
->
shape
[
0
].
h
;
cx
=
context
->
shape
[
0
].
cx
;
cx
=
context
->
shape
[
0
].
cx
;
cy
=
context
->
shape
[
0
].
cy
;
cy
=
context
->
shape
[
0
].
cy
;
if
(
overlay
->
abs
!=
POS_NONE
)
{
if
(
overlay
->
abs
!=
POS_NONE
)
{
if
(
overlay
->
shape_scale
!=
1
)
{
if
(
overlay
->
scale_w
||
overlay
->
scale_h
)
{
scale_w
=
overlay
->
png
->
d_w
*
overlay
->
shape_scale
;
if
(
overlay
->
scale_w
&&
!
overlay
->
scale_h
)
{
if
(
scale_w
>
frame
->
img
->
d_w
)
{
scale_w
=
frame
->
img
->
d_w
;
scale_w
=
frame
->
img
->
d_w
;
}
scale_h
=
((
overlay
->
png
->
d_h
*
scale_w
)
/
overlay
->
png
->
d_w
);
scale_h
=
((
overlay
->
png
->
d_h
*
scale_w
)
/
overlay
->
png
->
d_w
);
}
else
if
(
overlay
->
scale_h
&&
!
overlay
->
scale_w
)
{
scale_h
=
frame
->
img
->
d_h
;
scale_w
=
((
overlay
->
png
->
d_w
*
scale_h
)
/
overlay
->
png
->
d_h
);
}
else
{
}
else
{
scale_w
=
overlay
->
pn
g
->
d_w
;
scale_w
=
frame
->
im
g
->
d_w
;
scale_h
=
overlay
->
pn
g
->
d_h
;
scale_h
=
frame
->
im
g
->
d_h
;
}
}
}
else
if
(
overlay
->
shape_scale
!=
1
)
{
scale_w
=
overlay
->
png
->
d_w
*
overlay
->
shape_scale
;
switch_img_find_position
(
overlay
->
abs
,
frame
->
img
->
d_w
,
frame
->
img
->
d_h
,
scale_w
,
scale_h
,
&
x
,
&
y
);
}
else
{
scale_w
=
shape_w
*
overlay
->
shape_scale
;
if
(
scale_w
>
frame
->
img
->
d_w
)
{
if
(
scale_w
>
frame
->
img
->
d_w
)
{
scale_w
=
frame
->
img
->
d_w
;
scale_w
=
frame
->
img
->
d_w
;
}
}
scale_h
=
((
overlay
->
png
->
d_h
*
scale_w
)
/
overlay
->
png
->
d_w
);
scale_h
=
((
overlay
->
png
->
d_h
*
scale_w
)
/
overlay
->
png
->
d_w
);
}
else
{
scale_w
=
overlay
->
png
->
d_w
;
scale_h
=
overlay
->
png
->
d_h
;
}
if
(
overlay
->
xo
)
{
switch_img_find_position
(
overlay
->
abs
,
frame
->
img
->
d_w
,
frame
->
img
->
d_h
,
scale_w
,
scale_h
,
&
x
,
&
y
);
xo
=
overlay
->
xo
*
shape_w
;
}
else
{
}
scale_w
=
shape_w
*
overlay
->
shape_scale
;
if
(
overlay
->
yo
)
{
if
(
scale_w
>
frame
->
img
->
d_w
)
{
yo
=
overlay
->
yo
*
context
->
shape
[
0
].
h
;
scale_w
=
frame
->
img
->
d_w
;
}
x
=
cx
-
((
scale_w
/
2
)
+
xo
);
y
=
cy
-
((
scale_h
/
2
)
+
yo
);
}
}
scale_h
=
((
overlay
->
png
->
d_h
*
scale_w
)
/
overlay
->
png
->
d_w
);
switch_img_scale
(
overlay
->
png
,
&
img
,
scale_w
,
scale_h
);
if
(
img
)
{
if
(
overlay
->
xo
)
{
switch_img_patch
(
frame
->
img
,
img
,
x
,
y
);
xo
=
overlay
->
xo
*
shape_w
;
switch_img_free
(
&
img
);
}
if
(
overlay
->
yo
)
{
yo
=
overlay
->
yo
*
context
->
shape
[
0
].
h
;
}
}
x
=
cx
-
((
scale_w
/
2
)
+
xo
);
y
=
cy
-
((
scale_h
/
2
)
+
yo
);
}
switch_img_scale
(
overlay
->
png
,
&
img
,
scale_w
,
scale_h
);
if
(
img
)
{
switch_img_patch
(
frame
->
img
,
img
,
x
,
y
);
switch_img_free
(
&
img
);
}
}
}
}
}
}
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
...
@@ -701,7 +799,6 @@ static void parse_params(cv_context_t *context, int start, int argc, char **argv
...
@@ -701,7 +799,6 @@ static void parse_params(cv_context_t *context, int start, int argc, char **argv
}
}
if
(
name
&&
val
)
{
if
(
name
&&
val
)
{
if
(
!
strcasecmp
(
name
,
"xo"
))
{
if
(
!
strcasecmp
(
name
,
"xo"
))
{
context
->
overlay
[
png_idx
]
->
xo
=
atof
(
val
);
context
->
overlay
[
png_idx
]
->
xo
=
atof
(
val
);
}
else
if
(
!
strcasecmp
(
name
,
"nick"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"nick"
))
{
...
@@ -714,8 +811,27 @@ static void parse_params(cv_context_t *context, int start, int argc, char **argv
...
@@ -714,8 +811,27 @@ static void parse_params(cv_context_t *context, int start, int argc, char **argv
sort
++
;
sort
++
;
}
else
if
(
!
strcasecmp
(
name
,
"abs"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"abs"
))
{
context
->
overlay
[
png_idx
]
->
abs
=
parse_img_position
(
val
);
context
->
overlay
[
png_idx
]
->
abs
=
parse_img_position
(
val
);
if
(
context
->
overlay
[
png_idx
]
->
abs
==
POS_NONE
)
{
context
->
overlay
[
png_idx
]
->
scale_w
=
context
->
overlay
[
png_idx
]
->
scale_h
=
0
;
}
}
else
if
(
!
strcasecmp
(
name
,
"scaleto"
)
&&
context
->
overlay
[
png_idx
]
->
abs
!=
POS_NONE
)
{
if
(
strchr
(
val
,
'W'
))
{
context
->
overlay
[
png_idx
]
->
scale_w
=
1
;
}
if
(
strchr
(
val
,
'H'
))
{
context
->
overlay
[
png_idx
]
->
scale_h
=
1
;
}
if
(
strchr
(
val
,
'w'
))
{
context
->
overlay
[
png_idx
]
->
scale_w
=
0
;
}
if
(
strchr
(
val
,
'h'
))
{
context
->
overlay
[
png_idx
]
->
scale_h
=
0
;
}
}
else
if
(
!
strcasecmp
(
name
,
"scale"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"scale"
))
{
context
->
overlay
[
png_idx
]
->
shape_scale
=
atof
(
val
);
context
->
overlay
[
png_idx
]
->
shape_scale
=
atof
(
val
);
}
else
if
(
!
strcasecmp
(
name
,
"skip"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"skip"
))
{
context
->
skip
=
atoi
(
val
);
context
->
skip
=
atoi
(
val
);
}
else
if
(
!
strcasecmp
(
name
,
"debug"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"debug"
))
{
...
@@ -728,10 +844,26 @@ static void parse_params(cv_context_t *context, int start, int argc, char **argv
...
@@ -728,10 +844,26 @@ static void parse_params(cv_context_t *context, int start, int argc, char **argv
changed
++
;
changed
++
;
}
else
if
(
!
strcasecmp
(
name
,
"png"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"png"
))
{
png_idx
=
add_overlay
(
context
,
val
,
nick
);
png_idx
=
add_overlay
(
context
,
val
,
nick
);
}
else
if
(
!
strcasecmp
(
name
,
"txt"
))
{
int
iargc
=
0
;
char
*
iargv
[
10
]
=
{
0
};
iargc
=
switch_split
(
val
,
':'
,
iargv
);
if
(
iargc
>=
5
)
{
png_idx
=
add_text
(
context
,
nick
,
iargv
[
0
],
iargv
[
1
],
iargv
[
2
],
atoi
(
iargv
[
3
]),
iargv
[
4
]);
}
}
}
}
else
if
(
name
)
{
}
else
if
(
name
)
{
if
(
!
strcasecmp
(
name
,
"clear"
))
{
if
(
!
strcasecmp
(
name
,
"clear"
))
{
png_idx
=
clear_overlay
(
context
,
png_idx
);
png_idx
=
clear_overlay
(
context
,
png_idx
);
}
else
if
(
!
strcasecmp
(
name
,
"allclear"
))
{
for
(
int
x
=
context
->
overlay_count
-
1
;
x
>=
0
;
x
--
)
{
png_idx
=
clear_overlay
(
context
,
x
);
context
->
overlay
[
x
]
->
xo
=
context
->
overlay
[
x
]
->
yo
=
context
->
overlay
[
x
]
->
shape_scale
=
0.0
f
;
context
->
overlay
[
x
]
->
zidx
=
0
;
context
->
overlay
[
x
]
->
scale_w
=
context
->
overlay
[
x
]
->
scale_h
=
0
;
context
->
overlay
[
x
]
->
shape_scale
=
1
;
}
}
else
if
(
!
strcasecmp
(
name
,
"home"
))
{
}
else
if
(
!
strcasecmp
(
name
,
"home"
))
{
context
->
overlay
[
png_idx
]
->
xo
=
context
->
overlay
[
png_idx
]
->
yo
=
context
->
overlay
[
png_idx
]
->
shape_scale
=
0.0
f
;
context
->
overlay
[
png_idx
]
->
xo
=
context
->
overlay
[
png_idx
]
->
yo
=
context
->
overlay
[
png_idx
]
->
shape_scale
=
0.0
f
;
context
->
overlay
[
png_idx
]
->
zidx
=
0
;
context
->
overlay
[
png_idx
]
->
zidx
=
0
;
...
...
src/switch_core_video.c
浏览文件 @
df0108d1
...
@@ -507,7 +507,22 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_create(switch_img_txt_hand
...
@@ -507,7 +507,22 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_create(switch_img_txt_hand
new_handle
->
pool
=
pool
;
new_handle
->
pool
=
pool
;
new_handle
->
free_pool
=
free_pool
;
new_handle
->
free_pool
=
free_pool
;
new_handle
->
font_family
=
switch_core_strdup
(
new_handle
->
pool
,
font_family
);
if
(
!
switch_is_file_path
(
font_family
))
{
new_handle
->
font_family
=
switch_core_sprintf
(
new_handle
->
pool
,
"%s%s%s"
,
SWITCH_GLOBAL_dirs
.
fonts_dir
,
SWITCH_PATH_SEPARATOR
,
font_family
);
}
else
{
new_handle
->
font_family
=
switch_core_strdup
(
new_handle
->
pool
,
font_family
);
}
if
(
switch_file_exists
(
new_handle
->
font_family
,
new_handle
->
pool
)
!=
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Font %s does not exist
\n
"
,
new_handle
->
font_family
);
if
(
free_pool
)
{
switch_core_destroy_memory_pool
(
&
pool
);
}
*
handleP
=
NULL
;
return
SWITCH_STATUS_FALSE
;
}
new_handle
->
font_size
=
font_size
;
new_handle
->
font_size
=
font_size
;
new_handle
->
angle
=
angle
;
new_handle
->
angle
=
angle
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论