【问题标题】:Deconstructing Mat_<INT64> in opencv fails在 opencv 中解构 Mat_<INT64> 失败
【发布时间】:2014-03-12 01:31:00
【问题描述】:

我的程序在我的 32 位 Windows 上奇怪地崩溃了。函数返回时VS2010给我一个错误:

Windows 已在 mat_test.exe 中触发断点。这可能是由于堆损坏,这表明 mat_test.exe 或其已加载的任何 DLL 中存在错误。这也可能是由于用户按下F12 mat_test.exe 有焦点。输出窗口可能有更多诊断信息。

如果我将 INT64 更改为带符号的 int,则效果很好。这和opencv 有关系吗? opencvMat_ 是否支持 INT64 数据类型?

#include <opencv.hpp>
#include <stdio.h>

using namespace cv;
using namespace std;

typedef signed __int64 INT64;
typedef unsigned char byte;


Mat imgcpy(Mat &ori_image);
Mat imgcpy(Mat &ori_image){
    Mat img;
    Mat_<float> img_;

    Mat img_copy;
    img_copy.create(8,8,CV_8U);
    for(int i=0;i<8;i++)
        for(int j=0;j<8;j++)
            img_copy.at<byte>(i,j)=1;
    cout<<img_copy<<endl;



    const Size sz(9,9);
    Mat_<float> scores(sz,0);
    Mat_<INT64> Tig1 = Mat_<INT64>::zeros(sz), Tig2 = Mat_<INT64>::zeros(sz);
    Mat_<INT64> Tig4 = Mat_<INT64>::zeros(sz), Tig8 = Mat_<INT64>::zeros(sz);
    Mat_<byte> Row1 = Mat_<byte>::zeros(sz),Row2 = Mat_<byte>::zeros(sz);
    Mat_<byte> Row4 = Mat_<byte>::zeros(sz),Row8 = Mat_<byte>::zeros(sz);
    //cout << Tig1 << endl << endl;
    for (int y=1;y<=8;y++)
    {
        //byte* G = img_copy.ptr<byte>(y-1);
        INT64* T1 = Tig1.ptr<INT64>(y); // Binary TIG of current row
        INT64* T2 = Tig2.ptr<INT64>(y);
        INT64* T4 = Tig4.ptr<INT64>(y);
        INT64* T8 = Tig8.ptr<INT64>(y);
        INT64* Tu1 = Tig1.ptr<INT64>(y-1); // Binary TIG of upper row
        INT64* Tu2 = Tig2.ptr<INT64>(y-1);
        INT64* Tu4 = Tig4.ptr<INT64>(y-1);
        INT64* Tu8 = Tig8.ptr<INT64>(y-1);
        byte* R1 = Row1.ptr<byte>(y);
        byte* R2 = Row2.ptr<byte>(y);
        byte* R4 = Row4.ptr<byte>(y);
        byte* R8 = Row8.ptr<byte>(y);
        float *s = scores.ptr<float>(y);
        for (int x=1;x<=8;x++)
        {
            //cout<<G[x-1];
            //byte g = 1;//G[x-1];
            //R1[x] = (R1[x-1] << 1) | ((g >> 4) & 1);
            //R2[x] = (R2[x-1] << 1) | ((g >> 5) & 1);
            //R4[x] = (R4[x-1] << 1) | ((g >> 6) & 1);
            //R8[x] = (R8[x-1] << 1) | ((g >> 7) & 1);
            T1[x] = (Tu1[x] << 8) | R1[x];
            T2[x] = (Tu2[x] << 8) | R2[x];
            T4[x] = (Tu4[x] << 8) | R4[x];
            T8[x] = (Tu8[x] << 8) | R8[x];
            //cout<<Tig1<<endl<<"\n";
            //cout<<Tig2<<endl<<"\n";
            //cout<<Tig4<<endl<<"\n";
            //cout<<Tig8<<endl<<"\n";
            //cout<<Row1<<endl<<"\n";
            //cout<<Row2<<endl<<"\n";
            //cout<<Row4<<endl<<"\n";
            //cout<<Row8<<endl<<"\n";
            //s[x] = dot(T1[x], T2[x], T4[x], T8[x]);
            //T1[x]=1;
            //T2[x]=1;
            //T4[x]=1;
            //T8[x]=1;
            s[x]=y;

        }
    }
    cout<<scores<<endl<<endl;

    //cout<< scores(Rect(8,8,2,2)) <<endl<<endl;
    scores(Rect(7,7,2,2)).copyTo(img);
    cout<<img<<endl<<endl;
    return img;
}
int main(){

    Mat img;
    Mat ori_img;

    img = imgcpy(ori_img);
    return 0;

}

【问题讨论】:

    标签: c++ visual-studio-2010 opencv mat


    【解决方案1】:

    当调用向量析构函数时,我遇到了类似的问题,而且它正在另一台计算机上工作。问题是图书馆。我从另一台计算机复制了编译的库文件。他们的视觉标准版本是不同的。这可能会导致您的问题,请使用您的编译器构建 opencv。

    当 Visual Studio 版本更改时 c 运行时库版本更改。因此,您的代码可能会在运行时崩溃。当我用我的 Visual Studio 编译 OpenCV 时,我的问题得到了解决,我希望你的问题也能解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-23
      • 2023-03-18
      • 2018-05-08
      • 1970-01-01
      • 2013-11-10
      • 2015-06-25
      • 2019-09-24
      • 1970-01-01
      相关资源
      最近更新 更多