求教:出现错误,每次调用都出现这样的错误

图片说明

int SampleMat()
{
for (int c = 0; c != 12; c++)
{
for (int t = 0; t != m; t++)
{
//Load Image
char filename[14] = { 'S', 'a', 'm', 'p', 'l', 'e', '/', 'a' + c, '0' + t, '.', 'b', 'm', 'p' };
IplImage* pImage = cvLoadImage(filename, 1);
//Covert to Gray
IplImage* pImage2 = NULL;
//为什么在这里bug
pImage2 = cvCreateImage(cvSize(pImage->width, pImage->height), IPL_DEPTH_8U, 1);
//pImage2 = cvCreateImage(cvGetSize(pImage), IPL_DEPTH_8U, 1);
cvCvtColor(pImage, pImage2, CV_BGR2GRAY);

        //Get histograms of each image and Stored in SampleX and SampleY
        GetHisto(pImage2);
        for (int i = 0; i != W; i++)
        {
            if (HistoMatX[i]) SampleX[i][t][c] = HistoMatX[i];
            else SampleX[i][t][c] = 0;
        }
        for (int j = 0; j != H; j++)
        {
            if (HistoMatY[j]) SampleY[H - 1 - j][t][c] = HistoMatY[j];
            else SampleY[j][t][c] = 0;
        }

        //Release image
        cvReleaseImage(&pImage);
        cvReleaseImage(&pImage2);
    }
}
return 0;

}

应该是以下这句话导致的

 pImage2 = cvCreateImage(cvSize(pImage->width, pImage->height), IPL_DEPTH_8U, 1);

我猜应该是由于pImage是个NULL指针,也就是说IplImage* pImage = cvLoadImage(filename, 1);这句其实失败了
如果是NULL指针,pImage->width或者pImage->height就会报这样的异常
楼主不妨可以判断打印以下看看是否如此if(pImage==NULL)printf("pImage pointer is null\n");

电脑感染了360了,建议你先重装下系统,然后回过头来再看你的程序吧。