moved rgb2grey

This commit is contained in:
JCC 2016-06-17 03:06:25 +02:00
parent 41e1ec9f2e
commit 5a08849467

View file

@ -61,6 +61,10 @@ class Traite_image {
cv::Mat next; cv::Mat next;
resize(input, next, cv::Size(input.size().width/resize_f, input.size().height/resize_f)); resize(input, next, cv::Size(input.size().width/resize_f, input.size().height/resize_f));
cv::Mat output; cv::Mat output;
next.copyTo(output);
cv::cvtColor(next, next, cv::COLOR_BGR2GRAY);
if (first) { if (first) {
for (int i = 0; i < NB_FRAME_DROP; ++i) { for (int i = 0; i < NB_FRAME_DROP; ++i) {
prevs.push_back(next.clone()); prevs.push_back(next.clone());
@ -90,11 +94,7 @@ class Traite_image {
prevs.insert(prevs.begin(), next.clone()); prevs.insert(prevs.begin(), next.clone());
} }
void stabiliseImg(cv::Mat prev, cv::Mat cur, cv::Mat &output){ void stabiliseImg(cv::Mat prev_grey, cv::Mat cur_grey, cv::Mat &output){
cv::Mat cur_grey, prev_grey;
cv::cvtColor(cur, cur_grey, cv::COLOR_BGR2GRAY);
cv::cvtColor(prev, prev_grey, cv::COLOR_BGR2GRAY);
// vector from prev to cur // vector from prev to cur
vector <cv::Point2f> prev_corner, cur_corner; vector <cv::Point2f> prev_corner, cur_corner;
vector <cv::Point2f> prev_corner2, cur_corner2; vector <cv::Point2f> prev_corner2, cur_corner2;
@ -119,14 +119,10 @@ class Traite_image {
} }
T.copyTo(last_T); T.copyTo(last_T);
cv::warpAffine(cur, output, T, cur.size(),cv::INTER_CUBIC|cv::WARP_INVERSE_MAP); cv::warpAffine(cur_grey, output, T, cur_grey.size(),cv::INTER_CUBIC|cv::WARP_INVERSE_MAP);
} }
void searchForMovement(cv::Mat prev, cv::Mat cur, cv::Mat &output, cv::Mat &out2){ void searchForMovement(cv::Mat prev_grey, cv::Mat cur_grey, cv::Mat &output, cv::Mat &out2){
cv::Mat cur_grey, prev_grey;
cur.copyTo(output);
cv::cvtColor(prev, prev_grey, cv::COLOR_BGR2GRAY);
cv::cvtColor(cur, cur_grey, cv::COLOR_BGR2GRAY);
cv::GaussianBlur(prev_grey, prev_grey, cv::Size(BLUR_SIZE,BLUR_SIZE), 3.0); cv::GaussianBlur(prev_grey, prev_grey, cv::Size(BLUR_SIZE,BLUR_SIZE), 3.0);
cv::GaussianBlur(cur_grey, cur_grey, cv::Size(BLUR_SIZE,BLUR_SIZE), 3.0); cv::GaussianBlur(cur_grey, cur_grey, cv::Size(BLUR_SIZE,BLUR_SIZE), 3.0);
@ -166,17 +162,17 @@ class Traite_image {
} }
vector<cv::Rect> c_rects; // Connected rectangles vector<cv::Rect> c_rects; // Connected rectangles
cleanBBoxes(nc_rects, cur.size(), c_rects); cleanBBoxes(nc_rects, cur_grey.size(), c_rects);
if (c_rects.size() > 0) { if (c_rects.size() > 0) {
for (const auto& rect : c_rects) for (const auto& rect : c_rects)
cv::rectangle(output, rect, cv::Scalar(0, 255, 0), 2); cv::rectangle(output, rect, cv::Scalar(0, 255, 0), 2);
cv::Rect objBRect = c_rects.front(); cv::Rect objBRect = c_rects.front();
papillon::BoundingBox bbox = papillon::BoundingBox(); papillon::BoundingBox bbox = papillon::BoundingBox();
bbox.x = objBRect.x / (float)cur.size().width; bbox.x = objBRect.x / (float)cur_grey.size().width;
bbox.y = objBRect.y / (float)cur.size().height; bbox.y = objBRect.y / (float)cur_grey.size().height;
bbox.width = objBRect.width / (float)cur.size().width; bbox.width = objBRect.width / (float)cur_grey.size().width;
bbox.height = objBRect.height / (float)cur.size().height; bbox.height = objBRect.height / (float)cur_grey.size().height;
pub_cmd.publish(bbox); pub_cmd.publish(bbox);
} }
} }