Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t使用C+在Matlab上打开重新采样的图像+; 我有一个用OpenCV编写的C++代码,在我的图像上很好用。但是,由于代码运行时间太长,我决定更改每个图像的尺寸并保存在文件夹中。在Matlab中编写的代码中,我对图像重新采样的部分如下所示: %read image image=imread(char(image_name)); %The image will become 4 times smaller img_resized=imresize(image,0.25); %save the image with the same name, but now it is smaller C = regexp(char(image_name),'/','split'); imwrite(img_resized, [name_folder '/' char(C(end))]); P>真正奇怪的是,当我在这些大小的图像上运行C++代码时,我会得到分割错误。当我在原始图像上运行时,代码运行良好_C++_Image_Matlab_Opencv_Image Processing - Fatal编程技术网

Can';t使用C+在Matlab上打开重新采样的图像+; 我有一个用OpenCV编写的C++代码,在我的图像上很好用。但是,由于代码运行时间太长,我决定更改每个图像的尺寸并保存在文件夹中。在Matlab中编写的代码中,我对图像重新采样的部分如下所示: %read image image=imread(char(image_name)); %The image will become 4 times smaller img_resized=imresize(image,0.25); %save the image with the same name, but now it is smaller C = regexp(char(image_name),'/','split'); imwrite(img_resized, [name_folder '/' char(C(end))]); P>真正奇怪的是,当我在这些大小的图像上运行C++代码时,我会得到分割错误。当我在原始图像上运行时,代码运行良好

Can';t使用C+在Matlab上打开重新采样的图像+; 我有一个用OpenCV编写的C++代码,在我的图像上很好用。但是,由于代码运行时间太长,我决定更改每个图像的尺寸并保存在文件夹中。在Matlab中编写的代码中,我对图像重新采样的部分如下所示: %read image image=imread(char(image_name)); %The image will become 4 times smaller img_resized=imresize(image,0.25); %save the image with the same name, but now it is smaller C = regexp(char(image_name),'/','split'); imwrite(img_resized, [name_folder '/' char(C(end))]); P>真正奇怪的是,当我在这些大小的图像上运行C++代码时,我会得到分割错误。当我在原始图像上运行时,代码运行良好,c++,image,matlab,opencv,image-processing,C++,Image,Matlab,Opencv,Image Processing,这就是我在调整大小的图像上运行代码时返回的错误。这里,beach_wood_copy_r8.png是调整大小的图像 ./zernike beach_wood_copy_r8.png beach_wood_gt_r8.png resu.png Reading Images Calculating Zernike Segmentation fault (core dumped) 还有错误发生的C++源代码的一部分: int main(int argc, char** argv){

这就是我在调整大小的图像上运行代码时返回的错误。这里,beach_wood_copy_r8.png是调整大小的图像

  ./zernike beach_wood_copy_r8.png beach_wood_gt_r8.png resu.png
  Reading Images
  Calculating Zernike
  Segmentation fault (core dumped)

还有错误发生的C++源代码的一部分:

int main(int argc, char** argv){
  int r, c, nDegree, nBlockSize;
  printf("Reading Images\n");
  BYTE** pSrc = getImage(argv[1], r, c);
  BYTE** pGround = getImage(argv[2], r, c);
  set<pair<int, int>, LessFunctionClass> matchedIndex;
  time_t start_time, end_time, prog_time;   

  start_time = time(NULL);

  nDegree = 6;
  nBlockSize = 24;
  printf("Calculating Zernike\n");
  //error happens here
  calculateZernike(pSrc, r, c, nDegree, nBlockSize);
  printf("Zernike calculated\n");
int main(int argc,char**argv){
整数r、c、n度、n度;
printf(“读取图像”);
字节**pSrc=getImage(argv[1],r,c);
字节**pGround=getImage(argv[2],r,c);
设置匹配索引;
开始时间、结束时间、进展时间;
开始时间=时间(空);
nDegree=6;
nBlockSize=24;
printf(“计算Zernike\n”);
//这里发生了错误
计算类(pSrc、r、c、Ngree、nBlockSize);
printf(“Zernike计算\n”);
编辑:函数getImage位于以下行中:

BYTE** getImage(char* fName, int& r, int& c){

IplImage* img = cvLoadImage(fName, CV_LOAD_IMAGE_GRAYSCALE);
int i, j;
BYTE **pSrc;

c = img->width;
r = img->height;

pSrc = new BYTE*[r];

for(i=0; i<r; i++){
    pSrc[i] = new BYTE[c];
}


for(i=0; i<r; i++){
    for(j=0; j<c; j++){
        pSrc[i][j] = img->imageData[i*c + j];
    }
}
cvReleaseImage( &img);
return pSrc;
} 
BYTE**getImage(char*fName,int&r,int&c){
IplImage*img=cvLoadImage(fName,CV\u LOAD\u IMAGE\u灰度);
int i,j;
字节**pSrc;
c=img->宽度;
r=img->高度;
pSrc=新字节*[r];

对于(i=0;i,正如我们在评论中所讨论的,在Zernike矩计算代码中,最内部的两个
for
循环试图访问图像中超出边界的像素。为了防止这种情况,请在进行任何计算之前尝试编写以下
if
语句:

for (k = 0; k < blockSize; k++) {
     for (l = 0; l < blockSize; l++) {
          // Change here
          if (j+k < 0 || j+k >= r || i+l < 0 || i+l >= c) 
             continue;

          sumValue.r += p_Vnm[zDegree][k][l].r * p_block[j+k][i+l];
          sumValue.j += p_Vnm[zDegree][k][l].j * p_block[j+k][i+l];
     }
}
for(k=0;k=r | | i+l<0 | | i+l>=c)
继续;
r+=p_Vnm[zDegree][k][l].r*p_块[j+k][i+l];
j+=p_Vnm[zDegree][k][l].j*p_块[j+k][i+l];
}
}

for
循环中的
if
语句应防止访问图像尺寸以外的像素。此保护措施以前不在您的代码中。

对于较小的图像
nDegree
nBlockSize
有效吗?@mad-我看到了。看起来您的错误没有发生。是否您在Zernike计算中有规定,以确保您访问的像素不会超出边界?您可以向我们显示您的Zernike矩代码吗?@mad-缩小图像的
r
c
的值是多少?是否
r
小于
nBlockSize
?(或
c
)@mad-关于
zDegree
有什么假设?它是否小于或等于
?就像在
p_Vnm[zDegree][k][l]中使用的那样,它只是一个古玩
因此,我想知道这两个循环是如何联系在一起的,是什么保证了zDegree
永远不会超过p\u Vnm的第一维度。我的直觉是,for的两个内部
循环正试图访问超出边界的像素。它可能一直起作用,直到现在为止,因为您还没有一个实例表明选定的块大小试图超出图像中的界限。在进行任何计算之前,请尝试将其放置在最内部的
循环(
l=0…
)中:
如果(j+k<0 | | j+k>=r | | i+l<0 | i+l>=c)继续;
@mad-Cool!这就是您不断出现分割错误的原因吗?
for (k = 0; k < blockSize; k++) {
     for (l = 0; l < blockSize; l++) {
          // Change here
          if (j+k < 0 || j+k >= r || i+l < 0 || i+l >= c) 
             continue;

          sumValue.r += p_Vnm[zDegree][k][l].r * p_block[j+k][i+l];
          sumValue.j += p_Vnm[zDegree][k][l].j * p_block[j+k][i+l];
     }
}