Ask Your Question
0

Efficiently passing Mat object in different classes

asked 2016-09-01 08:01:37 -0600

supertramp-sid gravatar image

updated 2016-09-01 08:03:12 -0600

I am currently doing a project which has around 6-7 classes and requires me to use an image across multiple classes.

The project code that I am referring to write my own code , does it by saving the image and loading it across different classes.

What doubt I have is
Is this method efficient or I should set class variables and clone the image for the other classes. Which one of them will be efficient.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-09-01 11:25:01 -0600

Tetragramm gravatar image

Assuming you need a separate copy in each, you should use .clone() to make copies. All clone does is a memcopy which might happen entirely within the CPU, whereas saving the image to disk involves multiple RAM and disk accesses. This should be obvious even in the simplest test.

edit flag offensive delete link more

Comments

"whereas saving the image to disk involves multiple RAM and disk accesses." You could write the file to a RamDisk which would already speed up the current implementation by just changing the directory.

FooBar gravatar imageFooBar ( 2016-09-02 00:39:30 -0600 )edit

You are right, there are faster ways than what he's doing. But that's because just about anything is faster than that. clone() is certainly the best way.

Tetragramm gravatar imageTetragramm ( 2016-09-02 07:54:34 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-01 08:01:37 -0600

Seen: 233 times

Last updated: Sep 01 '16