OpenCV:从文件夹中读取图像系列(OpenCV: Reading image series from a folder)
我正尝试使用OpenCV的
VideoCapture
功能从文件夹读取一系列图像。 在互联网上进行一些搜索之后,我目前的代码是这样的:cv::VideoCapture cap ( "C:\\Users\\Admin\\Documents\\Images\\%02d.jpg");
我期待看到
VideoCapture
函数应该读取该文件夹中的所有图像,其中包含两个连续数字的名称,如01.jpg, 02.jpg, ..., 30.jpg
。 有人在互联网上说,一旦我给出第一张图片的位置和名称,VideoCapture
功能应该可以捕捉所有这些图像。 所以我也试图这样做:cv::VideoCapture cap ("C:\\Users\\Admin\\Documents\\Images\\01.jpg");
但这仍然没有用,至少不是我的情况。 这些图像具有不同的大小,因此我将首先阅读它们,调整它们的大小,然后对它们进行进一步处理。 我怎样才能做到这一点? 我正在使用Windows7和VisualStudio。 谢谢。
I am trying to read a series of images from a folder using OpenCV's
VideoCapture
function. After some search on the internet, my current code is like this:cv::VideoCapture cap ( "C:\\Users\\Admin\\Documents\\Images\\%02d.jpg");
I was expecting to see that
VideoCapture
function should read all the images in that folder with names of two serial digits, like01.jpg, 02.jpg, ..., 30.jpg
. Someone told on the internet that theVideoCapture
function should be ale to catch all of these images once I give the first image's location and name. So I also tried to do it like this:cv::VideoCapture cap ("C:\\Users\\Admin\\Documents\\Images\\01.jpg");
But still this is not working, at least not for my case here. These images are of different sizes, so I am going to read them first, resize them, and then do further processing on each of them. How can I do this? I am using Windows7, with VisualStudio. Thank you.
原文:https://stackoverflow.com/questions/16713258
最满意答案
您可以有效地设置CSR稀疏数组的元素,只要您不添加新的非零,只需通过使用元组下标数组即可:
i, j = zip(*pruneme) # assuming that pruneme is a python list m[i, j] = 0. m.eliminate_zeros()
这应该比构造两个数组快得多。
You can set elements of CSR sparse arrays efficiently, as long as you do not add new nonzeros, simply by subscripting the array with tuples:
i, j = zip(*pruneme) # assuming that pruneme is a python list m[i, j] = 0. m.eliminate_zeros()
That should be much faster than constructing two arrays.
相关问答
更多-
我不能说哪个最有效存储。 这将取决于您的数据。 我可以说,但是+=运算符可以工作,只是你不能依赖通常的数组广播规则: >>> m = sparse.lil_matrix((100,100)) >>> m[50:56,50:56]+=scipy.ones((6,6)) >>> m[50,50] #1.0 I can't say which is most efficient to store. It's going to depend on your data. I can say, however th ...
-
Scipy Sparse:SciPy / NumPy更新后的单一矩阵警告(Scipy Sparse: Singular Matrix Warning after SciPy/NumPy Update)[2024-05-03]
你以前的scipy版本很老,它使用umfpack来完成这项任务。 由于授权问题 (GPL与scipy不兼容,我认为umfpack在某些时候切换了许可证), 此lib已被删除 ,现在使用了superlu 。 许多人观察到速度减慢(和健壮性问题),但评估性能可能并不那么容易(超级可能也是快速和健壮的)。 请阅读本文 。 你可能有两个选择: 调整superlu的参数(阅读官方superlu文档和scipy关于如何传递这些选项的文档) 转轴和订购非常重要! 还有一个对称模式 (不是真正的高度调整的对称矩阵求解器,但 ... -
scipy大型稀疏矩阵(scipy large sparse matrix)[2022-03-18]
这是由scipy.sparse.rand()的实现方式scipy.sparse.rand()的限制。 你可以推出自己的随机矩阵生成来绕过这个限制: n = 10 ** 5 density = 1e-3 ij = numpy.random.randint(n, size=(2, n * n * density)) data = numpy.random.rand(n * n * density) matrix = scipy.sparse.coo.coo_matrix((data, ij), (n, n)) ... -
SciPy / numpy:只保留稀疏矩阵块的最大值(SciPy/numpy: Only keep maximum value of a sparse matrix block)[2022-05-07]
def keep_only_max(a,b,c,d): sub = x[a:b,c:d] z = np.max(sub) sub[sub < z] = 0 对于稀疏x , sub片适用于csr格式。 它不会像等效密度片那么快,但它会创建x的那部分副本。 我必须检查稀疏max函数。 但是我可以想象将sub转换为coo格式,对.data属性使用np.argmax ,并使用相应的row和col值构造一个具有相同形状但只有一个非零值的新矩阵。 如果你的块以规则的,不重叠的方式覆盖x ,我建议用spar ... -
在没有深究问题的情况下,您应该确保在Linux平台上使用64位体系结构上的64位构建。 在那里,本机“长”数据类型是64位大小(相反Windows,我相信)。 供参考,请参阅以下表格: http://www.unix.org/whitepapers/64bit.html ( - > LP64上长64位) http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models 编辑:也许我以前不够明确 - 在64位Windows上,经典的本地“长”数据 ...
-
如何在python / scipy中有效地组装大型稀疏矩阵(How to assemble large sparse matrices effectively in python/scipy)[2023-10-18]
我发布了对scipy邮件列表的回复; 堆栈溢出更容易访问,所以我也会在这里发布,尽管版本略有改进。 诀窍是使用IJV存储格式。 这是三个阵列的三个,其中第一个包含行指示,第二个包含列指示,第三个具有该位置的矩阵值。 这是建立有限元素矩阵(或者我认为的任何稀疏矩阵)的最佳方法,因为对这种格式的访问非常快(只是填充一个数组)。 在scipy中,这称为coo_matrix ; 该类将三个数组作为参数。 它实际上只对转换为快速线性代数的另一种格式(CSR os CSC)很有用。 对于有限元,您可以通过类似的方式估计 ... -
下面的示例遍历lil_matrix并计算每行的总和。 注意我没有声明,即使它非常快, 因为Cython已经针对内置类型(如列表)进行了优化 。 时间也如下所示...... import time import numpy as np cimport numpy as np from scipy.sparse import lil_matrix cdef iter_over_lil_matrix(m): cdef list sums, data_row sums = [] for ...
-
有效地将大量SciPy稀疏矩阵条目设置为零(efficiently set a large number of SciPy sparse matrix entries to zero)[2022-01-24]
您可以有效地设置CSR稀疏数组的元素,只要您不添加新的非零,只需通过使用元组下标数组即可: i, j = zip(*pruneme) # assuming that pruneme is a python list m[i, j] = 0. m.eliminate_zeros() 这应该比构造两个数组快得多。 You can set elements of CSR sparse arrays efficiently, as long as you do not add new nonzeros, simp ... -
在CSC格式中,您有两个可写属性, data和indices ,它们保存矩阵的非零条目和相应的行索引。 您可以使用以下优势: def sparse_row_normalize(sps_mat) : if sps_mat.format != 'csc' : msg = 'Can only row-normalize in place with csc format, not {0}.' msg = msg.format(sps_mat.format) r ...
-
首先让我们构建一个随机的COO矩阵: import numpy as np from scipy import sparse x = sparse.rand(10000, 10000, format='coo') 非零值可以在矩阵的.data属性中找到,您可以使用x.nonzero()获取相应的行/列索引: v = x.data r, c = x.nonzero() print np.all(x.todense()[r, c] == v) # True 使用COO矩阵,可以使用getrow() / ...