首页 \ 问答 \ OpenCV:从文件夹中读取图像系列(OpenCV: Reading image series from a folder)

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, like 01.jpg, 02.jpg, ..., 30.jpg. Someone told on the internet that the VideoCapture 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
更新时间:2022-01-10 21:01

最满意答案

您可以有效地设置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版本很老,它使用umfpack来完成这项任务。 由于授权问题 (GPL与scipy不兼容,我认为umfpack在某些时候切换了许可证), 此lib已被删除 ,现在使用了superlu 。 许多人观察到速度减慢(和健壮性问题),但评估性能可能并不那么容易(超级可能也是快速和健壮的)。 请阅读本文 。 你可能有两个选择: 调整superlu的参数(阅读官方superlu文档和scipy关于如何传递这些选项的文档) 转轴和订购非常重要! 还有一个对称模式 (不是真正的高度调整的对称矩阵求解器,但 ...
  • 这是由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)) ...
  • 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上,经典的本地“长”数据 ...
  • 我发布了对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 ...
  • 您可以有效地设置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() / ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)