Ask Your Question
8

Do all opencv functions support in-place mode for their arguments?

asked 2012-06-27 06:26:43 -0600

Maria Dimashova gravatar image

updated 2020-11-01 02:00:01 -0600

in cases where this question arises.

For example, should I write:

Mat img = imread(filename);
{ 
  Mat tmp;
  cvtColor(img, tmp, CV_BGR2Lab);
  img = tmp;
}

(not in-place variant)

or:

Mat img = imread(filename);
cvtColor(img, img, CV_BGR2Lab);

(in-place variant)?

If some functions do not support in-place mode, how can I know about this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
5

answered 2012-06-27 09:58:56 -0600

Vincent Rabaud gravatar image

The speed here should not be an issue: create an image is not much compared to all the operations happening in a function.

The in-place is just faster to write and the way to go provided you can get rid of your original matrix. Each OpenCV function that does/does not support in-place should be checking for it so the code will throw if you are doing something in-place and you cannot. The documentation should also highlight that.

If you find something undocumented and that works/does not work, please file an issue on http://code.opencv.org/

edit flag offensive delete link more

Comments

4

But please also note, that in the first example memory for the tmp matrix will be allocated, and not in the second example. Memory allocations are very expensive on mobile platforms, so we should avoid them, especially in loops.

Kirill Kornyakov gravatar imageKirill Kornyakov ( 2012-06-27 11:04:11 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2012-06-27 06:26:43 -0600

Seen: 5,666 times

Last updated: Jun 27 '12