本文介绍了在cv2 python中克隆图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是opencv的新手,这是一个问题,与cpp中的cv :: clone()相同的python函数是什么?我只是想通过

I'm new to opencv, here is a question, what is the python function which act the same as cv::clone() in cpp?I just try to get a rect by

    rectImg = img[10:20, 10:20]

但是当我在上面画一条线时,我发现这条线同时出现在img和rectImage上,所以,如何做到这一点?

but when I draw a line on it ,I find the line appear both on img and the rectImage,so , how can I get this done?

推荐答案

如果使用cv2,则正确的方法是在Numpy中使用.copy()方法.它将创建您需要的阵列的副本.否则,它将仅生成该对象的视图.

If you use cv2, correct method is to use .copy() method in Numpy. It will create a copy of the array you need. Otherwise it will produce only a view of that object.

例如:

In [1]: import numpy as np

In [2]: x = np.arange(10*10).reshape((10,10))

In [4]: y = x[3:7,3:7].copy()

In [6]: y[2,2] = 1000

In [8]: 1000 in x
Out[8]: False     # see, 1000 in y doesn't change values in x, parent array.

这篇关于在cv2 python中克隆图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 17:17