提交 c77153b0 authored 作者: blu's avatar blu

init

上级 377d0ee2
...@@ -203,11 +203,11 @@ namespace DB { ...@@ -203,11 +203,11 @@ namespace DB {
// ipc: id, user, passwd, addr, status // ipc: id, user, passwd, addr, status
// ex: 1, admin, FWBWTU, 172.31.0.51, 0 // ex: 1, admin, FWBWTU, 172.31.0.51, 0
// evmgr: iid integer, cid <id_of_ipc>, addr text, status // evmgr: iid integer, sn, cid <id_of_ipc>, addr text, status
// evpuller: iid, cid <id_of_ipc>, addr, pub, rep, status; // evpuller: iid, sn, cid <id_of_ipc>, addr, pub, rep, status;
// evpusher: iid, pid <id_of_puller>, urldest, enabled, status; // evpusher: iid, sn, pid <id_of_puller>, urldest, enabled, status;
// evslicer: iid, pid, urldest, days, miniutes, status; // evslicer: iid, sn, pid, urldest, days, miniutes, status;
// evml: iid, pid, cls, enabled, status // evml: iid, sn, pid, cls, enabled, status
// //
// //
......
...@@ -23,6 +23,12 @@ namespace fs = std::filesystem; ...@@ -23,6 +23,12 @@ namespace fs = std::filesystem;
using namespace std; using namespace std;
#define URLOUT_DEFAULT "frames" #define URLOUT_DEFAULT "frames"
#define DEBUG
#ifdef DEBUG
// TODO: remove me
cv::Mat matShow1, matShow2, matShow3;
#endif
class EvMLMotion: public TinyThread { class EvMLMotion: public TinyThread {
private: private:
...@@ -248,7 +254,8 @@ private: ...@@ -248,7 +254,8 @@ private:
if (response < 0) { if (response < 0) {
spdlog::error("Error while receiving a frame from the decoder: {}", av_err2str(response)); spdlog::error("Error while receiving a frame from the decoder: {}", av_err2str(response));
return response; return response;
} else { }
else {
spdlog::info( spdlog::info(
"Frame {} (type={}, size={} bytes) pts {} key_frame {} [DTS {}]", "Frame {} (type={}, size={} bytes) pts {} key_frame {} [DTS {}]",
pCodecContext->frame_number, pCodecContext->frame_number,
...@@ -259,19 +266,71 @@ private: ...@@ -259,19 +266,71 @@ private:
pFrame->coded_picture_number pFrame->coded_picture_number
); );
// save a grayscale frame into a .pgm file // save a grayscale frame into a .pgm file
// string name = urlOut + "/"+ to_string(chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count()) + ".pgm"; // string name = urlOut + "/"+ to_string(chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count()) + ".pgm";
detectMotion(pFrame); detectMotion(pCodecContext->pix_fmt,pFrame);
} }
spdlog::debug("ch4"); spdlog::debug("ch4");
} }
return 0; return 0;
} }
void detectMotion(AVFrame *pFrame) void detectMotion(AVPixelFormat format,AVFrame *pFrame)
{ {
static bool first = true;
static cv::Mat avg;
static vector<vector<cv::Point> > cnts;
cv::Mat origin, gray, thresh;
avcvhelpers::frame2mat(format, pFrame, origin);
cv::resize(origin, gray, cv::Size(500,500));
cv::cvtColor(gray, thresh, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(thresh, gray, cv::Size(21, 21), cv::THRESH_BINARY);
if(first) {
// avg = cv::Mat::zeros(gray.size(), CV_32FC3);
avg = gray.clone();
first = false;
return;
}
#ifdef DEBUG
matShow3 = gray.clone();
#endif
// TODO: AVG
// cv::accumulateWeighted(gray, avg, 0.5);
cv::absdiff(gray, avg, thresh);
#ifdef DEBUG
avg = gray.clone();
#endif
// TODO:
cv::threshold(thresh, gray, 25, 255, cv::THRESH_BINARY);
cv::dilate(gray, thresh, cv::Mat(), cv::Point(-1,-1), 2);
#ifdef DEBUG
matShow1 = thresh.clone();
#endif
cv::findContours(thresh, cnts, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
bool hasEvent = false;
for(int i =0; i < cnts.size(); i++) {
// TODO:
if(cv::contourArea(cnts[i]) < 200) {
// nothing
}
else {
hasEvent = true;
#ifdef DEBUG
cv::putText(origin, "motion detected", cv::Point(10, 20), cv::FONT_HERSHEY_SIMPLEX, 0.75, cv::Scalar(0,0,255),2);
#endif
break;
}
}
#ifdef DEBUG
matShow2 = origin;
#endif
} }
protected: protected:
void run() void run()
...@@ -316,17 +375,20 @@ protected: ...@@ -316,17 +375,20 @@ protected:
if (packet.stream_index == streamIdx) { if (packet.stream_index == streamIdx) {
spdlog::debug("AVPacket.pts {}", packet.pts); spdlog::debug("AVPacket.pts {}", packet.pts);
// TODO
if(pktCnt < 18*5) {
continue;
}
ret = decode_packet(&packet, pCodecCtx, pFrame); ret = decode_packet(&packet, pCodecCtx, pFrame);
if (ret < 0)
break;
} }
av_frame_free(&pFrame);
av_packet_unref(&packet); av_packet_unref(&packet);
if (ret < 0) { if (ret < 0) {
spdlog::error("error muxing packet"); spdlog::error("error muxing packet");
} }
} }
av_frame_free(&pFrame);
} }
public: public:
EvMLMotion() EvMLMotion()
...@@ -342,6 +404,25 @@ int main(int argc, const char *argv[]) ...@@ -342,6 +404,25 @@ int main(int argc, const char *argv[])
{ {
spdlog::set_level(spdlog::level::debug); spdlog::set_level(spdlog::level::debug);
EvMLMotion es; EvMLMotion es;
#ifdef DEBUG
// TODO: remove
cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );
es.detach();
// TODO: remove me
this_thread::sleep_for(chrono::seconds(5));
while(true) {
cv::imshow("evmlmotion1", matShow1);
cv::imshow("evmlmotion2", matShow2);
cv::imshow("evmlmotion3", matShow3);
if(cv::waitKey(200) == 27) {
break;
}
}
#else
es.join(); es.join();
#endif
return 0; return 0;
} }
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论