Ask Your Question
0

is resize a cpu intensive operation

asked 2016-09-08 17:29:04 -0500

atv gravatar image

Hi, Instead of doing a resize for different Mat variables, if i had a need anyway they are all to be the same size, could i not do once: resize(src,dst ...)

and then assign other Mat variables the same size by doing: fubar=dst

Would it help?

Thanks for your help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-08 18:57:05 -0500

Tetragramm gravatar image

Resize is moderate-low cost. But if you can resize once before you do a bunch of operations and make new copies, rather than resizing all of those copies, you probably should.

edit flag offensive delete link more

Comments

Thanks! Sorry for being obtuse - but how would i do this again? ( i believe it was something like fubar=dst(Mat, size(fubar) ?

Also, i think clone() is in that same region? Is there a way to get a single frame/screenshot from a Mat that contains a video/webcam stream? I don't really need the whole video. Currently i'm keeping a list of snapshots of user history that were recognised, but they are all moving as a copy of the video in stamp format. I just need a screenshot. I can't do cap << frame as that doesn't work on a regular Mat.

atv

atv gravatar imageatv ( 2016-09-09 01:18:46 -0500 )edit

Um? I don't entirely understand, but I think this is what you mean:

  • You are trying to save single frames from a video stream, but they keep changing.
  • You are assigning these variables by doing screenshot = frame;
  • You want to keep a copy of the frame as is.

To do that, you use the .clone() function as follows. Clone is very low cost in time. A single copy is as cheap as it gets.

screenshot = frame.clone();

With that, it makes a copy and screenshot will not change unless you do something to it. If you just use the = assignment, Mat makes a shallow copy, and any changes to one changes the other. Clone makes a deep copy, and changes to one do not affect the other.

Tetragramm gravatar imageTetragramm ( 2016-09-09 18:04:01 -0500 )edit

Hey Tetragramm, yes that's what i meant with clone(). I use that method now, i was just worried it might be cpu intensive and maybe there was an easier way. So i'm doing it the right way.

As for my the first part of my question, is there a way to resize a Mat, and then create a new Mat with the size of that other resized Mat (without actually calling resize again). I thought there was something like Mat fubar=(Mat bla.size(), ... )

Just trying to minimize amount of resize calls.

Thanks again

atv gravatar imageatv ( 2016-09-10 11:46:04 -0500 )edit

You need to take a look at the documentation. HERE is the Mat class, and as you can see, it has several constructors that let you specify size.

Tetragramm gravatar imageTetragramm ( 2016-09-10 12:09:26 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-09-08 17:29:04 -0500

Seen: 108 times

Last updated: Sep 08 '16