Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:35:22+00:00 2026-06-02T07:35:22+00:00

All, I have a python script that uses OpenCV to calibrate a camera. It

  • 0

All,
I have a python script that uses OpenCV to calibrate a camera. It now works with much help from stackoverflow help. But, I’m having problems with the distortion constants. I can not seem to control the number of constants fit. I want only 4 distoriton constants, not 5. In the documentation it states “That is, if the vector contains four elements, it means that K3=0”, that is what I want. So I initiate dist_const = np.zeros(4), pass it to cv2.calibrateCamera, but the returned dist_const has 5 constants returned. I’ve also tried the flag CV_CALIB_FIX_K3, but keep getting a ‘an iteger must be asigned’ error. Has anyone seen this behavior before, any help would be appreciated greatly.

import cv2 
from cv2 import cv 
import numpy as np

obj_points = [[-9.7,3.0,4.5],[-11.1,0.5,3.1],[-8.5,0.9,2.4],[-5.8,4.4,2.7],[-4.8,1.5,0.2],[-6.7,-1.6,-0.4],[-8.7,-3.3,-0.6],[-4.3,-1.2,-2.4],[-12.4,-2.3,0.9],[-14.1,-3.8,-0.6],[-18.9,2.9,2.9],[-14.6,2.3,4.6],[-16.0,0.8,3.0],[-18.9,-0.1,0.3],[-16.3,-1.7,0.5],[-18.6,-2.7,-2.2]]

img_points = [[993.0,623.0],[942.0,705.0],[1023.0,720.0],[1116.0,645.0],[1136.0,764.0],[1071.0,847.0],[1003.0,885.0],[1142.0,887.0],[886.0,816.0],[827.0,883.0],[710.0,636.0],[837.0,621.0],[789.0,688.0],[699.0,759.0],[768.0,800.0],[697.0,873.0]]

obj_points = np.array(obj_points,'float32')
img_points = np.array(img_points,'float32')

w = 1680
h = 1050
size = (w,h)

camera_matrix = np.zeros((3,3),'float32')
camera_matrix[0,0]= 2200.0
camera_matrix[1,1]= 2200.0
camera_matrix[2,2]=1.0

camera_matrix[0,2]=750.0 
camera_matrix[1,2]=750.0

dist_coefs = np.zeros(4,'float32')

retval,camera_matrix,dist_coefs,rvecs,tvecs = cv2.calibrateCamera([obj_points],[img_points],size,camera_matrix,dist_coefs,flags=cv.CV_CALIB_USE_INTRINSIC_GUESS)

print camera_matrix
print dist_coefs

link to my other question, has results for dist_coefs, from the caltech matlab code I’m trying to replace with python/opencv.

john

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:35:24+00:00Added an answer on June 2, 2026 at 7:35 am

    Change your calibrateCamera call to:

    retval,camera_matrix,dist_coefs,rvecs,tvecs = cv2.calibrateCamera([obj_points],[img_points],size,camera_matrix,dist_coefs,flags=cv2.CALIB_USE_INTRINSIC_GUESS + cv2.CALIB_FIX_K3)
    

    You don’t want to me mixing the cv2 and cv namespaces like you did in your example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled
I have a Python script that pulls in data from many sources (databases, files,
I have a web page that uses a Python cgi script to store requested
I have a python script that works great when run by itself. Based on
I have a share backup bash script that works as is, but it uses
I have python script that works fine but only when run as stand-alone, while
I have a Python script that uses Python version 2.6 syntax (Except error as
I have a data-intensive Python script that uses HTTP connections to download data. I
I have a Python script which uses the MySQLdb interface to load various CSV
I have a python script that'll be checking a queue and performing an action

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.