我可以在我自己的自定义数据二维数组上使用 opencv cvResize() 函数吗?如果是的话怎么办?
目标:
我正在尝试使用 openCV 函数 cvResize() 来重新采样 2D 数组。[我在 opencv 中有一个使用 cvResize 的工作代码,我知道它的用法]但是我想要重新采样的输入 2D 数组不是读取的任何图像openCV 使用 cvLoadImage() 代替 -
1.我想从我拥有的文本文件中读取 2D 数组。该文件中有浮点值。我将使用 opencv 库在此测试代码中打开该文件,读取二维浮点数组中的值。
2.然后使用cvResize()调整其大小。首先我想对其进行下采样 - 宽度/2,高度/2。
3.然后我想将其上采样4 - 宽度*4,高度*4。这是我最终的二维数组。
4. 将最终的二维数组作为浮点值存储到文本文件中。
5.基本上我想使用OpenCV使用的双线性插值逻辑,但是在我自己的数据上。我可以在哪个路径/哪个文件中看到 cvResize() 的代码?
任何指示表示赞赏。
Objective:
I am trying to use openCV function cvResize() to resample a 2D array.[I have a working code in opencv using cvResize, I know its usage] But the input 2D array which I want to resample is not any image read by openCV using cvLoadImage() instead -
1.I would want to read the 2D array from a text file I have. That file has floating point values, in it. I would open that file in this test code using opencv library, read the values in a 2D array of float.
2.Then use cvResize() to resize it. First I want to downsample it - width/2, height/2.
3.Then I want to upsample it by 4 - width*4, height*4. This is my final 2D array.
4.Store this final 2D array to a text file as floating point values.
5.Basically I want to use the Bilinear interpolation logic used by OpenCV, but on my own data. What path/which file can I see the code for cvResize()?
Any pointers appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的困难似乎是您正在使用数据类型(二维数组)来存储从文件中读取的数据,这与
cvResize()
的工作方式不兼容(它是IplImage *
还记得吗?)。如果您使用 OpenCV 的 C 接口(并且通过观看您的其他问题,我知道您是),在成功将文件中的数据读取到您的自定义数据类型(2D 数组?)后,您需要创建一个 IplImage* 足够大来存储这些信息。
IplImage* cv_data_img = cvCreateImage(cvSize(custom_data_height, custom_data_width), IPL_DEPTH_32F, 1);
之后,您必须迭代
cv_data_img
复制原始数据。一旦
cv_data_img
填充了数据,您就可以创建您需要存储cvResize()
结果的其他IplImage*
。最后,您可以迭代生成的
IplImage*
并将其复制回原始数据类型(二维数组)或对其执行任何您想要的操作。The difficulty here seems to be that you are using a data type (2D array) to store the data read from the file, that is not compatible with what
cvResize()
works with (it'sIplImage*
remember?).If you are using the C interface of OpenCV (and by watching your other questions I know you are), after successfully reading the data from the file to your custom data type (2D array?) you need to create a
IplImage*
that is big enough to store this information.IplImage* cv_data_img = cvCreateImage(cvSize(custom_data_height, custom_data_width), IPL_DEPTH_32F, 1);
and after that, you'll have to iterate on
cv_data_img
copying the original data.Once
cv_data_img
it's filled with the data, you can create the othersIplImage*
you'll need to store the result ofcvResize()
.At the end, you can iterate on the resulting
IplImage*
and copy it back to your original data type (2D array) or do whatever you want with it.您可以使用
Mat
包装您的自定义数据,然后继续将其用作普通的Mat
对象。您将使用的构造函数是:You can use a
Mat
wrapper on top of your custom data and then proceed to use it as an ordinaryMat
object. The constructor you would use is: