提交 1c6376e9 authored 作者: blu's avatar blu

evml: crop image

上级 4c46c897
...@@ -309,21 +309,25 @@ private: ...@@ -309,21 +309,25 @@ private:
detPara.maxDuration = evmlmotion["maxDuration"]; detPara.maxDuration = evmlmotion["maxDuration"];
} }
if(evmlmotion.count("region") == 0|| !evmlmotion["maxDuration"].is_object()) { if(evmlmotion.count("region") == 0|| !evmlmotion["region"].is_object()) {
json &region = evmlmotion["region"]; json &region = evmlmotion["region"];
if((region.count("center") == 0|| !region["center"].is_array()) || (region.count("wh") == 0||!region["wh"].is_array())){ if(region.count("minX") == 0|| !region["minX"].is_number() ||
region.count("minY") == 0||!region["minY"].is_number() ||
region.count("maxX") == 0||!region["maxX"].is_number() ||
region.count("maxY") == 0||!region["maxY"].is_number()){
spdlog::error("evmlmotion {} invalid region config: format. ignored", selfId); spdlog::error("evmlmotion {} invalid region config: format. ignored", selfId);
}else{ }else{
cv::Point2f p1, p2; cv::Point2f p1, p2;
const float EVML_MARGIN_F = 0.0001; const float EVML_MARGIN_F = 0.0001;
try{ try{
p1.x = region["center"][0]; p1.x = region["minX"].get<float>();
p1.y = region["center"][1]; p1.y = region["minY"].get<float>();
p2.x = region["wh"][0]; p2.x = region["maxX"].get<float>();
p2.y = region["wh"][1]; p2.y = region["maxY"].get<float>();
if((p1.x - p2.x/2) < EVML_MARGIN_F || (p1.x + p2.x/2) > (1 - EVML_MARGIN_F) ||
(p1.y - p2.y/2) < EVML_MARGIN_F || (p1.y + p2.y/2) > (1 - EVML_MARGIN_F)) { if(p1.x < 0 || p1.x>=1 || p1.y <=0 || p1.y > 1||
spdlog::error("evmlmotion {} invalid region config: valid exceeding. ignored", selfId); p2.x <=0 || p2.x > 1 || p2.y <=0 || p2.y >1 || p1.x < p2.x || p1.y < p2.y) {
spdlog::error("evmlmotion {} invalid region config: invalid value range. ignored", selfId);
}else{ }else{
detPara.region[0] = p1; detPara.region[0] = p1;
detPara.region[1] = p2; detPara.region[1] = p2;
...@@ -594,16 +598,16 @@ private: ...@@ -594,16 +598,16 @@ private:
cv::Mat origin, gray, thresh; cv::Mat origin, gray, thresh;
avcvhelpers::frame2mat(format, pFrame, origin); avcvhelpers::frame2mat(format, pFrame, origin);
// check region // check region
if(detPara.region[0].x == 0) { if(detPara.region[0].y == 0) {
// do nothing // do nothing
}else { }else {
// crop // crop
auto w = origin.size().width; auto w = origin.size().width;
auto h = origin.size().height; auto h = origin.size().height;
auto x = (int)(w * (detPara.region[0].x - detPara.region[1].x/2)); auto x = (int)(w * detPara.region[0].x);
auto y = (int)(h * (detPara.region[0].y - detPara.region[1].y/2)); auto y = (int)(h * detPara.region[0].y);
w = w * detPara.region[1].x; w = w * (detPara.region[1].x - detPara.region[0].x);
h = h * detPara.region[1].y; h = h * (detPara.region[1].y - detPara.region[0].y);
cv::Rect crop(x,y,w,h); cv::Rect crop(x,y,w,h);
origin = origin(crop); origin = origin(crop);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论