Open CV : Assertion failed while implementing SIFT

﹥>﹥吖頭↗ 提交于 2019-12-25 04:27:06

问题


I am trying to implement SIFT in studio 2013 and opencv 2.4. And I am getting the following error.

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

I think the error is in this code :

    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;
                }




            }
        }
    }
}

The code is printing " IN findmaxmin" 0 1 1 1 and then the error is occuring. I have checked the remaining code by commenting out this function, and the code works fine.

来源:https://stackoverflow.com/questions/22561372/open-cv-assertion-failed-while-implementing-sift

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!