为啥在运行此 OpenCV 程序时出现此异常?

Posted

技术标签:

【中文标题】为啥在运行此 OpenCV 程序时出现此异常?【英文标题】:Why am I getting this exception while running running this OpenCV program?为什么在运行此 OpenCV 程序时出现此异常? 【发布时间】:2012-09-01 22:10:48 【问题描述】:

我使用 Visual Studio 2010 和 OpenCV 2.3.0。

#include "stdafx.h"
#include <cv.h>
#include <ml.h>
#include <highgui.h>
#include <iostream>
#include <stdlib.h>

template<class T> class Image 
  private:
  IplImage* imgp;

  public:
  Image(IplImage* img = 0) 
      imgp = img;
  

  ~Image() 
      imgp = 0;
  

  void operator=(IplImage* img) 
      imgp = img;
  

  inline T* operator[](const int rowIndx) 
      return ((T *)(imgp->imageData + rowIndx * imgp->widthStep));
  
;

typedef struct 
  unsigned char b,g,r;
 RgbPixel;

typedef struct 
  float b,g,r;
 RgbPixelFloat;

//typedef Image<RgbPixel>       RgbImage;
//typedef Image<RgbPixelFloat>  RgbImageFloat;
typedef Image<unsigned char>  BwImage;
//typedef Image<float>          BwImageFloat;

double crossCorrelation( IplImage* img1, IplImage* img2 ) 
    double corr;
    int M = img1->width;
    int N = img1->height;

    BwImage img_1( img1 );
    BwImage img_2( img2 );

    CvScalar img1_avg = cvAvg( img1, NULL );
    CvScalar img2_avg = cvAvg( img2, NULL );

    double sum_img1_img2 = 0;
    double sum_img1_2    = 0;
    double sum_img2_2    = 0;

    for( int m = 0; m < M; ++m ) 
        for( int n = 0; n < N; ++n ) 
            sum_img1_img2   = sum_img1_img2 + (img_1[m][n] - img1_avg.val[0]) * (img_2[m][n] - img2_avg.val[0]);
            sum_img1_2      = sum_img1_2    + (img_1[m][n] - img1_avg.val[0]) * (img_1[m][n] - img1_avg.val[0]);
            sum_img2_2      = sum_img2_2    + (img_2[m][n] - img2_avg.val[0]) * (img_2[m][n] - img2_avg.val[0]);
        
    

    corr = sum_img1_img2/sqrt(sum_img1_2*sum_img2_2);
    return corr;


int _tmain(int argc, _TCHAR* argv[]) 
    IplImage *img1 = cvLoadImage("C:/Users/ANIMES~1/Documents/VISUAL~3/Projects/tutOpencv/tutOpencv/38.png", CV_LOAD_IMAGE_COLOR);
    IplImage *img2 = cvLoadImage("C:/Users/ANIMES~1/Documents/VISUAL~3/Projects/tutOpencv/tutOpencv/39.png", CV_LOAD_IMAGE_COLOR);
    IplImage *img1g = cvCreateImage( cvSize( img1->width, img1->height ), IPL_DEPTH_8U, 1 );
    IplImage *img2g = cvCreateImage( cvSize( img2->width, img2->height ), IPL_DEPTH_8U, 1 );
    std::cout << (double)crossCorrelation(img1g, img2g) << std::endl;
    std::system("Pause");
    return 0;

当我调试时,我总是得到这个异常:

tutOpencv.exe 中 0x013e157f 处未处理的异常:0xC0000005:访问冲突读取位置 0x00f3b00c。

我不知道,这个错误是从哪里来的?

【问题讨论】:

【参考方案1】:

添加一些断点以找出程序崩溃的位置

【讨论】:

以上是关于为啥在运行此 OpenCV 程序时出现此异常?的主要内容,如果未能解决你的问题,请参考以下文章

运行天气应用程序时出现此错误我正在使用 json 和 http 库来获取数据但我不知道为啥会出现此错误

为啥在我的程序中打开某些 wav 文件时出现此错误“EMCIDeviceError”

为啥在使用 Cordova 构建 APK 时出现此错误?

为啥在尝试将firebase添加到flutter时出现此错误“已弃用的API”

为啥在将应用程序部署到 Heroku 时出现此错误?

opencv detectMultiScale