OV9281 occasional capture timeout on CM3

I am using a CM3 which interfaces with the OV9281 using a custom carrier board.

I have a python script based heavily off of the capture2opencv.py demo - it sits in a while loop capturing images.

I have set my gpu allocation as following:
[email protected]:~ $ vcgencmd get_mem gpu gpu=128M <code></code>

My wiring is a little bit different to a standard CM3 carrier so I have reflected this change in my setup:
`
self._camera = arducam.mipi_camera()

define hw wiring for OV9281

self.camera_interface = arducam.CAMERA_INTERFACE()
self.camera_interface.i2c_bus = 0
self.camera_interface.camera_num = 1
self.camera_interface.sda_pins = (28, 0)
self.camera_interface.led_pins = (44, 5)
self.camera_interface.shutdown_pins = (44,5)

self._camera.init_camera2(self.camera_interface)
self._fmt = self._camera.set_resolution(640, 400)
self._camera.software_auto_exposure(enable = True)
`

My main loop is pretty much identical to capture2opencv.py:
`
while True:

update frame

frame = self._camera.capture(encoding = ‘i420’)
height = int(self.align_up(fmt[‘height’], 16))
width = int(self.align_up(fmt[‘width’], 32))
image = frame.as_array.reshape(int(height * 1.5), width)
image = cv2.cvtColor(image, cv2.COLOR_YUV2BGR_I420)
`

My problem is that after 50 or so images, the arducam_capture() method will timeout and return a NullPtr. (Definition located here)

My current work around is the very hacky following to catch the buffer being a Null Pointer. It will just reinitialise the camera again and it will operate normatlly for another ~50 images before the error occurs again.
try: image = frame.as_array.reshape(int(height * 1.5), width) except ValueError as e: print("ValueError: {}".format(e)) self._camera.close_camera() self._camera.init_camera2(self.camera_interface) continue <code></code>

I have been using this camera with a 3B+ for several weeks and haven’t had this problem.

(Also posted on git repo: https://github.com/ArduCAM/MIPI_Camera/issues/24)

Just in addition - subsequent images taken are just plain white. So the hacky reboot posted above doesn’t fix anything.

Disregard the above message about plain white images - I wasn’t resetting the sensor type.

Timeout issue still exists however…

Hi,

Sorry for my late reply. The result you have got is very strange, I have copied your problems to our engineer and we will check it and reply you as soon as possible.

Hi @lukedempsey ,

After my test I can’t reproduce the problem you described, I will upload my test code with the attachment.

Hi Wong,

I will give it a try tomorrow and let you know how I go.

Cheers, Luke

Hi Wong,

I’ve found the problem and appear to have it working consistently now - it isn’t a camera or driver issue.

I ommitted several lines in my previous post to try an simplify it down but removed this line which appears to cause the issue:

fmt = self._camera_get(fmt)

(^The above line was in the main loop (for some reason) and was therefore updating many times a second)

Note when I initialised the camera, I had:
self._fmt = self._camera.set_resolution(width, height)

So I had two variables (fmt & self._fmt) which I was using interchangeably.

Not entirely sure how this caused the error, but it’s fixed and I’m satisfied.

Thankyou for your support

Hi @lukedempsey ,

Can you try to turn off auto exposure?

After my debugging, the problem seems to be in automatic exposure, I am trying to solve it, but I can not guarantee to solve it in a short time, if you can not wait, you can use it without automatic exposure.

Hi @wong,

I have tried setting camera.software_auto_exposure(enable=False) - the error still occurs.

I have also tried camera.software_auto_white_balance(enable=False),
Changing the encoding to ‘jpeg’ and ‘raw’

Were you replicating this issue on your hardware too?

It is definitely the capture() method returning NULL

This snippet of code:

print(f"Frame: {c}") frame = camera.capture(encoding = 'i420') print(f"Buffer Ptr: {frame.buffer_ptr}") print(f"Buffer Ptr: {id(frame.buffer_ptr)}") #print(f"Length: {frame.length}")

 


returns the following on a failed frame:

Frame: 1055 Buffer Ptr: <arducam_mipicamera.LP_BUFFER object at 0x7515f210> Buffer Ptr: 1964372496 NULL pointer access

Hi @lukedempsey ,

I reproduced this problem on CM3, but this problem only appeared when camera.software_auto_exposure (enable = True), and I did not reproduce this problem on RPI 3B.

The test code I used is capture0, I mentioned it in reply #21497

Hi @lukedempsey ,

I am not in the office now, I wrote another test script, but it has not been tested, I am not sure it will work, you can give it a try.