使用c ++ - 在详细信息cv :: Mat :: at的OpenCV库导致大图像上的SIGSEGV [英] The OpenCV lib with c++ - in Detail cv::Mat::at causes SIGSEGV on large images

查看:170
本文介绍了使用c ++ - 在详细信息cv :: Mat :: at的OpenCV库导致大图像上的SIGSEGV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用openCV-lib(2.1版)在c ++中编写应用程序。
任务是实现一个小型数据库作为学生项目,使用这个库的一些功能。我自己的中值滤波器和boxcar滤波器的实现使用cv :: Mat :: at方法访问给定图像中的单个像素,同时具有读取和写入操作。

I am currently writing an application in c++ using the openCV-lib (version 2.1). The task was to implement a small database as a students project, using some of the features of this library. My very own implementations of the median-filter and the boxcar-filter use the cv::Mat::at method to access single pixels in a given image with both reading and writing operations.

这个好奇的事情是:它在较小的图像上工作得很完美。

The curious thing about this is: It works just perfect on smaller images. but only larger images it allways generates a SIGSEGV, allways on the same coordinates.

这是一个知道的错误,还是我真的做错了什么?

Is this a know bug or am i really doing something wrong?

这里是我写的最重要的函数:

here are the most significants functions i wrote:

class point {
public:
    int x,y;
};

class ImageEntry {  
    friend class ImageDB;
private:
    string _key;
    string _filename;
    Mat *_data;
    ImageEntry* _next;
    void show(void);
public:
    void operator<<(ImageFilter* x);
    ~ImageEntry();  
    ImageEntry(string filename, string key);
    Vec3b GetPoint(int x, int y);
    point GetSize(void);
    void SetPoint(int x, int y, Vec3b color);
};


point ImageEntry::GetSize(void) {
    point iRet;
    iRet.x = _data->cols;
    iRet.y = _data->rows;
    return iRet;
}

Vec3b ImageEntry::GetPoint(int x, int y) {
    Vec3b iRet;
    iRet = _data->at<Vec3b>(x,y);
    return iRet;
}

void ImageEntry::SetPoint(int x, int y, Vec3b color) {
    _data->at<Vec3b>(x,y) = color;
}

void MedianFilter::filterImage(ImageEntry* img) {
    Vec3b Points[9];
    Vec3b NewColor;

    unsigned char ActChan[9];
    point range = img->GetSize();
    for (int act_x = 1; act_x < (range.x - 1); act_x++) {
        for (int act_y = 1; act_y < range.y - 1; act_y++) {
            Points[0] = img->GetPoint(act_x-1,act_y-1);
            Points[1] = img->GetPoint(act_x,act_y-1);
            Points[2] = img->GetPoint(act_x+1,act_y-1);
            Points[3] = img->GetPoint(act_x-1,act_y);
            Points[4] = img->GetPoint(act_x,act_y);
            Points[5] = img->GetPoint(act_x+1,act_y);
            Points[6] = img->GetPoint(act_x-1,act_y+1);
            Points[7] = img->GetPoint(act_x,act_y+1);
            Points[8] = img->GetPoint(act_x+1,act_y+1);

            for (int act_color = 0; act_color < 3; act_color++) {
                for (int i = 0; i < 9; i++) ActChan[i] = Points[i][act_color];
                SelSort9(ActChan);
                NewColor[act_color] = ActChan[4];
            }
            img->SetPoint(act_x,act_y,NewColor);
        }
    }
}


谢谢您的时间!

I would really appreciate any suggestion. Thank you for your time!

推荐答案

如果你看一下函数 () rel =nofollow> OpenCv的文档,它说:

If you take a look at the function at(), which you use in the SetPoint() method, in the documentation of OpenCv, it says:

template<typename _Tp> _Tp& Mat::at(int i, int j)

返回指定矩阵元素的引用。
参数:

Return reference to the specified matrix element. Parameters:

i – The 0-based row index
j – The 0-based column index



< y = _data-> rows
,然后在方法 filterImage()中使用for循环从 act_y = 1 to iRet.y 。第二个循环,循环通过行。在这个方法的最后,你调用 SetPoint(act_x,act_y),它依次调用 at(act_x,act_y)基本上。

Furthermore, if you look at your GetSize() method, you set iRet.y = _data->rows and then in the method filterImage() use a for loop to loop from act_y = 1 to iRet.y. The second loop, loops through the rows. At the end of this method you call SetPoint(act_x, act_y), which on its turn calls at(act_x, act_y) basically.

回想一下, act_y 是一个行的索引,列。我希望这个建议是你需要解决你的问题。

Recall that act_y was an index of a row, but is now being used as index of a column. I hope this suggestion is all you need to solve your problem.

这篇关于使用c ++ - 在详细信息cv :: Mat :: at的OpenCV库导致大图像上的SIGSEGV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆