Skip to content

Remove copies in image and video implementation#104

Merged
luisremis merged 1 commit intodevelopfrom
optimize_image_video_impl
May 17, 2019
Merged

Remove copies in image and video implementation#104
luisremis merged 1 commit intodevelopfrom
optimize_image_video_impl

Conversation

@luisremis
Copy link
Copy Markdown
Contributor

Optimized video and image code, avoiding copies of cvmats. This increase performance of video read and several image operations by up to 25%.

@vishakha041
Copy link
Copy Markdown
Contributor

I don't see new tests for checking the copy parameters. Are our current tests sufficient to make sure we are not losing image content anywhere? Our typical checks involve metadata verification. I guess that concern applies to the old code too but just thought of it now.

@vishakha041
Copy link
Copy Markdown
Contributor

What are the pros/cons of merging the ImageData/Image classes? That code was reviewed well back when and this change kind of breaks consistency across how video and descriptors were structured. Is that not true?

@luisremis luisremis force-pushed the optimize_image_video_impl branch from ea80b48 to 48bd510 Compare May 10, 2019 19:00
@luisremis
Copy link
Copy Markdown
Contributor Author

What are the pros/cons of merging the ImageData/Image classes? That code was reviewed well back when and this change kind of breaks consistency across how video and descriptors were structured. Is that not true?

These changes have been moved to another branch and will be part of a future pull request

@luisremis
Copy link
Copy Markdown
Contributor Author

luisremis commented May 10, 2019

I don't see new tests for checking the copy parameters. Are our current tests sufficient to make sure we are not losing image content anywhere? Our typical checks involve metadata verification. I guess that concern applies to the old code too but just thought of it now.

We have tests for both, the metadata an pixels. We have many tests that check every single pixel of the image and video and compare it with direct OpenCV results. The copies in the images are tests through the video implementation that is using those copy and move constructors.

All tests are passing.

vishakha041
vishakha041 previously approved these changes May 16, 2019
Copy link
Copy Markdown
Contributor

@vishakha041 vishakha041 left a comment

Choose a reason for hiding this comment

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

Just make sure it is thread safe and remove that all caps TODO comment. Rest looks fine.


Image::~Image()
{
delete _image;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just noticed. Is this never null? I think we talked about this but I am not remembering why there is no null check here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is never null.

_tdb = NULL;

int start;
// TODO IS THIS REALLY NEEDED????
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Its better to not have comments like that. Either you can resolve it or file an issue and remove the comment

_cv_type = cv_img.type();

_cv_img = cv_img.clone();
_cv_img = cv_img; // shallow copy
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Probably a silly question but is this still thread safe? That would be hard to catch with our tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

none of this is thread safe. these changes do not affect that.


for (auto& frame : frames) {
outputVideo << frame.get_cvmat();
outputVideo << frame.get_cvmat(false);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can see why the shallow copy would be important here!

* @return A new Image object that is only the requested area
*/
Image get_area(const Rectangle &roi) const;
Image get_area(const Rectangle &roi);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

move this change to the remove layer PR


Image::~Image()
{
delete _image;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is never null.

* @return An OpenCV Mat
*/
cv::Mat get_cvmat() const;
cv::Mat get_cvmat(bool copy=false);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this should be true.

}
else {
img->copy_cv(cv::imread(_fullpath, cv::IMREAD_ANYCOLOR));
auto img_read = cv::imread(_fullpath, cv::IMREAD_ANYCOLOR);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cv::Mat

*/
Image(const cv::Mat &cv_img);

Image(cv::Mat &cv_img);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see if we can use a parameter instead

if (front->get_type() == OperationType::READ) {
start = 1;
copy_cv(cv::imread(img._image_id, cv::IMREAD_ANYCOLOR));
cv::Mat img_read = cv::imread(img._image_id, cv::IMREAD_ANYCOLOR);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

check if this hurts or not.

_cv_type = cv_img.type();

_cv_img = cv_img.clone();
_cv_img = cv_img; // shallow copy
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

none of this is thread safe. these changes do not affect that.

Copy link
Copy Markdown
Contributor Author

@luisremis luisremis left a comment

Choose a reason for hiding this comment

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

Comments during code review with @philiplantz

@luisremis luisremis force-pushed the optimize_image_video_impl branch 2 times, most recently from d3efb8a to 5184192 Compare May 17, 2019 23:33
@luisremis
Copy link
Copy Markdown
Contributor Author

All comments applied, all tests passing, noticeable improvement on video performance by avoing copies. Same should be good images that is now avoiding multiple copies. looks good to go!

@luisremis luisremis merged commit daacc52 into develop May 17, 2019
@luisremis luisremis deleted the optimize_image_video_impl branch July 2, 2019 20:35
cwlacewe added a commit to cwlacewe/vdms that referenced this pull request Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants