简体   繁体   English

C / OpenCV内存管理

[英]C/OpenCV Memory Management

I'm dealing with OpenCV and have some memory management questions from their DFT example code . 我正在处理OpenCV,并且从其DFT示例代码中有一些内存管理问题。

1 In openCV, what's the most efficient way of creating a two channel image? 1在openCV中,创建两通道图像的最有效方法是什么? The linked code seems to allocate two IplImages and then combine them via 链接的代码似乎分配了两个IplImage,然后通过

    cvMerge(realInput, imaginaryInput, NULL, NULL, complexInput);

I this this may 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? 2另外,将矩阵分为两部分的最佳方法是什么? 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) 但是我认为这可能会将数据的单独副本保留在dft_A和image_Re / image_Im中(另一个浪费了两个图像)

Thanks! 谢谢!

PS I know the code linked to doesn't release it's used memory...that will be fixed soon PS我知道链接到的代码不会释放它的用过的内存...很快就会修复

PPS I could test this directly, but I would like to learn how I can figure this out from the docs instead. PPS我可以直接对此进行测试,但是我想学习如何从文档中找出答案。

Opencv does quite a bit of clever memory management to avoid unnecessary copies. Opencv做了很多聪明的内存管理,以避免不必要的复制。 It often makes sense to write the simple niave solution and then profile to check if it needs or can be improved. 编写简单的niave解决方案,然后进行概要分析以检查是否需要或可以改进通常是有意义的。

See http://opencv.willowgarage.com/documentation/cpp/memory_management.html 参见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. 如果目标图像是平面的,则合并可能非常有效-如果目标图像是平面的,则无论如何都必须复制各个实数值和虚数值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM