Manually Setting Exposure Time for IMX219 on Nano

Hello,

I’m trying to write to the IMX219 camera sensor register and change the exposure time in the arducam_camera.py code when it first opens the camera. However, it won’t allow me to change the exposure time. Does anyone know a way to fix this? I’m also playing around with changing the binning and that too doesn’t seem to work. However, if I write to the camera rotation register that does work.

 

class MyCamera(object):
def init(self):
pass
def open_camera(self, device = 0, width = -1, height = -1):
self.cap = cv2.VideoCapture(device, cv2.CAP_V4L2)
self.arducam_utils = ArducamUtils(device)

Adjust Settings

#self.arducam_utils.write_sensor(0x1142, 0x41A) #set 1142 from 255us to 1050us
#self.arducam_utils.write_sensor(0x1143, 0x41A) #set 1143 from 254us to 1050us
self.arducam_utils.write_sensor(0x015A, 0x3E8) #course integration time 1000
self.arducam_utils.write_sensor(0x015B, 0x3E8)
self.arducam_utils.write_sensor(0x025A, 0x3E8)
self.arducam_utils.write_sensor(0x025B, 0x3E8)
self.arducam_utils.write_sensor(0x0174, 0x00) #Set Binning H from 1 to 2
self.arducam_utils.write_sensor(0x0175, 0x00) #Set Binning V from 1 to 2
self.arducam_utils.write_sensor(0x0274, 0x00) #Set Binning H from 1 to 2
self.arducam_utils.write_sensor(0x0275, 0x00) #Set Binning V from 1 to 2
print(self.arducam_utils.read_sensor(0x015D))

turn off RGB conversion

if self.arducam_utils.convert2rgb == 0:
self.cap.set(cv2.CAP_PROP_CONVERT_RGB, self.arducam_utils.convert2rgb)

set width

if width != -1:
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)

set height

if height != -1:
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)

self.fix_orientation()

I have replied the customer through the email.

It would be quite a bit more useful for all the other readers to also post the answer here.

Hello,

Our engineer has wrote a test demo to tell user how to adjust the exposure time

 

Hi, Bin:

I tried your code, but end up with “ModuleNotFoundError: No module named ‘v4l2’”. May i know where i can get v4l2? Thank you in advance.

 

Please run the sudo apt-get install v4l2-utils to install the v4l2 lib.

 

Hi Bin:

thank you for reply. but i couldn’t install it. below is the error message:

[email protected]:~$ sudo apt-get install v4l2-utils
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package v4l2-utils
[email protected]:~$

 

by the way, one more question: if installation done successfully, the camera will use v4l2 driver, can i still use GStreamer to configure camera?

Hi @cydu123 ,

Please refer to this document: https://www.arducam.com/docs/camera-for-jetson-nano/mipi-camera-modules-for-jetson-nano/camera-demonstration/#5-31-install-v4l2-python-module

Hi Bin:

I followed exactly all the stops shown in the link you provided above.

It seems the v4l2 is installed successfully in this step:

[email protected]:~$ sudo pip3 install v4l2
WARNING: The directory ‘/home/amtd/.cache/pip’ or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Collecting v4l2
Downloading v4l2-0.2.tar.gz (23 kB)
Building wheels for collected packages: v4l2
Building wheel for v4l2 (setup.py) … done
Created wheel for v4l2: filename=v4l2-0.2-py3-none-any.whl size=13024 sha256=c18a8f3b47653e86c01b638fe9707de4b6fb7919f9b5fe32c4aed78f93125d82
Stored in directory: /tmp/pip-ephem-wheel-cache-nmfrwcjl/wheels/82/fa/1f/e86ec7e34cf44a14cae4ea0318e336be9f5ea2bf864cb055b2
Successfully built v4l2
Installing collected packages: v4l2
Successfully installed v4l2-0.2

But it still cannot find v4l2 when running the demo code in this step:

[email protected]:~/MIPI_Camera/Jetson/Jetvariety/example$ python arducam_displayer.py -d 0
Traceback (most recent call last):
File “arducam_displayer.py”, line 8, in <module>
from utils import ArducamUtils
File “/home/amtd/MIPI_Camera/Jetson/Jetvariety/example/utils.py”, line 1, in <module>
import v4l2
ImportError: No module named v4l2

 

PS: I am using IMX219 auto-focus camera on Nano, without Jetvariety adapter board.

 

Please advise. Thanks.

Hi @cydu123 ,

You are using python instead of python3, so you need to use pip to install v4l2 instead of pip3, please try sudo pip install v4l2

Hi Wong:

Thank you for your advice.

I’m using Python 3.6. So I follow the instruction to use “sudo pip3 install v4l2”. According to the instruction, “sudo pip install v4l2” is used for Python 2.7.

Hi @cydu123 ,

I noticed that you use the following command to execute the python script, so I think you are using python2.7.

python arducam_displayer.py -d 0

Can you now import the v4l2 module normally? If not, please try to install both python2.7 and python3.x v4l2 module.

 

Hi, Wong:

Sorry, I made a mistake. I installed v4l2 for python3.x, but I used python command to run it. Instead, I should use python3 to run it.

Yes, I can use v4l2 now. Thank you very much.

You are welcome. Arducam support team will try our best to help you.

 

Hi bin and wong:

I want to manually set parameters of exposure time, white balance, iris, gain, etc… There is no such example in your demo code. I used Google to search, but ended without useful findings. Can you please share some codes with me? Thank you.

Hi @cydu123 ,

What camera are you using?
Can you run v4l2-ctrl -l to see if the camera supports control?

Hi wong:

I use Arducam IMX219 auto-focus camera.

When I use “v4l2-ctl --list-formats-ext”, it returns following:

[email protected]:~$ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: ‘RG10’
Name : 10-bit Bayer RGRG/GBGB
Size: Discrete 3264x2464
Interval: Discrete 0.048s (21.000 fps)
Size: Discrete 3264x1848
Interval: Discrete 0.036s (28.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.017s (60.000 fps)

While when I use “v4l2-ctrl -l” as you advised, it returns this:

[email protected]:~$ v4l2-ctrl -l
bash: v4l2-ctrl: command not found

When I use "python3 arducam_displayer.py -d 0 ", it returns following:

[email protected]:~/MIPI_Camera/Jetson/Jetvariety/example$ python3 arducam_displayer.py -d 0
Firmware Version: 0
Sensor ID: 0x0000
Serial Number: 0x00000000

followed by a new display window showing a full green image, with a title of “Arducam”.

 

Hi @cydu123 ,

To use IMX219 on Jetson Nano, you should follow this document:
https://www.arducam.com/docs/camera-for-jetson-nano/native-jetson-cameras-imx219-imx477/imx219-8mp-camera/

For more ISP control you can refer to this:
https://forums.developer.nvidia.com/t/setting-manual-exposure-and-list-of-available-options-for-nvarguscamerasrc/74215/4