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

[BUG] LensPosition must be set to 4 in manual focus for "Infinity" #1098

Open
tutoduino opened this issue Aug 25, 2024 · 6 comments
Open

[BUG] LensPosition must be set to 4 in manual focus for "Infinity" #1098

tutoduino opened this issue Aug 25, 2024 · 6 comments

Comments

@tutoduino
Copy link

The manual focus is not "Infinity" when LensPosition is set to 0.0.
With LensPosition between 0 and 3, the horizon is blurred, it is clear when LensPosition = 4

My hardware is : Raspberry Pi Zero 2 W + Raspberry camera v3 (wide 120°)

Here is the test program:

import libcamera
import time
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.configure(picam2.create_still_configuration())
picam2.start()

for lens_position in range(35):
    picam2.set_controls({"AfMode": libcamera.controls.AfModeEnum.Manual, "LensPosition": lens_position})
    time.sleep(1)
    r = picam2.capture_request()
    filename = "lens-position" + str(lens_position) + ".jpg"
    metadata = r.get_metadata()
    actual_lens_position = metadata["LensPosition"]
    print("Actual LensPosition = {}, file capture in file {}".format(actual_lens_position,filename))
    r.save("main", filename)
    r.release()

picam2.stop()
@davidplowman
Copy link
Collaborator

Hi, thanks for the report.

It's worth saying that the lens position is always somewhat approximate because there is variation between different modules. However, in this case it seems to be behaving in a significantly different manner from what we expect. By any chance, do you have any other modules to compare this one against?

It does seem to me like something is significantly wrong here, and you may have a faulty module which would need to be returned to the place where you bought it.

@njhollinghurst Anything else to add, do you think?

@njhollinghurst
Copy link
Contributor

There is some variation, but this is well outside the expected range and should have been caught by factory test. Unfortunately this does suggest the camera may have been damaged during handling or shipping, and should be raised with the vendor.

If the camera otherwise works well and you want to keep it, it may be possible to edit the camera tuning file.

Other things to check: Do you have any other optics (lenses, mirrors, etc)? Is the camera tilted vertically upwards?

@tutoduino
Copy link
Author

Thanks for your reply.
No other optics.
The camera is tilted 45°.

@davidplowman
Copy link
Collaborator

Tilting the camera will generally make a difference, though it's hard to say how much. Does it behave better when it's not tilted?

@tutoduino
Copy link
Author

Tilting the camera seems to have an impact, but quite difficult to measure with my test conditions... Any official input from Raspberry would help.

@njhollinghurst
Copy link
Contributor

njhollinghurst commented Sep 6, 2024

The effect is intrinsic to the camera. But if it's permanently mounted in that orientation, it can be calibrated for.

Take a copy of the file /usr/share/libcamera/ipa/rpi/vc4/imx708_wide.json and find the "map": line which is near the bottom.
Edit it to something this (to increase focus by 4.0):

                "map": [ 0.0, 475, 33.0, 950 ]

Test the modification using:

tuning = Picamera2.load_tuning_file("imx708_wide.json", dir=".")
picam2 = Picamera2(tuning=tuning)

If you're happy with it, you can put it back into the default directory.

Alternatively, you could edit "tuning" programmatically in Python:

tuning = Picamera2.load_tuning_file("imx708_wide.json")
Picamera2.find_tuning_algo(tuning, 'rpi.af')['map']=[0.0, 475, 33.0, 950]
picam2 = Picamera2(tuning=tuning)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants