Ask Your Question
7

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

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

Maria Dimashova gravatar image

updated 2015-09-05 03:57:38 -0500

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
4

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

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 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

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

Seen: 1,397 times

Last updated: Jun 27 '12