0

私はopencv 2.4.8とスタジオ2013を使用しています.niは実行時エラーを取得しています.私のメインコードはこれです..

#include<opencv2\core\core.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include"SIFT.h"
#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace cv;
using namespace std;
int main()
{
    cout << "hello";
    Mat image = imread("abc.jpg",0);
    cout << image.channels() << endl;
    SIFT controller(image);
    controller.DoSIFT();    
    waitKey(100000);

}

私のヘッダーファイルコードは以下の通りです

#include<opencv2\core\core.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\imgproc\imgproc.hpp>

#include<iostream>

using namespace cv;
using namespace std;

class SIFT{

private:
    Mat image_orig;
    Mat Scale_spaces[4][6];
    Mat LOG_img[4][4];
    Mat Extrema[4][2];
    Mat image_temp;
    Mat middle, up, down;


    void BuildScaleSpace()
    {

        cout << "in build space" <<endl;
        int i, j;
            //image should be in grey scale
        cout << endl<<image_temp.rows << image_temp.cols << endl;
            GaussianBlur(image_temp, image_temp, cv::Size(5, 5), 0.5);
            resize(image_temp, image_temp, Size(image_temp.cols * 2, image_temp.rows * 2), 0, 0, 1);
            cout << image_temp.rows << image_temp.cols << endl;
            Scale_spaces[0][0] =image_temp;
            cout << endl << image_temp.rows << image_temp.cols << endl;
            GaussianBlur(Scale_spaces[0][0], Scale_spaces[0][0], cv::Size(5, 5), 1);
            double int_sigma = sqrt(2) / 2;
            double sigma = int_sigma;;
            double mid;
            double power = 1.0;
            for (i = 0; i < 4; i++)
            {

                if (i>0)
                {
                    sigma = mid;
                    Scale_spaces[i][0] = image_temp;
                    resize(image_temp, Scale_spaces[i][0], Size(image_temp.cols / power, image_temp.rows / power), 0, 0, 1);
                    cout << endl << "after resizing" << Scale_spaces[i][0].rows << Scale_spaces[i][0].cols << endl;
                }

                for (j = 1; j <= 5; j++)
                {
                    if (j == 2)
                        mid = sigma;
            //      printf(" %f  ", sigma);
                            GaussianBlur(Scale_spaces[i][j-1], Scale_spaces[i][j], cv::Size(5, 5), sigma);
                    sigma = sigma*sqrt(2);

                }
        //      printf("\n");
                power = power * 2;
            }




    }

    void ShowScaleSpace()
    {
        cout << "\n show scale\n\n";
        namedWindow("image", CV_WINDOW_AUTOSIZE);
        int i, j;
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j <= 5; j++)
            {
                cout << i<<"   "<<j<<endl;
                cout << Scale_spaces[i][j].rows<<"  " << Scale_spaces[i][j].cols << endl;
                imshow("image", Scale_spaces[i][j]);
                cvWaitKey(700);
            }
        }

    }

    void FindLOG()
    {
        cout << endl << "IN LOG  " << endl;
        int i;
        int j;
        for (i = 0; i < 4; i++)
        {
            for (j = 1; j < 5; j++)
            {
                addWeighted(Scale_spaces[i][j], 1, Scale_spaces[i][j + 1], -1,0, LOG_img[i][j - 1]);
            }
        }

    }

    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++)
            {

                std::cout << LOG_img[i][j].channels();
                middle = LOG_img[i][j].clone();
                up = LOG_img[i][j - 1].clone();
                down = LOG_img[i][j + 1].clone();

                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 (cout << "helllo 2hhukjhgkj"&&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;
                    }




                }
            }
        }
    }



public:
    SIFT(Mat Image)
    {
        image_orig = Image;
        image_temp = Image;

    }

    void DoSIFT()
    {

        BuildScaleSpace();
        //ShowScaleSpace();
        FindLOG();
        FindMaxMin();


    }



};

ビルドは成功しますが、実行時に次のエラーが表示されます。

ここに画像の説明を入力

エラーは FindMaxMin() 関数とこの行にある可能性があります

  currentPixel> middle.at<uchar>(yiter, xiter + 1)

しかし、私はそれを修正することができません。

4

2 に答える 2

1

申し訳ありませんが、@ user2396315、私は常にここにアクセスしていませんでした。

問題は、正しいサイズとタイプの Mat::create() を使用して、「Extrema」を初期化しなかったことです。「Mat Extrema[4][2];」と宣言しただけです。

if else の後に...

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

空のマット "Extrema[i][j - 1]" にアクセスします。

あなたは置くことができます

if( Extrema[i][j - 1].empty() == true )
   cerr << "Fatal error" << endl ;

その前に、あなたは見るでしょう。

使用する前に、常に Mat::empty() でマットを確認してください。それが、この投稿の「サイズを確認する」という意味です。配列のサイズをチェックするつもりはありませんでした。

「アサーションが失敗しました」とは、通常、期待どおりに間違ったサイズの空のマットまたはマットを渡したという意味です。

于 2014-04-01T16:34:48.933 に答える