#๐Ÿ”’ fisheyecalibration

21 messages ยท Page 1 of 1 (latest)

errant laurel
#

Hello, i'm having issue with fisheye calibration

magnitude = 1.0
new_w, new_h = int(w * magnitude), int(h * magnitude)
new_DIM = (new_w, new_h)


balance = 0  
new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(
    K, D, DIM, np.eye(3), balance=balance, new_size=new_DIM
)

print("new_K:", new_K)


map1, map2 = cv2.fisheye.initUndistortRectifyMap(
    K, D, np.eye(3), new_K, new_DIM, cv2.CV_16SC2
)

The new_K is always output NaN, why is that?

If i'm removing the estimateNewCameraMatrixForUndistortRectify and use it directly like this

    map1, map2 = cv2.fisheye.initUndistortRectifyMap(
        K, D, np.eye(3), K, DIM, cv2.CV_16SC2)

The output of distort img is normal with the images have been calibrated

I want to use the estimateNewCameraMatrixForUndistortRectify because of the image could be scalable

worthy ravenBOT
#

@errant laurel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

undone pumice
#

!paste

worthy ravenBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

errant laurel
undone pumice
#

I can't see anything obvious. I would check that your input values match what you expect them to.

candid summit
#
print("Original DIM:", DIM)
print("New Dimensions (new_DIM):", new_DIM)
print("Camera Matrix (K):", K)
print("Distortion Coefficients (D):", D)
print("Balance:", balance)

can u add these first and give me the output so i can debug it for u. @errant laurel

errant laurel
errant laurel
#

But if i'm adding the estimateNewCameraMatrixForUndistortRectify into the code, the output become black image

#

And the problem come from the new_K outputing only NaN, so idk why

new_K: [[nan  0. nan]
 [ 0. nan nan]
 [ 0.  0.  1.]]
candid summit
#
balance = 0.01 
new_K = cv2.fisheye.estimateNewCameraMatrixForUndistortRectify(
    K, D, DIM, np.eye(3), balance=balance, new_size=new_DIM
)
print("Estimated new_K:", new_K)

also do this and give me output

errant laurel
errant laurel
#
DIM: (1280, 960)
new_DIM: (1280, 960)
K: [[450.7178932    0.         633.26931447]
 [  0.         451.56641645 493.48975785]
 [  0.           0.           1.        ]]
D: [[-0.0652063 ]
 [ 0.05214419]
 [-0.03969624]
 [-0.00844822]]
Estimated new_K: [[inf  0. inf]
 [ 0. inf inf]
 [ 0.  0.  1.]]
Traceback (most recent call last):
  File "C:\Users\Buivi\Desktop\TestCode\undistort.py", line 100, in <module>
    undistort(img_path, DIM, K, D)
  File "C:\Users\Buivi\Desktop\TestCode\undistort.py", line 72, in undistort
    raise ValueError("new_K contains invalid (NaN or Inf) values. Check inputs.")
ValueError: new_K contains invalid (NaN or Inf) values. Check inputs.
candid summit
errant laurel
#

If i'm using directly like this

map1, map2 = cv2.fisheye.initUndistortRectifyMap(
        K, D, np.eye(3), K, DIM, cv2.CV_16SC2
    )

The output is good tho

worthy ravenBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.