0

I have written code to convert an image to two part in Matlab as below

img1=imge(1:M,1:0.55*N,:);
img2=imge(1:M,0.55*N:N,:);

here imge is my input image, I am trying to convert this code to opencv. I tried to use cv::Resize ,but that doesn't work. Can you please help me out?

Ishant Mrinal
  • 4,898
  • 3
  • 29
  • 47
  • note that MATLAB would issue the following warning: `Warning: Integer operands are required for colon operator when used as index`, so perhaps you should use fix/round to make sure the index `0.55*N` is a whole number – Amro Jul 14 '13 at 16:42
  • Yahh, i did this.thanks – Ishant Mrinal Jul 15 '13 at 04:03

1 Answers1

0

Try:

int b = static_cast<int>(0.55*N);
cv::Mat img1 = img.rowRange(0,M).colRange(0,b);
cv::Mat img2 = img.rowRange(0,M).colRange(b,N);

Note that this simply creates a matrix header, the underlying data of the new matrix is shared with the original matrix.

Amro
  • 123,847
  • 25
  • 243
  • 454