2011-05-03 70 views
2

我想要做一些像eigenfaces但有不同的圖像(不是面孔)。我有一個圖像矢量,images。從這些圖像中,我想製作一個Mat對象,其中每個行包含一個作爲行向量寫出的圖像,其中包含data。這是我試圖做的:使用開放式CV迭代器段落錯誤

// 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! 
    } 
} 

幫助!

謝謝!

回答

1

我認爲在你的矩陣中每個字段有1個字節(CV_8UC1),但你的迭代器是「無符號短」迭代器。無符號短通常有2個字節。將其更改爲

data.begin<unsigned char>() 

還要檢查stdint.h:http://en.wikipedia.org/wiki/Stdint.h

+0

是的,這似乎是它。現在我感到跛腳:P謝謝! – 2011-05-04 05:14:23