Arducam_64mp autofocus via picamera2

I have not had any success, and Arducam has gone dark on any responses to us at this point. I also tried to send them a contact us form describing the issue on the morning of February 6th (last Monday) and have not received a response. While I have not received a response, I do encourage anyone having an issue with the 16 or 64mp autofocus to also send the issue to their contact us form here: Contact Arducam - Arducam

At some point they can’t continue to ignore the fact that their products are unusable, and would hopefully work to fix them.

1 Like

I’m sending the issue to arducam. I hope someone is able to solve the problem, maybe with a downgrade of libcamera to a previous version.

2 Likes

I solve the problem on my own. There was a missing part in the imx519.json file which you can find in “/usr/share/libcamera/ipa/raspberrypi”. You have to add the following part at the end of the file:

        {
            "rpi.af":
            {
                "ranges":
                {
                    "normal":
                    {
                        "min": 0.0,
                        "max": 10.0,
                        "default": 1.0
                    },
                    "macro":
                    {
                        "min": 3.0,
                        "max": 15.0,
                        "default": 4.0
                    }
                },
                "speeds":
                {
                    "normal":
                    {
                        "step_coarse": 1.0,
                        "step_fine": 0.25,
                        "contrast_ratio": 0.75,
                        "pdaf_gain": -0.02,
                        "pdaf_squelch": 0.125,
                        "max_slew": 2.0,
                        "pdaf_frames": 20,
                        "dropout_frames": 6,
                        "step_frames": 4
                    }
                },
                "conf_epsilon": 8,
                "conf_thresh": 16,
                "conf_clip": 512,
                "skip_frames": 5,
                "map": [ 0.0, 0, 15.0, 4095 ]
            }
        }

And then reboot. In this way autofocus will work. You can try easly with the command “libcamera-still -t30000” in Terminal and you can now set it in python script with the command: picam2.set_controls({"AfMode": 2}) or picam2.set_controls({"AfMode": controls.AfModeEnum.Continuous}). I hope everything is clear, let me know if it will work for you too.

1 Like

Thx for posting. I will give it a test right now and let others know if it works for me as well.

@Minesv what version of libcamera are you using? When I go into imx519.json file this is already posted at the end of it. I went line by line and confirmed that is in the json file on mine. I still am getting the error that AfMode is not advertised by libcamera.

I’m using the latest version, and I had to write this part in order to solve the problem, because I don’t have it. Maybe you can try to reinstall libcamera-dev and libcamera-app and reboot.

Well, in a final act of desperation I just started trying everything I could find in any thread anywhere. In one thread I read someone was entering “sudo ./install_pivariety_pkgs.sh -d” and now suddenly my 16mp camera will autofocus and is very clear using:
libcamera-still -t5000 --autofocus-mode auto -o test.jpg

Also Picamera2 seems to be working with:
picam2.set_controls({“AfMode”: 0, “LensPosition”: 425})

Now, if I can get all my other items installed into this environment and it still works I’ll be beside myself with joy. Will update everyone in what is probably a multi-day journey.

1 Like

And as an update. I can get the 64mp to autofocus and take a 16mp picture with libcamera-still using:
libcamera-still --autofocus-mode auto -t 8000 -o test64.jpg

I am unable to get it to take a 64mp image as it just hangs or gives me an error that it cannot allocate memory and failed to allocate buffers/start camera (even though it opens a preview and autofocuses before it throws the error).
libcamera-still --autofocus-mode auto --width 9152 --height 6944 -t 8000 -o test64.jpg

I am also unable to get it to work with autofocus within python, but still playing with it.

In python, setting dimensions down to 16mp works for me with the 64mp camera.

import time
from picamera2 import Picamera2, Preview

picam2 = Picamera2()

capture_config = picam2.create_still_configuration(main={"size": (4264,3472)})
picam2.configure(capture_config)
picam2.start()
time.sleep(1)

picam2.set_controls({"AfSpeed": 1, "AfMode": 1})

picam2.switch_mode_and_capture_file(capture_config, "image64.png")

picam2.stop()

But, still having issues when trying to capture at full resolution (removing the capture_config part main={“size”: (4264,3472)})

I receive:

[1:54:00.253199480] [2507] ERROR V4L2 v4l2_videodevice.cpp:1241 /dev/video21[17:cap]: Unable to request 1 buffers: Cannot allocate memory
Failed to allocate buffers.
Traceback (most recent call last):
  File "/home/pi/python_test/ard16.py", line 30, in <module>
    picam2.switch_mode_and_capture_file(capture_config, "image64c.png")
  File "/usr/local/lib/python3.9/dist-packages/picamera2/picamera2.py", line 1232, in switch_mode_and_capture_file
    return self.dispatch_functions(functions, wait, signal_function)
  File "/usr/local/lib/python3.9/dist-packages/picamera2/picamera2.py", line 1163, in dispatch_functions
    return job.get_result() if wait else job
  File "/usr/local/lib/python3.9/dist-packages/picamera2/job.py", line 77, in get_result
    return self._future.result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 440, in result
    return self.__get_result()
  File "/usr/lib/python3.9/concurrent/futures/_base.py", line 389, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.9/dist-packages/picamera2/job.py", line 47, in execute
    done, result = self._functions[0]()
  File "/usr/local/lib/python3.9/dist-packages/picamera2/picamera2.py", line 1208, in switch_mode_
    self.configure_(camera_config)
  File "/usr/local/lib/python3.9/dist-packages/picamera2/picamera2.py", line 956, in configure_
    raise RuntimeError("Failed to allocate buffers.")
RuntimeError: Failed to allocate buffers.

You need to enable more buffer space for 64mp: How to use arducam_64mp & arducam_64mp FAQ - #2 by Edward

1 Like

thanks for all your hard work @MichRX7
i’m really not trying to be a complainer, like all the other folks in this forum i just want this thing to work, but i am REALLY disappointed in the Arducam team for upgrading/breaking the entire thing they sold us, and not replying for WEEKS now :frowning: to what should be VERY BASIC ISSUES (like how to get the 64mp autofocus camera to take 64mp autofocus images)

cmon folks like @Dion @Edward and the rest of the support team. Help us out here, or at the very least give us (and folks like MichRX7) the source code so we can fix the stuff for you

@MichRX7 @hikinghack @Minesv @Nighthawk @mgrl

First of all I’m sorry for your experience.

I would like to make some explanations about how the focus part is used, modified again and again.
Libcamera did not implement the focus function before, so we developed it and continued to improve the way of use based on user feedback. Now libcamera has also developed this function, so we keep in sync with the official, so we made a big change.

I thought about why the usage aspect happened, it has something to do with not posting how to use it, I feel like this is missing in our work, so sorry.

The way it was resolved was that I took the advice of @AnotherDredd, an active member of our forum community, who has been supporting our work and offering ways to improve it, for which I thank you again.

Then there is the 64mp maximum resolution problem, and I have been looking for a solution.

Just like the link provided by @mgrl, I sorted out a lot of questions about 64mp, and I also hope that you can use our camera smoothly, but the reality is that there are many states, and this is one of my jobs, which is to find different states solution.

Because this post has said a lot now, if you still have questions, you can open a new post to discuss with me, I will be happy to communicate with you.

Because of other work reasons, sometimes I may see a thread being replied to. I would think that everyone was discussing together, so I didn’t participate. Or sometimes I forget to reply to certain posts. If I have any bad impression on you, I am very very sorry.

In the following work, I will also consider your feelings more, look at problems from your perspective, and be more timely.

1 Like

Well, I have tried everything in those links at this point and am still getting the error:
Failed to allocate buffers ERROR:
failed to start camera

My guess at this point is because I am running the GUI and dual monitors. I guess I’m sticking with the 16mp which is a shame.

@Edward Another problem is that when autofocus does work (in libcamera-still) it is now very slow. It takes almost twice as long to autofocus in the latest release (.12) than it did in .10. While I appreciate that some changes were made to make it compliant with the autofocus parameters added to libcamera, surely this could be better.

Can you share your autofocus algorithm? Part of the slowness appears to be that it only changes the lens position one step for every 5 frames.actually captured.

1 Like

@Nighthawk

In fact, we recently open-sourced it, including the autofocus algorithm.

We will also implement a faster autofocus algorithm later, so stay tuned.

I’ve been working with 4 separate pi’s with 64MP cameras and have managed to get them all to take 9152x6944 images. A couple of things that I am doing / not doing.

I’m not using picamera2 python libraries (was planning on trying that this weekend)

I’m doing it via a custom python app and using pOpen to execute a cmd line straight to the libcamera-still commands. I boot it up in signal mode waiting for a code execution to trigger SIGUSR1 to take the photo.

Single monitor only.

I dont show preview window at all using - n

I’m setting manual focus ( can test autofocus this weekend probably for you. I have stayed on the 0.11 drivers though as 0.12 broke my focus numbers and I need to figure those out again)

I had 2 of my Pis machine with the dtoverlay change set in the [all] area and they weren’t working at full res. moved them to [pi4] section and they worked.

3 of my Pi’s are 4GB and one is an 8GB.

My cmd line arguments are basically this
libcamera-still -t 0 -n --autofocus-mode manual --lens-position 2 --width 9152 --height 6944 --denoise cdn_off --gain 9 --shutter 10000 --awbgains 2.0,1.8 --signal -o PiCam1_%04d.jpg --framestart 1

Hope some of this may help.

1 Like

@DaveMcD

Regarding usage, you don’t have to worry about it in the future. After 0.0.12, our usage has been synchronized with the official ones, and we will not change unless there are major changes in the official ones.

For the latest update, you can refer to the link below
https://docs.arducam.com/Raspberry-Pi-Camera/Native-camera/Libcamera-User-Guide/#for-arducam-16mp64mp-autofocus-camera

Thanks Edward. Is there a documentation update that describes the units used in the focus distance changes. It used to be the reciprocal in meters as far as I understood. i.e
–lens-position 5
would have been 1/5 (0.2m)

What are the numbers in relation to now?

@DaveMcD

The scope has been changed, please see my post below for details:

In fact, this value is used to control the size of the motor current.
For all the updates later, I will write them in the document, and it will get better and better.

Thanks Edward. Is there any description though of how those numbers correspond to real world distances?

I get that they map from one value to the other but I can’t find info on what either of those numbers are measuring.