This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/OPT9221: Writing calibration parameters in register OPT9221

Part Number: OPT9221
Other Parts Discussed in Thread: OPT8241

Tool/software: TI C/C++ Compiler

Hello, TI!

We created our self made ToF board and we tried to perform calibration you demo-board in Voxel Viewer 0.9.10 for understanding all calibration process.

I got such error message: (it was non linear calibration)


File "D:\voxelviewerbitbucket\voxelviewer-devel\build\VoxelViewer\out00-PYZ.pyz\PyVoxelViewer.calibration.CalibrationNonLinearityPage", line 289, in calibrate
IndexError: index 2 is out of bounds for axis 1 with size 2

And can you say, how we can calculate calibration parameters for non linear calibration, temperature calibration, pixel wise calibration without using Voxel Viewer?

Because our board is not compatible with voxel viewer interface.

  • Semenov, 

    We have an open-source calibration code present here. Refer the 'calibration' directory. 

    This is all python-based, so you can refer this and create your own calibration procedure. This uses the same algorithm as Voxel Viewer. 

    Suramya

  • Suramya, Thank you for your answer, it is very useful link.

    But what is reason of error message in Voxel Viewer log?
    " File "D:\voxelviewerbitbucket\voxelviewer-devel\build\VoxelViewer\out00-PYZ.pyz\PyVoxelViewer.calibration.CalibrationNonLinearityPage", line 289, in calibrate
    IndexError: index 2 is out of bounds for axis 1 with size 2 "
  • Hi Semenov,

    Could you share your csv file? It seems that you have selected a profile with only one modulation frequency, but are trying to calibrate for two frequencies.

    Suramya
  • Hi,

    Can you please tell us if this issue is resolved?

    Regards,
    Subhash
  • Hello!

    I am sorry for so long pause.

    distance (m) phase at (cx, cy) pixel point.
    0.853 2065
    1.055 2323
    1.27 2612
    1.489 2903
    1.692 3172
    1.891 3425
    2.091 3709
    2.306 3986

    Config-file NoCalibration.

  • Semenov, 

    I am able to open the data that you gave using Voxel VIewer, for the no-calibration profile:

    Make sure that you select the "No Calibration" profile in the first wizard page. 

    The error occurs because you've selected a profile with two modulation frequencies, but giving only one phase value to the CSV file. 

    Suramya

  • Thank you for your answer!

    But I have the same troubles in VoxelViewer, when I try to calibrate.

    I did as you advised me, choose only Non-linearity Calibration in Calibration Wizard with NoCalibration profile.

    I tried both to load csv-file and to write the values by hand.

    I use win7-64bit and win10-64bit.

    VoxelViewer 0.9.10.

    all log info:

    Voxel Viewer v0.9.10

    Texas Instruments Inc.

    INFO: ParameterDMLParser: Found register map with name 'OPT9221' (vPG1P0)

    INFO: HardwareSerializer: Received 42851 bytes from hardware in 1.9344 s

    INFO: Data2DCodec: Original number of 8-bit offsets = 196

    INFO: Data2DCodec: Number of invalid pixels in original data = 0

    INFO: Data2DCodec: Current number of 8-bit offsets = 196

    INFO: CameraSystem: Successfully refreshed parameters for TintinCDKCamera(0::0451:9105::916103915826).

    INFO: ToFCameraBase: Starting with 320x240@30fpsUsing rate factor = 0.1

    Using rate factor = 0.0825973295022

    Using rate factor = 0.0825973295022

    Using rate factor = 0.0825973295022

    C:\PROGRA~1\TEXASI~1\VOXELV~1.10\VOXELV~1\pyqtgraph\graphicsItems\ImageItem.py:354: VisibleDeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

    INFO: DepthCamera: Streaming stopped.Lens Calibration False

    Modulation Frequency Calibration True

    Cross-talk Calibration True

    Non-linearity Calibration True

    Temperature Calibration True

    Common Phase Calibration True

    Pixelwise Phase Calibration True

    INFO: DepthCamera: Setting parameter 'op_clk_freq'

    INFO: DepthCamera: Setting parameter 'sub_frame_cnt_max'

    INFO: DepthCamera: Setting parameter 'quad_cnt_max'

    INFO: DepthCamera: Setting parameter 'mod_freq1'

    INFO: DepthCamera: Setting parameter 'mod_freq2'

    INFO: DepthCamera: Setting parameter 'intg_duty_cycle'

    INFO: DepthCamera: Setting parameter 'dealias_en'

    INFO: DepthCamera: Setting parameter 'unambiguous_range'

    INFO: DepthCamera: Setting parameter 'mix_volt'

    INFO: DepthCamera: Setting parameter 'intg_time'

    INFO: DepthCamera: Setting parameter 'illum_power_percentage'

    INFO: DepthCamera: Setting parameter 'delay_fb_corr_mode'

    INFO: DepthCamera: Setting parameter 'delay_fb_dc_corr_mode'[2065 2065 2065 2065 2172 2479 2792 3102 3403 3731 3986 3986 3986 3986 3986

    3986]

    Traceback (most recent call last):

    File "D:\voxelviewerbitbucket\voxelviewer-devel\build\VoxelViewer\out00-PYZ.pyz\PyVoxelViewer.calibration.CalibrationNonLinearityPage", line 289, in calibrate

    IndexError: index 2 is out of bounds for axis 1 with size 2

  • Semenov,

    There's something wrong with the "No Calibration" profile you're setting. Please share the profile from the ~/.Voxel/conf directory.

    Suramya
  • in folder ~/.Voxel/conf:
    916103915826.bin (lool like serial of demo-board)
  • Sorry Semenov,
    I think I wasn't clear.

    Please send the "TintinCDKCameraNoCalibration.conf" profile from the ~/.Voxel/conf directory.

    Suramya
  • you were clear.

    in folder ~/.Voxel/conf of win7 computer  "TintinCDKCamera" and "916103915826.bin", and only "916103915826.bin" win10 computer.

    file "TintinCDKCameraNoCalibration.conf" is found in folder Program files/Texas Instruments/VoxelViewer 0.9.10/VoxelViewer/voxelsdk/share/voxel-0.6.11/conf

    It seem it intall by default VoxelViewer installer.

    Is it means I need to move file "TintinCDKCameraNoCalibration.conf" in ~/.Voxel/conf folder?

    file "TintinCDKCameraNoCalibration.conf" in application. (but renamed from .conf to .txt only here)

    TintinCDKCameraNoCalibration.txt
    [global]
    id = 132
    name = No Calibration
    
    [params]
    
    [defining_params]
    op_clk_freq = 0
    sub_frame_cnt_max = 4
    quad_cnt_max = 4
    mod_freq1 = 48
    mod_freq2 = 48
    frame_rate = 30.00
    intg_duty_cycle = 9
    dealias_en = 0
    
    [calib]
    fx = 220.0
    fy = 220.0
    cx = 160
    cy = 120
    k1 = 0
    k2 = 0
    k3 = 0
    p1 = 0
    p2 = 0

  • Semenov,

    The conf file seems correct. There seems to be a bug with the non-linearity correction code in Voxel Viewer, which will be corrected in the next revision.

    Thanks for sharing the bug.

    Suramya
  • Thank you, Suramya.
    When will new VoxelViewer release?
  • Semenov,

    The new version will be out in the next couple of months.

    Suramya
  • Suramya,
    Thank you for your answer!
    And few last questions.
    1. In script NonLinearityCalibration function getCoefficients returns array with 17 elements, in such case I have to you first 16 values or last 16 values as calibration parameters?
    2. For example, I use dealiasing mode with f1 = 40MHz and f2 = 60 MHz,
    What is the maximum range where I have to measure dependence actual distance vs phase1 and phase2?
    Is it R1 = c/(2*f1), R2 = c/(2*f2), or R = c/(2*feff)?
    What is the parameter "period" in such case? for different frequencies it can differs sufficiently.
  • Semenov,

    1) The wizard is supposed to give only 16 parameters, can you share the part where it gives 17 parameters? These parameters should be spaced equally and start from a value close to 0 to a value close to 4096 for the complete range. Use the parameters accordingly.
    2) For two frequencies, please use a csv file with three elements in each row. You need to measure individual frequency data, and not the combined frequencies. This can be done by using ind_freq_data_en and ind_freq_data_sel registers. You should sweep through the complete range for R_sweep = max(R1, R2). You do not need the complete range (R)
    3) Period will be:
    0 for quarter of R_sweep
    1 for half of R_sweep
    2 for the complete R_sweep.

    I hope this helps.

    Suramya
  • 1. This line in function getCoefficients:

    112 offsetPoints = np.arange(0., 4096./2**(2-period)+1, 256./2**(2-period)) 


    give array with 17 elements from 0 up 4096 with equidistantly step 256 when period = 2;
    [ 0. 256. 512. 768. 1024. 1280. 1536. 1792. 2048. 2304. 2560. 2816. 3072. 3328. 3584. 3840. 4096.]

    113 y = np.around(np.interp(offsetPoints, measuredPhase, expectedPhase))


    function "interp" return array with the same size as "offsetPoints" i.e. 17 elements
    docs.scipy.org/.../numpy.interp.html

    and there is not any erasing processes with array elements in other places of code.

  • Semenov,

    Since 4096 and 0 correspond to the same value, the last point should be close to 3840, the second-last point.
    Thanks for reporting this.

    Use the first sixteen points.

    Suramya
  • Suramya,
    Thank you for your answer!

    Is the method of checking calculated NonLinearity Calibration coefficients?

    Do I need to make tg_dis stop/start and/or PLL_Update when writing nonlinear calibration parameters (not only this ones but other too) to the OPT9221?

  • Hi, I am also trying to understand how the python calibration works for OPT8241. I understand that 4 phase values are collected to calculate the distance value. But in this discussion I see only one phase being mentioned. How are 4 raw phase values connected to this single phase used in calibration conf file ?

  • Semenov,

    I didn't understand the question.
    You do not need to update the pll or toggle tg_dis when writing NonLinearity calibration parameters. Pixel-wise phase offsets and lens correction is done in software, so you may need to stop and start the camera (if you're using VoxelSDK) on updating these values. For all other parameters, the values can directly be written without toggling any other registers.

    Suramya
  • Tauseef,

    This question is unrelated to this thread. Please create a new thread for your questions.

    Suramya
  • Suramya, Thank you for your answer!

    I am sorry for unclear question.

    "Is the method of checking calculated NonLinearity Calibration coefficients?"

    I meant if I got some array nonLinearityCalibration[16] after calibration process, than I wrote this one to register opt9221, how  can I understand that phase/depth map is better than before?

    In NonLinearityCalibration.py

    151    if y1:
    
    154    print "phase_lin_coeff1 = " + data

    may be some bug in line 151:

    if y1.all

    and some bug in line 154:

    print "phase_lin_coeff1 = " + data1

    and about common offset correction:

    Is some main physical/technical difference between CommonPhaseOffsetSimpleAverage and CommonPhaseOffsetComplexAverage algorithms?

    And in CommonPhaseOffsetSimpleAverage.py

    82     centerShape = [cx-window/2, cx+window/2, cy-window/2, cy+window/2]


    103 averagePhase = np.sum(averagePhase)/(window*window)


    when window = 4. it is meant centsrShape is square with side 5 at center (cx, cy) (25 point)

    but averaging is made by window x window, (16 points)

    
    

    Or may be I do not understand something?

  • Semenov,

    After applying the calibration parameters, you should capture the phase at different distances. The measured phase should be closer to the expected phase that you provided as input.

    Note that you have to do common phase offset calibration after correcting for nonlinearity.

    Suramya
  • Suramya, Thank you for your answer!

    But I updated my question.
  • Semenov,

    Python does not take the last index, so the number of points are 16. Complex average considers the phase to be complex (amplitude* exp(j*(phase))), while simple average just averages the phase. There's not much difference between the results of both.

    I'll look at the NonLinearityCalibration code.

    Suramya
  • Suramya, Thank you for your answer!

    So, what is the window-averaging it is better to use for calculation phase_corrX (for example window = 4):
    cx - 2, cx - 1, cx, cx + 1
    or
    cx - 2, cx - 1, cx, cx + 1, cx + 2?
    (the same about cy)
  • Semenov, 

    If the second is used, this would make the window size 5. Actually, the value shouldn't make much of a difference as we're trying to find the common offset for all pixels (ideally, this should just be the center pixel). It would be better, for symmetry to use the second one. 

    Suramya 

  • Suramya, Thank you for your answer!