IMX519 Zoom factor at max focus

  1. Where did you get the camera module(s)?
    ArduCam partner

  2. Model number of the product(s)?
    IMX519
    B0371

  3. What hardware/platform were you working on?
    Jetson Nano 2GB B01 with Ubuntu platform

  4. Instructions you have followed. (link/manual/etc.)
    Writing software through the QT GUI that uses opencv 3d framework to determine the required focal range of a predefined object that is rotated on a center stage. Because the camera is capturing at a set angle I use the focal range to step through the increments of focus building an image one band at a time. Every raw capture is scaled by the current focus level and then the area cropped and placed into the output image in the appropriate place.

  5. Problems you were having.
    As I changed the focus level zoom makes minor adjustments. I have been trying to make minor adjustments but can’t get it to line up just right. The final image should be seamless.

  6. The dmesg log from your hardware.
    NA

  7. Troubleshooting attempts you’ve made.
    I used paint.net to manually line them up for a baseline. That has not proven to be as reliable as I need.
    My current code does the following.
    const int MAX_FOCUS = 1000;
    const double FOCUS_WIDTH_RATIO = 0.565f;
    const double FOCUS_HEIGHT_RATIO = 0.424F;

// I set the final width and height of the image based on the absolutely level of the camera at max focus. This is done so that all images taken at a later time line up exactly.
uint final_Width = 4656 - (FOCUS_WIDTH_RATIO * MAX_FOCUS);
uint final_Height = 3496 - (FOCUS_HEIGHT_RATIO * MAX_FOCUS);

int yMarker = maxY; // maxY represents the lowest point on the raw image where the object is visible
int yBand = (int)qPow(qSqrt(yMarker),slope); // The yBand is the +/- area that will be in focus on the image based on where the focus is set to. The slope is based on the stage angle with the camera.
int yFocus = (int)(((double)yMarker/(double)raw_img.height())*(double)MAX_FOCUS);

In this example the final resolution of the image would be 4091 x 3072.

The Here is an example image from the process.

  1. What help do you need?
    What is the correct zoomed height/width factor when focus is set to the maximum value of 1000? Does the value change on a curve or a straight line?

@CBPSaga

Amazing idea.

There is a curvilinear relationship between the value of vcm (image distance) and the object distance.

IMX519 (B0371) related parameters:
focal length: 4.28mm

Their relationship is as follows:

use thin lens formula:
42bd75a5-1be3-42c9-8cd6-442851a3082f

The relationship between focus value and image distance:
In order to use the above curves in the program, we need to know the relationship between focus value (vcm control value) and image distance, which requires calibration.
Here are the results of our calibration:
y = 12350x - 52244.74
x is image distance, y is focus value.

for imx519 vcm control value range [0-4095].
Note: FocusExample.py script scale [0-4095] to [0-1000]

1 Like

Thank you for the encouragement!
I used the calibration information that you posted to modify my approach to calculating the focus value, and the band in focus. I took my original approach of placing the item in real space with opencv and adjusted it as follows:
Note: values in my 3d space are done in mm.

Calculate the 3D space

  1. rotate and place the 3d object in world coordinate system.
  2. process the min (-12.5) and max(+12.5) Z value
  3. create a new set of points with X/Y set to 0 and the Z value incrementing by 25 starting at the min Z and going to the max Z value.
  4. translate the set of points to the camera coordinate system.

Calculate the 2D space.

  1. runs the set points from step 3 through cv:projectpoints()
  2. correlates the points from 2d space with 3d space
    a. focus is started in 3d space focus = calcFocus(3d[1])
    b. the crop band is set to the 2d space. y = 2d[2], height = 2d[0]
  3. for loop repeats step 2 till finished incrementing bucket by 2 each step.
  4. the last item in the settings object list has its crop band set to y = 0, height = settings[settings.size-2].y
  5. the first item in the settings object list has its crop band set to y = settings[0].y, height = image_height - settings[0].y

I am very grateful to have that part of the equation locked down. Thank you for that!

I do still have the question of how much the field of view changes as the focus value changes.



I have added three images to show you what I’m seeing. The first two are focal values at opposite ends of the spectrum. The last one I overlapped the images and set the opaque value to 100 of 255 for the top layer. You can see how the images do not line up. Not sure if this is a change in the field of view as the zoom len makes micro adjustments to allow for the change in focus. The higher the focus level, the lower the field of view is.

I currently have my FOV value set to 80 degrees on the X and 60 degrees on the Y. Is there a more accurate range for when the camera is at different focus levels?

@CBPSaga

As for your question, I haven’t studied it in detail yet. I’m afraid I can’t tell you more precise information for the time being.

This is indeed an interesting project. But I have a lot of other things to worry about now, I will study what you said later when I have time.

1 Like

Completely understand! I appreciate the help you have given already and nuggets of knowledge I can glean in the future.

So I have been plugging away at this for the last several hours. I started by making a color map of each 10 point increment from 800 to 1000 using the FocusExample.py scaling. Visually its very evident of the change. As I dug into coding a solution I had an ‘ah ha’ moment. It is the FOV that changes, but it is a result of another value that changes. The Focal Length is the value that is changing! I confirmed on the Arducam wiki that the process of focus is achieved by a motorized focus lens that “moves closer and further from the image sensor”.

The Focal Length that is given for the device is 4.28mm. I’m making an educated guess in stating that is the value when the vcm is at 0? If can confirm the Focal Length when at the min/max vcm control values, I can make the calculations. Thank you again for the huge help you have been!

I was poking around and found “Focus Range: 10 cm ~ infinite”. Using the calculations you provided that would mean that the camera is only good to 2976/4056 or 726/1000 focus value. I’ll keep messing with the range and see if I can better tweak it to get the full range of the hardware.