0

I am recently reading the code of cv::getRectSubPix in OpenCV, which involves dealing rectangles out of image. Concretely, I am stuck on function adjustRect that is used to reshape the out-of-bounds rectangular window.
According to the code of adjustRect, top left corner p=(x,y) of rectangle will shift to p'=(-x,-y)(blue frame) if p(red frame) is as follows: enter image description here What puzzled me was the last line in adjustRect:

return src - rect.x*pix_size;

why src is shifted in x direction only? To my understanding, proper code should be:

return src - rect.x*pix_size-rect.y*src_step

Besides, I think src will point to undefined memory if both x and y are negative. Can anyone help?

Finley
  • 795
  • 1
  • 8
  • 26

1 Answers1

0

Basically, adjustRect should be considered together with codes in getRectSubPix_Cn_. OpenCV adopts different interpolation strategies when pixel rectangle is out of image.
It will dereference properly when indexing pixels because:

s0 = src[r.x*cn + c]*b1 + src2[r.x*cn + c]*b2; .

For my case, this interpolation scheme is depicted in following figure: enter image description here This post waits to be updated because I think there should be more details to be discovered.

Finley
  • 795
  • 1
  • 8
  • 26