Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added cropping of capture/background #153

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
5 changes: 4 additions & 1 deletion app/background.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ int grab_background(std::shared_ptr<background_t> pbkd, int width, int height, c
} else {
// resize still image as requested into out
cv::Rect crop = calcCropping(pbkd->raw.cols, pbkd->raw.rows, width, height);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..as above, could be removed in favour of a state variable, calculated just once.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must think about that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must review this part.

Copy link
Author

@jjsarton jjsarton Sep 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have put the variable bg_stored into the structure background_t.
The code is now:

   } else {
   	if (!pbkd->bg_stored) {
   		// resize still image as requested into out
   		cv::Rect crop = bs_calc_cropping(pbkd->raw.cols, pbkd->raw.rows, width, height);
   		// Under some circumstances we must do the job in two steps!
   		// Otherwise this resize(pbkd->raw(crop), pbkd->raw, ...) may fail.
   		pbkd->raw(crop).copyTo(pbkd->raw);
   		cv::resize(pbkd->raw, pbkd->raw, cv::Size(width, height));
   		pbkd->bg_stored = true;
   	}
   	out = pbkd->raw;
   	frm = 1;
   }
   return frm;

For the video processing the code remain to the old code, we will probably every time read a new picture from the video source.

Please note that the changes are not effective now, the tests for video or still image don't work as required.
I propose to detect according to the value cnt which has the value -1 for still image and a greater value for video.
I have also changed the corresponding code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry too much about this, it's a minor performance enhancement to avoid a couple of floating point ops per frame, when we are running a whole inference model too.. I'd rather the code was readable than maximum speed 😄

cv::resize(pbkd->raw(crop), pbkd->raw, cv::Size(width, height));
// under some circumstances we must do the job with 2 step!
// without this resize(pbkd->raw(crop), pbkd->raw, ...) may fail.
jjsarton marked this conversation as resolved.
Show resolved Hide resolved
cv::resize(pbkd->raw(crop), out, cv::Size(width, height));
pbkd->raw = out;
frm = 1;
}
return frm;
Expand Down