OpenCV =运算子

编程入门 行业动态 更新时间:2024-10-21 12:44:03
本文介绍了OpenCV =运算子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发OpenCV,但感到困惑.我通过了链接,但我不太理解OpenCV中'='运算符的概念.

I am working on OpenCV and I have a confusion. I went through this link and I did not quite understand the concept of '=' operator in OpenCV.

假设我声明3个矩阵,如下所示:

Suppose I declare 3 Matrices as follows:

Mat img1, img2, gray;

如果我从相机拍摄的图像中获取矩阵gray并将其分配给img1,如下所述,实际上会发生什么?是将gray中的数据复制到img1还是在它们之间共享数据?

If I obtain the matrix gray from the image captured from the camera and assign it to img1 as mentioned below, what actually happens? Does the data in gray get copied to img1 or is it that data is shared between them?

img1 = gray;

推荐答案

OpenCV的Mat类只是实际图像数据的 header ,它包含一个指向的指针. =运算符复制指针(以及标题中的其他信息,如图像尺寸),以便两个Mat共享相同的数据.这意味着修改一个Mat中的数据也会更改另一个Mat中的数据.之所以称为浅"副本,是因为仅复制顶层(标头),而不复制底层(数据).

OpenCV's Mat class is simply a header for the actual image data, which it contains a pointer to. The = operator copies the pointer (and the other information in the header, like the image dimensions) so that both Mats share the same data. This means that modifying the data in one Mat also changes it in the other. This is called a "shallow" copy, since only the top layer (the header) is copied, not the lower layer (the data).

要复制基础数据(称为深层复制"),请使用clone()方法.您可以在链接到的页面上找到有关它的信息.

To make a copy of the underlying data (called a "deep copy"), use the clone() method. You can find information about it on the page that you linked to.

更多推荐

OpenCV =运算子

本文发布于:2023-10-14 22:19:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:OpenCV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!