문제

I have to translate from Matlab to C this code:

   % take off the pads
   x = (1 + padSize) : (rows - pad8Size);
   y = (1 + padSize) : (cols - padSize);
   rpad=rpad(x,y);

1st and 2nd create 2 array, but I don t know how I have to delete it from rpad Mat object It can be something like(subtract every element)

    for(int i=1+pad;i<=rows-pad;i++){
     for(int j=1+pad;i<=cols-pad;j++){
            subtract(rpad,x,rpad);
           subtract(rpad,y,rpad);}}

Or something like(delete the external element)

      int a=(rows-pad)-(1+pad);
      int b=(cols-pad)-(1+pad);
      rpad.create(img.rows - a,img.cols - b,original.type());
      img.copyTo(rpad);
도움이 되었습니까?

해결책

Try

cv::Rect roi(padSize, padSize, rpad.cols-2*padSize, rpad.rows-2*padSize);
cv::Mat result = rpad(roi);

And depending on whether you want continuous memory, you can choose to directly use result (discontinuous, usually okay for most OpenCV functions) or copy it to back to rpad (continuous)

다른 팁

Is it possible to multiply a Mat object with a bidimensional array? Imfft is obviously the Mat object

      for (int i = 0; i &lt; rows; i++){
         for (int j = 0; j &lt; cols; j++){
               imfft=imfft*filter[i][j]
         }
       }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top