2012-05-08 66 views
1

OpenCVのMeanShiftAlgorithmを私たちの論文(ディプロマ)に使用します。 QT4.6の例はうまくいきます。唯一の我々は320x3x240 RGBストリームを受信する当社独自のGUIアプリケーションの中に、それを次のエラーメッセージを表示します。OpenCVエラー:アサーションが失敗しました(j <nimages)

OpenCV Error: Assertion failed (j < nimages) in histPrepareImages, file /home/luca/OpenCvSDK/opencv-src/modules/imgproc/src/histogram.cpp, line 148 
terminate called after throwing an instance of 'cv::Exception' 
    what(): /home/luca/OpenCvSDK/opencv-src/modules/imgproc/src/histogram.cpp:148: error: (-215) j < nimages in function histPrepareImages 

GUIはEclipseの/ QT4.6とUbuntuの下にプログラムされています。ここでのコードは次のとおり

// Mean Shift Algorithm On 
minSat=65; 
ch[1]={0}; 
if (m_meanShiftAlgoOn) 
{ 
    if (m_firstFrame) 
    { 
     m_firstFrame = false; 
     // Define ROI 
     imageROI= m_currentFrame(  cv::Rect(m_meanShift_xPos,m_meanShift_yPos, 
               m_meanShift_width,m_meanShift_height)); 
     cv::rectangle(m_currentFrame, cv::Rect(m_meanShift_xPos,m_meanShift_yPos,m_meanShift_width, 
               m_meanShift_height),cv::Scalar(0,0,255)); 
     // Get the Hue histogram 
     ColorHistogram hc; 
     cv::MatND colorhist= hc.getHueHistogram(imageROI,minSat); 

     finder.setHistogram(colorhist); 
     finder.setThreshold(0.2f); 

     // Convert to HSV space 
     cv::cvtColor(m_currentFrame, hsv, CV_BGR2HSV); 

     // Split the image 
     cv::split(hsv,v); 

     // Eliminate pixels with low saturation 
     cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY); 
     // for debug only: shows the frame with threshold 
     //m_currentFrame = v[1]; 

     // Get back-projection of hue histogram 
     result1= finder.find(hsv,0.0f,180.0f,ch,1); 
     // for debug only: shows the frame with back-projection of hue histogram 
     //m_currentFrame = result1; 

     cv::bitwise_and(result1,v[1],result1); 
     // for debug only: shows the frame with bitwise_and of src1 and src2 
     //m_currentFrame = result1; 
    } 
    else 
    { 
      // Second frame 

     // Convert to HSV space 
     cv::cvtColor(m_currentFrame, hsv, CV_BGR2HSV); 

     // Split the frame 
     cv::split(hsv,v); 

     // Eliminate pixels with low saturation 
     cv::threshold(v[1],v[1],minSat,255,cv::THRESH_BINARY); 
     // for debug only: shows the frame with eliminated pixels with low saturation 
     //m_currentFrame = v[1]; 

     // Get back-projection of hue histogram 
     result2= finder.find(hsv,0.0f,180.0f,ch,1);  // here code crash 
     // for debug only: shows the frame with back-projection of hue histogram 
     //m_currentFrame = result2; 

     // Eliminate low stauration pixels 
     cv::bitwise_and(result2,v[1],result2); 

     // Get back-projection of hue histogram 
     finder.setThreshold(-1.0f); 
     result2= finder.find(hsv,0.0f,180.0f,ch,1); 
     cv::bitwise_and(result2,v[1],result2); 

     cv::Rect rect(m_meanShift_xPos,m_meanShift_yPos,m_meanShift_width,m_meanShift_height); 
     cv::rectangle(m_currentFrame, rect, cv::Scalar(0,0,255)); 

     cv::TermCriteria criteria(cv::TermCriteria::MAX_ITER,10,0.01); 

     cv::rectangle(m_currentFrame, rect, cv::Scalar(0,255,0)); 

    } 
} 
else 
    m_firstFrame = true; 

ROIのパラメータは次のとおり

m_meanShift_xPos= 80 
m_meanShift_yPos= 120 
m_meanShift_width= 80 
m_meanShift_height= 90 

ここ依然としてファイルhistogramm.cpp/LINE 1163(エラーメッセージのように示されている)

static void histPrepareImages(const Mat* images, int nimages, const int* channels, 
           const Mat& mask, int dims, const int* histSize, 
           const float** ranges, bool uniform, 
           vector<uchar*>& ptrs, vector<int>& deltas, 
           Size& imsize, vector<double>& uniranges) 
{ 
    int i, j, c; 
    CV_Assert(channels != 0 || nimages == dims); 

    imsize = images[0].size(); 
    int depth = images[0].depth(), esz1 = (int)images[0].elemSize1(); 
    bool isContinuous = true; 

    ptrs.resize(dims + 1); 
    deltas.resize((dims + 1)*2); 

    for(i = 0; i < dims; i++) 
    { 
     if(!channels) 
     { 
      j = i; 
      c = 0; 
      CV_Assert(images[j].channels() == 1); 
     } 
     else 
     { 
      c = channels[i]; 
      CV_Assert(c >= 0); 
      for(j = 0; j < nimages; c -= images[j].channels(), j++) 
       if(c < images[j].channels()) 
        break; 
      CV_Assert(j < nimages);    // line 148 
     } 

     CV_Assert(images[j].size() == imsize && images[j].depth() == depth); 
     if(!images[j].isContinuous()) 
      isContinuous = false; 
     ptrs[i] = images[j].data + c*esz1; 
     deltas[i*2] = images[j].channels(); 
     deltas[i*2+1] = (int)(images[j].step/esz1 - imsize.width*deltas[i*2]); 
    } 

    if(mask.data) 
    { 
     CV_Assert(mask.size() == imsize && mask.channels() == 1); 
     isContinuous = isContinuous && mask.isContinuous(); 
     ptrs[dims] = mask.data; 
     deltas[dims*2] = 1; 
     deltas[dims*2 + 1] = (int)(mask.step/mask.elemSize1()); 
    } 

    if(isContinuous) 
    { 
     imsize.width *= imsize.height; 
     imsize.height = 1; 
    } 

    if(!ranges) 
    { 
     CV_Assert(depth == CV_8U); 

     uniranges.resize(dims*2); 
     for(i = 0; i < dims; i++) 
     { 
      uniranges[i*2] = histSize[i]/256.; 
      uniranges[i*2+1] = 0; 
     } 
    } 
    else if(uniform) 
    { 
     uniranges.resize(dims*2); 
     for(i = 0; i < dims; i++) 
     { 
      CV_Assert(ranges[i] && ranges[i][0] < ranges[i][1]); 
      double low = ranges[i][0], high = ranges[i][1]; 
      double t = histSize[i]/(high - low); 
      uniranges[i*2] = t; 
      uniranges[i*2+1] = -t*low; 
     } 
    } 
    else 
    { 
     for(i = 0; i < dims; i++) 
     { 
      size_t j, n = histSize[i]; 
      for(j = 0; j < n; j++) 
       CV_Assert(ranges[i][j] < ranges[i][j+1]); 
     } 
    } 
} 
関数

事前にお答えいただきありがとうございます...

+2

質問をするときにコードを表示するのは良いことですが、研究活動を示すことも良いことです。アサーションが失敗したときに 'i'、' j'、 'c'などの値をチェックして、デバッガまたは単に' printf'を使ってアサーションが148行で失敗しました。 – Simon

+1

[この質問](http://stackoverflow.com/questions/16840968/multi-channel-back-projection-assertion-j-nimages)が役に立ちます。 'find()'メソッドのコードを投稿しないので、私は確かに分かりません。 – Aurelius

答えて

0

私はexを実行すると、同じ問題が発生しました十分なpython-opencvを含む、私はコードを調べた後、私は画像の場所が間違っていた、私は答えがあなたを助けてくれることを願った。

関連する問題