提交 41d16a7f authored 作者: blu's avatar blu

evmlmotion: resize image

上级 1bb03abb
......@@ -30,6 +30,7 @@ query configuration for edge device with specified sn
"evml":[
{
"area":200,
"resize": 0.5,
"enabled":1,
"iid":1,
"post":30,
......
......@@ -1180,13 +1180,13 @@ void cleanup(int signal)
gWatchDog.stop();
spdlog::info("evdaemon watchdog stopped, exiting");
while (waitpid((pid_t) (-1), 0, WNOHANG) > 0) {}
// while (waitpid((pid_t) (-1), 0, WNOHANG) > 0) {}
exit(signal);
}
int main()
{
signal(SIGCHLD, cleanup);
// signal(SIGCHLD, cleanup);
signal(SIGINT, cleanup);
signal(SIGTERM, cleanup);
signal(SIGKILL, cleanup);
......
......@@ -49,6 +49,7 @@ struct DetectParam {
int post;
float entropy;
int maxDuration; // max event video length in minutes
float resize; //
cv::Point2f region[2];
};
......@@ -68,7 +69,7 @@ private:
int iid;
AVFormatContext *pAVFormatInput = nullptr;
AVCodecContext *pCodecCtx = nullptr;
DetectParam detPara = {25, 500, -1, 3, 3, 30, 0.3, 25, {{0,0},{0,0}}};
DetectParam detPara = {25, 500, -1, 3, 3, 30, 0.3, 25, 0,{{0,0},{0,0}}};
EventState evtState = EventState::NONE;
// chrono::system_clock::time_point packetTm, evtStartTmLast, evtStartTmOrig;
long long packetTm = 0, evtStartTmLast = 0, evtStartTmOrig = 0, evtStartTmPre = 0;
......@@ -83,7 +84,7 @@ private:
bool gotFormat = false;
long long packetTs = 0;
long long packetTsDelta = 0;
float pps = 0, imgScalor = 1;
float pps = 0;
int pktLag = 0;
int fps = 0;
uint64_t pktCnt = 0;
......@@ -315,6 +316,18 @@ private:
detPara.maxDuration = evmlmotion["maxDuration"];
}
if(evmlmotion.count("resize") == 0|| !evmlmotion["resize"].is_number_float() ||evmlmotion["resize"] < 0 || evmlmotion["resize"] > 1) {
spdlog::info("{} invalid resize value. should be in [0, 1] as float value, default to {}", selfId, detPara.resize);
}
else {
detPara.resize = evmlmotion["resize"];
if(detPara.resize < 0.001) {
detPara.resize = 0;
}else if (detPara.resize > 0.99) {
detPara.resize = 1;
}
}
if(evmlmotion.count("region") != 0) {
json &region = evmlmotion["region"];
if(region.count("minX") == 0|| !region["minX"].is_number() ||
......@@ -593,6 +606,21 @@ private:
// check region
auto w = origin.size().width;
auto h = origin.size().height;
// auto config
if(detPara.resize == 0) {
detPara.resize = 540*1.0/h;
}
if(detPara.resize > 0 && detPara.resize < 1){
// resize. new w, h caculated
w = int(w * detPara.resize);
h = int(h * detPara.resize);
cv::resize(origin, origin, cv::Size(w,h));
}else{
detPara.resize = 1;
}
if(detPara.region[0].y == 0 || (detPara.region[0].x == 0 && detPara.region[0].y == 0 && detPara.region[1].x == 1 && detPara.region[1].y == 1)) {
// do nothing
}else {
......@@ -605,8 +633,6 @@ private:
origin = origin(crop);
}
// imgScalor = w * h / (FRAME_SIZE * FRAME_SIZE * 1.0);
// cv::resize(origin, gray, cv::Size(FRAME_SIZE,FRAME_SIZE));
cv::Mat gray;
cv::cvtColor(origin, gray, cv::COLOR_BGR2GRAY);
// float fent = avcvhelpers::getEntropy(thresh);
......@@ -616,7 +642,7 @@ private:
avg.release();
avg = gray.clone();
first = false;
spdlog::info("{} imgScalor: {}, area: {}", selfId, imgScalor, detPara.area * imgScalor);
spdlog::info("{} resize: {}, area: {}, origin area: {}", selfId, detPara.resize, detPara.area * detPara.resize * detPara.resize, detPara.area);
return;
}
......@@ -646,9 +672,10 @@ private:
bool hasEvent = false;
static int evtCnt = 0;
int i = 0;
double area = (double)(detPara.area * imgScalor);
if(area < 10) {
area = 10;
static double area = (double)(detPara.area * detPara.resize * detPara.resize);
// avoid vage cases
if(area < 5) {
area = 5;
}
for(; i < cnts.size(); i++) {
_area = cv::contourArea(cnts[i]);
......@@ -877,8 +904,8 @@ protected:
static int _fpsDetectCnt = 0;
static auto _pts = packet.pts;
if(pAVFormatInput->streams[packet.stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && this->fps == 0){
// static auto num = pAVFormatInput->streams[packet.stream_index]->time_base.num;
if(pAVFormatInput->streams[packet.stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && (this->fps == 0|| pktCnt % 250 == 0)){
// static auto num = pAVFormatInput->streams[packet.stream_index]->time_base.num;s
// static auto den = pAVFormatInput->streams[packet.stream_index]->time_base.den;
// _fpsDetectCnt++;
// if(_fpsDetectCnt < 20){
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论