使用 Open CV 迭代器出现段错误
我想做类似 eigenfaces 的事情,但使用不同的图像(不是面孔)。我有一个图像向量,images
。从这些图像中,我想创建一个 Mat
对象,data
,其中每行包含一个以行向量形式写出的图像。这就是我试图做的:
// This is basically a matrix that needs to have a bunch of images as rows.
Mat data(numImages, IMAGE_SIZE * IMAGE_SIZE, CV_8UC1);
// I also replaced CV_8U by images[0].type() and CV_8U. no change
MatIterator_<unsigned short> iter = data.begin<unsigned short> (),
iter_end = data.end<unsigned short> (),
iter2;
for (i = 0; i < numImages; ++i)
{
MatIterator_<unsigned short> begin = images[i].begin<unsigned short> ();
MatIterator_<unsigned short> end = images[i].end<unsigned short> ();
for (iter2 = begin; iter2 != end; iter2++)
{
*iter = *iter2; // Segfault is here.
if (iter != iter_end) // safety check
iter++;
else
perror("Screwed!\n"); // This does not execute!
}
}
帮助!
谢谢!
I want to do something like eigenfaces but with different images (not faces). I have a vector of images, images
. From these images, I want to make a Mat
object, data
which contains in each row, a image written out as a row vector. This is what I tried to do:
// This is basically a matrix that needs to have a bunch of images as rows.
Mat data(numImages, IMAGE_SIZE * IMAGE_SIZE, CV_8UC1);
// I also replaced CV_8U by images[0].type() and CV_8U. no change
MatIterator_<unsigned short> iter = data.begin<unsigned short> (),
iter_end = data.end<unsigned short> (),
iter2;
for (i = 0; i < numImages; ++i)
{
MatIterator_<unsigned short> begin = images[i].begin<unsigned short> ();
MatIterator_<unsigned short> end = images[i].end<unsigned short> ();
for (iter2 = begin; iter2 != end; iter2++)
{
*iter = *iter2; // Segfault is here.
if (iter != iter_end) // safety check
iter++;
else
perror("Screwed!\n"); // This does not execute!
}
}
Help!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在你的矩阵中每个字段都有 1 个字节(CV_8UC1),但你的迭代器是“无符号短”迭代器。无符号短通常有2个字节。更改它以
同时检查 stdint.h:http://en.wikipedia.org/wiki/Stdint。哈
I think that in your matrix each field has 1 byte (CV_8UC1), but you iterator is "unsigned short" iterator. Unsigned short usually has 2 bytes. change it to
also check stdint.h: http://en.wikipedia.org/wiki/Stdint.h