开发者

Using Open CV Iterators segfault

开发者 https://www.devze.com 2023-03-02 20:13 出处:网络
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 imag

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 s开发者_如何学运维hort> ();
    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!


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

data.begin<unsigned char> ()

also check stdint.h: http://en.wikipedia.org/wiki/Stdint.h

0

精彩评论

暂无评论...
验证码 换一张
取 消