itk 读图像 c++ 0xC0000005: Access violation reading location 0x00000000 出错总结

来源:互联网 发布:unity 2d 不会编程 编辑:程序博客网 时间:2024/06/06 22:02

 
int main ()
{
int * p=NULL;
int a;
a=p[0];
cout<<a;


}


这个例子大家一定看明白了。就是因为我们定义了一个空指针。但是我们去访问的元素。

但是有时大家可能会遇到这样一个问题觉得你初始化了。昨天我们在使用itk的时候也遇到这个问题

一下贴出itk代码

<span style="font-size: 24px;"> std::string inputFilename;  typedef itk::Image< unsigned char,3>  ImageType;  typedef itk::ImageFileReader<ImageType> ReaderType;  inputFilename = "C:\\Users\\Administrator\\Desktop\\TAM088_1.mha";  ReaderType::Pointer reader=ReaderType::New();   reader->SetFileName(inputFilename); </span><span style="font-size:32px;color:#ff0000;"> </span><span style="font-size:48px;color:#ff0000;">reader->Update();//就是因为没有这句话</span><span style="font-size: 24px;">  ImageType::Pointer image=reader->GetOutput();  ImageType::SizeType size=image->GetLargestPossibleRegion().GetSize();     ImageType::IndexType index={{188,283,20}};   ImageType::PixelType value=image->GetPixel(index);   printf("%uc",value);   for(int x=0;x<size[0];x++)  {  for(int y=0;y<size[1];y++)  {  for(int z=0;z<size[2];z++)  {    index[0]=x;  index[1]=y;  index[2]=z;  value=image->GetPixel(index);  printf("%uc ",value);  //M.at<unsigned char>(x,y,z)=value;  //M.at<unsigned char>(x,y,z)=image->GetPixel(index);  }  }  }</span>

就是因为红字标出的话没有写,我们们的像素指针image 还没有初始化。所以我们会报

c++ 0xC0000005: Access violation reading location 0x00000000 ;

所以当出这样的错误大家一定开一下指针的初始化的地方看我们有没有初始化


0 0
原创粉丝点击