I'm dealing with OpenCV and have some memory management questions from their DFT example code.
1 In openCV, what's the most efficient way of creating a two channel image? The linked code seems to allocate two IplImages and then combine them via
cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);
I this this m开发者_Python百科ay make a deep copy to combine the two images, which is a waste of two images.
2 Also, what's the best way of splitting a matrix into two parts? The linked to code uses
cvSplit( dft_A, image_Re, image_Im, 0, 0 );
but I think this may keep separate copies of the data in dft_A and image_Re/image_Im (another waste of two images)
Thanks!
PS I know the code linked to doesn't release it's used memory...that will be fixed soon
PPS I could test this directly, but I would like to learn how I can figure this out from the docs instead.
Opencv does quite a bit of clever memory management to avoid unnecessary copies. It often makes sense to write the simple niave solution and then profile to check if it needs or can be improved.
See http://opencv.willowgarage.com/documentation/cpp/memory_management.html
Merge may be very efficient if the destination image is planer - if it is flat then the individual real and imaginary values are all going to have to be copied anyway.
精彩评论