Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct distortion figure in calib3d documentation #12966

Merged
merged 1 commit into from
Oct 29, 2018

Conversation

catree
Copy link
Contributor

@catree catree commented Oct 26, 2018

This pullrequest changes

Related #12958
To be merged after #12958

Second figure shows that barrel distorted image is smaller than the original one (thus k1 < 0), thing that I was not aware. I hope that it will be useful for other people too.

Ugly code to generate the second figure:

import numpy as np
import cv2 as cv

img = np.ones((480, 640, 3), dtype=np.uint8)*255

xmin = 100
xmax = 640-xmin
ymin = 80
ymax = 480-ymin

def distort(pt):
  u = pt[0]
  v = pt[1]

  fx = 600.0
  fy = 600.0
  cx = 640.0/2.0
  cy = 480.0/2.0
  x = (u - cx) / fx
  y = (v - cy) / fy

  k1 = -1.5
  r2 = x**2 + y**2
  x_dist = x * (1.0 + k1*r2)
  y_dist = y * (1.0 + k1*r2)

  u_dist = x_dist*fx + cx
  v_dist = y_dist*fy + cy

  return (int(u_dist), int(v_dist))

step = 1
for x in range(xmin, xmax, step):
  pt1 = (x, ymin)
  pt2 = (x+step, ymin)
  cv.line(img, pt1, pt2, (0,0,255), 2)

  pt1_dist = distort(pt1)
  pt2_dist = distort(pt2)
  cv.line(img, pt1_dist, pt2_dist, (255,0,0), 2)

  pt1 = (x, ymax)
  pt2 = (x+step, ymax)
  cv.line(img, pt1, pt2, (0,0,255), 2)

  pt1_dist = distort(pt1)
  pt2_dist = distort(pt2)
  cv.line(img, pt1_dist, pt2_dist, (255,0,0), 2)


for y in range(ymin, ymax, step):
  pt1 = (xmin, y)
  pt2 = (xmin, y+step)
  cv.line(img, pt1, pt2, (0,0,255), 2)

  pt1_dist = distort(pt1)
  pt2_dist = distort(pt2)
  cv.line(img, pt1_dist, pt2_dist, (255,0,0), 2)

  pt1 = (xmax, y)
  pt2 = (xmax, y+step)
  cv.line(img, pt1, pt2, (0,0,255), 2)

  pt1_dist = distort(pt1)
  pt2_dist = distort(pt2)
  cv.line(img, pt1_dist, pt2_dist, (255,0,0), 2)

cv.imshow('img', img)
cv.imwrite('img_distortion.png', img)
cv.waitKey(0)

…nds to pincushion distortion and negative to barrel distortion. Add another figure that illustrates the influence of k1 in the distortion effect.
@alalek
Copy link
Member

alalek commented Oct 27, 2018

Rebased due merge conflicts. Please take a look.

@vpisarev vpisarev self-assigned this Oct 29, 2018
@vpisarev
Copy link
Contributor

@catree, thank you! 👍

@opencv-pushbot opencv-pushbot merged commit d37164b into opencv:3.4 Oct 29, 2018
@alalek alalek mentioned this pull request Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants