Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
9a6c3684
提交
9a6c3684
authored
8月 22, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
0c2c96ea
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
188 行增加
和
0 行删除
+188
-0
avcvhelpers.hpp
opencv-motion-detect/inc/avcvhelpers.hpp
+87
-0
zmqhelper.hpp
opencv-motion-detect/inc/zmqhelper.hpp
+101
-0
opencv-motiondetect.cpp
opencv-motion-detect/opencv-motiondetect.cpp
+0
-0
没有找到文件。
opencv-motion-detect/inc/avcvhelpers.hpp
0 → 100644
浏览文件 @
9a6c3684
#ifndef __AVCVHELPERS_H__
#define __AVCVHELPERS_H__
extern
"C"
{
#include <libswscale/swscale.h>
#include <libavformat/avformat.h>
}
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc.hpp>
#include <map>
using
namespace
std
;
namespace
avcvhelpers
{
// AVFrame mat2frame(cv::Mat* frame)
// {
// // TODO.
// AVFrame dst;
// // cv::Size frameSize = frame->size();
// // AVCodec *encoder = avcodec_find_encoder(AV_CODEC_ID_RAWVIDEO);
// // AVFormatContext* outContainer = avformat_alloc_context();
// // AVStream *outStream = avformat_new_stream(outContainer, encoder);
// // // outStream->codec->pix_fmt = AV_PIX_FMT_BGR24;
// // outStream->codecpar->format = AV_PIX_FMT_BGR24;
// // outStream->codecpar->width = frame->cols;
// // outStream->codecpar->height = frame->rows;
// // avpicture_fill((AVPicture*)&dst, frame->data, AV_PIX_FMT_BGR24, outStream->codecpar->width, outStream->codecpar->height);
// // dst.width = frameSize.width;
// // dst.height = frameSize.height;
// return dst;
// }
// struct Point {
// int format;
// int width;
// int height;
// bool operator==(Point const &other) {
// return format == other.format && width == other.width && height == other.height;
// }
// size_t operator()(Point const &pt) {
// size_t h = hash<int>{}(pt.format);
// h ^= (hash<int>{}(pt.width) <<1);
// h ^= (hash<int>{}(pt.height) <<1);
// return h;
// }
// };
void
frame2mat
(
AVPixelFormat
format
,
const
AVFrame
*
frame
,
cv
::
Mat
&
image
)
{
int
width
=
frame
->
width
;
int
height
=
frame
->
height
;
// Allocate the opencv mat and store its stride in a 1-element array
if
(
image
.
rows
!=
height
||
image
.
cols
!=
width
||
image
.
type
()
!=
CV_8UC3
)
{
image
=
cv
::
Mat
(
height
,
width
,
CV_8UC3
);
}
int
cvLinesizes
[
1
];
cvLinesizes
[
0
]
=
image
.
step1
();
// Convert the colour format and write directly to the opencv matrix
// TODO: optimization
switch
(
format
)
{
case
AV_PIX_FMT_YUVJ420P
:
format
=
AV_PIX_FMT_YUV420P
;
break
;
case
AV_PIX_FMT_YUVJ422P
:
format
=
AV_PIX_FMT_YUV422P
;
break
;
case
AV_PIX_FMT_YUVJ444P
:
format
=
AV_PIX_FMT_YUV444P
;
break
;
case
AV_PIX_FMT_YUVJ440P
:
format
=
AV_PIX_FMT_YUV440P
;
break
;
default
:
;
}
SwsContext
*
conversion
=
sws_getContext
(
width
,
height
,
(
AVPixelFormat
)
format
,
width
,
height
,
AVPixelFormat
::
AV_PIX_FMT_BGR24
,
SWS_FAST_BILINEAR
,
NULL
,
NULL
,
NULL
);
sws_scale
(
conversion
,
frame
->
data
,
frame
->
linesize
,
0
,
height
,
&
image
.
data
,
cvLinesizes
);
sws_freeContext
(
conversion
);
}
}
#endif
opencv-motion-detect/inc/zmqhelper.hpp
0 → 100644
浏览文件 @
9a6c3684
#ifndef __ZMQ_HELPER_H__
#define __ZMQ_HELPER_H__
#include "zmq.h"
#include <vector>
#include <spdlog/spdlog.h>
using
namespace
std
;
namespace
zmqhelper
{
#define EV_HEARTBEAT_SECONDS 30
#define MSG_HELLO "hello"
#define EV_MSG_META_PING "ping"
#define EV_MSG_META_PONG "pong"
#define EV_MSG_META_PEEROFFLINE "offline"
#define EV_MSG_META_RESTART "restart"
#define EV_MSG_META_UPDATE "update"
#define EV_MSG_META_EVENT "event"
#define EV_MSG_META_AVFORMATCTX "afctx"
#define EV_NUM_CACHE_PERPEER 100
//
string
body2str
(
vector
<
uint8_t
>
body
){
return
string
((
char
*
)(
body
.
data
()),
body
.
size
());
}
vector
<
uint8_t
>
data2body
(
char
*
data
,
int
len
){
vector
<
uint8_t
>
v
;
v
.
insert
(
v
.
end
(),
(
uint8_t
*
)
data
,
(
uint8_t
*
)
data
+
len
);
return
v
;
}
vector
<
uint8_t
>
str2body
(
string
const
&
str
){
vector
<
uint8_t
>
v
;
v
.
insert
(
v
.
end
(),
(
uint8_t
*
)(
str
.
data
()),
(
uint8_t
*
)(
str
.
data
())
+
str
.
size
());
return
v
;
}
// proto: 1. on router [sender_id] [target_id] [body]
// 2. on dealer [sender_id] [body]
vector
<
vector
<
uint8_t
>
>
z_recv_multiple
(
void
*
s
,
bool
nowait
=
false
)
{
int64_t
more
=
1
;
vector
<
vector
<
uint8_t
>
>
body
;
int
cnt
=
0
;
int
ret
=
0
;
while
(
more
>
0
)
{
cnt
++
;
zmq_msg_t
msg
;
ret
=
zmq_msg_init
(
&
msg
);
if
(
ret
<
0
)
{
spdlog
::
debug
(
"failed to receive multiple msg on zmq_msg_init: {}"
,
zmq_strerror
(
zmq_errno
()));
break
;
}
ret
=
zmq_recvmsg
(
s
,
&
msg
,
nowait
?
ZMQ_DONTWAIT
:
0
);
if
(
ret
<
0
)
{
spdlog
::
debug
(
"z_recv_multiple: {}"
,
zmq_strerror
(
zmq_errno
()));
break
;
}
vector
<
uint8_t
>
v
;
v
.
insert
(
v
.
end
(),
(
uint8_t
*
)
zmq_msg_data
(
&
msg
),
(
uint8_t
*
)
zmq_msg_data
(
&
msg
)
+
ret
);
body
.
push_back
(
v
);
spdlog
::
debug
(
"z_rcv_multiple: {}"
,
body2str
(
v
).
substr
(
0
,
v
.
size
()
>
100
?
15
:
v
.
size
()));
zmq_msg_close
(
&
msg
);
size_t
more_size
=
sizeof
(
more
);
ret
=
zmq_getsockopt
(
s
,
ZMQ_RCVMORE
,
&
more
,
&
more_size
);
if
(
ret
<
0
)
{
spdlog
::
debug
(
"z_recv_multiple: {}"
,
zmq_strerror
(
zmq_errno
()));
break
;
}
}
return
body
;
}
// proto [sender_id(only when no identifier set in setsockopts)] [target_id] [body]
int
z_send_multiple
(
void
*
s
,
vector
<
vector
<
uint8_t
>
>&
body
)
{
int
cnt
=
0
,
ret
=
0
;
zmq_msg_t
msg
;
for
(
auto
&
i
:
body
)
{
ret
=
zmq_msg_init_size
(
&
msg
,
i
.
size
());
memcpy
(
zmq_msg_data
(
&
msg
),
(
void
*
)(
i
.
data
()),
i
.
size
());
spdlog
::
debug
(
"z_send_multiple: {}"
,
body2str
(
i
).
substr
(
0
,
i
.
size
()
>
100
?
15
:
i
.
size
()));
if
(
ret
<
0
)
{
spdlog
::
debug
(
"z_send_multiple: {}"
,
zmq_strerror
(
zmq_errno
()));
break
;
}
ret
=
zmq_msg_send
(
&
msg
,
s
,
cnt
==
(
body
.
size
()
-
1
)
?
0
:
(
ZMQ_SNDMORE
));
zmq_msg_close
(
&
msg
);
if
(
ret
<
0
)
{
spdlog
::
debug
(
"z_send_multiple: {}"
,
zmq_strerror
(
zmq_errno
()));
break
;
}
cnt
++
;
}
return
ret
;
}
}
#endif
\ No newline at end of file
opencv-motion-detect/opencv-motiondetect.cpp
0 → 100644
浏览文件 @
9a6c3684
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论