简体   繁体   English

opencv中的这个陈述是什么意思?

[英]What does this statement in opencv mean?

k this is kind of noob of me since I really haven't worked on C and objective c all that much. k这是我的菜鸟,因为我真的没有在C和目标c上做过那么多。

Mat mymat(myIplImage, true);

This apparently not only declares mymat as a local variable but also copies the contents over from myIplImage. 这显然不仅将mymat声明为局部变量,还将内容从myIplImage复制。 The problems I can't make of the syntax. 我无法解决语法问题。 I would be more comfortable if it were something like this: 如果它是这样的话我会更舒服:

Mat mymat = new Mat(myIplImage, true); // in c++

Can you explain what happened in the background for the original statement? 你能解释原始陈述背景中发生的事情吗?

Thanks, 谢谢,

This is C++ actually. 实际上这是C ++。 The first statement does basically the same thing as the second statement except that you don't handle the memory yourself, that is you don't have to delete mymat when you don't need it anymore, it will be destructed automatically when it goes out of scope. 第一个语句基本上与第二个语句完全相同,只是你自己没有处理内存,也就是你不再需要delete mymat时,它会自动被破坏。超出范围。

As stated by Simon, the first version handles the memory allocation for you. 正如Simon所说,第一个版本为您处理内存分配。 In the first version, behind the scenes, there's probably a new call or malloc or something similar in the constructor, and a delete or free call in the destructor for Mat. 在第一个版本中,在幕后,可能在构造函数中有一个new调用或malloc或类似的东西,以及在Mat的析构函数中的deletefree调用。 That way, if you're just making one Mat (as opposed to an array of them), you don't need to think much about the allocation. 这样,如果你只是制作一个Mat(而不是它们的数组),你不需要考虑分配。

Keep in mind you can always look at the source for the Mat constructor or any other portions of OpenCV if you ever want to get all the nitty gritty details. 请记住,如果您想获得所有细节,可以随时查看Mat构造函数的源代码或OpenCV的任何其他部分。

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

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