打开CV:实现SIFT时断言失败

时间:2014-03-21 14:18:40

标签: c++ opencv sift

我正在尝试在studio 2013和opencv 2.4中实现SIFT。我收到以下错误。

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((sizeof(size_t)<<28)|0x8442211)

((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in unknown function, file C:\opencv231\build\include\opencv2/core/mat.hpp, line 552

我认为错误出现在以下代码中:

    void FindMaxMin()
{

    cout << endl << "IN findmaxmin  " << endl;
    int i;
    int j;
    int xiter, yiter;
    for (i = 0; i < 4; i++)
    {
        for (j = 1; j < 3; j++)
        {
            middle = LOG_img[i][j];
            up = LOG_img[i][j - 1];
            down = LOG_img[i][j + 1];

            for (yiter = 1; yiter < middle.rows-1; yiter++)
            {
                for (xiter = 1; xiter < middle.cols-1; xiter++)
                {
                    cout << i << "  " << j << "  " << yiter << "  " << xiter<< "  "<<endl;
                    double currentPixel = middle.at<uchar>(yiter, xiter);
                    cout << "1 ";
                    // Check for a maximum
                    if (currentPixel> middle.at<uchar>(yiter, xiter + 1) &&
                        currentPixel> middle.at<uchar>(yiter, xiter - 1) &&
                        currentPixel > middle.at<uchar>(yiter + 1, xiter) &&
                        currentPixel > middle.at<uchar>(yiter + 1, xiter - 1) &&
                        currentPixel > middle.at<uchar>(yiter, xiter + 1) &&
                        currentPixel > middle.at<uchar>(yiter - 1, xiter) &&
                        currentPixel > middle.at<uchar>(yiter - 1, xiter + 1) &&
                        currentPixel > middle.at<uchar>(yiter - 1, xiter - 1) &&

                        currentPixel > up.at<uchar>(yiter, xiter) &&
                        currentPixel > up.at<uchar>(yiter, xiter + 1) &&
                        currentPixel > up.at<uchar>(yiter, xiter - 1) &&
                        currentPixel > up.at<uchar>(yiter + 1, xiter) &&
                        currentPixel > up.at<uchar>(yiter + 1, xiter - 1) &&
                        currentPixel > up.at<uchar>(yiter, xiter + 1) &&
                        currentPixel > up.at<uchar>(yiter - 1, xiter) &&
                        currentPixel > up.at<uchar>(yiter - 1, xiter + 1) &&
                        currentPixel > up.at<uchar>(yiter - 1, xiter - 1) &&

                        currentPixel > down.at<uchar>(yiter, xiter) &&
                        currentPixel > down.at<uchar>(yiter, xiter + 1) &&
                        currentPixel > down.at<uchar>(yiter, xiter - 1) &&
                        currentPixel > down.at<uchar>(yiter + 1, xiter) &&
                        currentPixel > down.at<uchar>(yiter + 1, xiter - 1) &&
                        currentPixel > down.at<uchar>(yiter, xiter + 1) &&
                        currentPixel > down.at<uchar>(yiter - 1, xiter) &&
                        currentPixel > down.at<uchar>(yiter - 1, xiter + 1) &&
                        currentPixel > down.at<uchar>(yiter - 1, xiter - 1)
                        )
                    {
                        cout << "inside, updating extrema  ";
                        Extrema[i][j - 1].at<uchar>(xiter, yiter) = 255;
                    }

                    else if (currentPixel< middle.at<uchar>(yiter, xiter + 1) &&
                        currentPixel< middle.at<uchar>(yiter, xiter - 1) &&
                        currentPixel < middle.at<uchar>(yiter + 1, xiter) &&
                        currentPixel < middle.at<uchar>(yiter + 1, xiter - 1) &&
                        currentPixel < middle.at<uchar>(yiter, xiter + 1) &&
                        currentPixel < middle.at<uchar>(yiter - 1, xiter) &&
                        currentPixel < middle.at<uchar>(yiter - 1, xiter + 1) &&
                        currentPixel < middle.at<uchar>(yiter - 1, xiter - 1) &&

                        currentPixel < up.at<uchar>(yiter, xiter) &&
                        currentPixel < up.at<uchar>(yiter, xiter + 1) &&
                        currentPixel < up.at<uchar>(yiter, xiter - 1) &&
                        currentPixel < up.at<uchar>(yiter + 1, xiter) &&
                        currentPixel < up.at<uchar>(yiter + 1, xiter - 1) &&
                        currentPixel < up.at<uchar>(yiter, xiter + 1) &&
                        currentPixel < up.at<uchar>(yiter - 1, xiter) &&
                        currentPixel < up.at<uchar>(yiter - 1, xiter + 1) &&
                        currentPixel < up.at<uchar>(yiter - 1, xiter - 1) &&

                        currentPixel < down.at<uchar>(yiter, xiter) &&
                        currentPixel < down.at<uchar>(yiter, xiter + 1) &&
                        currentPixel < down.at<uchar>(yiter, xiter - 1) &&
                        currentPixel < down.at<uchar>(yiter + 1, xiter) &&
                        currentPixel < down.at<uchar>(yiter + 1, xiter - 1) &&
                        currentPixel < down.at<uchar>(yiter, xiter + 1) &&
                        currentPixel < down.at<uchar>(yiter - 1, xiter) &&
                        currentPixel < down.at<uchar>(yiter - 1, xiter + 1) &&
                        currentPixel < down.at<uchar>(yiter - 1, xiter - 1)
                        )
                    {
                        Extrema[i][j - 1].at<uchar>(xiter, yiter) = 255;
                    }

                    else
                        Extrema[i][j - 1].at<uchar>(xiter, yiter) = 0;
                }




            }
        }
    }
}

代码正在打印“IN findmaxmin”                          0 1 1 1 然后发生错误。我通过注释掉这个函数检查了剩下的代码,代码工作正常。

0 个答案:

没有答案