Page 1 of 1

Capture still images from HQ Camera 12.3MP

Posted: Fri Sep 18, 2020 8:26 am
by tuannm
Hi everyone,
I want to capture images using two HQ Cameras 12.3MP but when I use the code from the "stereopi-tutorial" package with 1_test.py file, it did not work. But that code works well for two V1 cameras.

This is the link of the code: https://github.com/realizator/stereopi- ... /1_test.py

So, anyone knows how to modify the code properly, please help me.
Thank you guys so much.

Re: Capture still images from HQ Camera 12.3MP

Posted: Fri Sep 18, 2020 4:35 pm
by Realizator
Hello Tuannm,
This issue was discussed in this topic.
12.3MPix can be captured as a photo, as RPi GPU able to process it. But the OpenCV code works with this as with video by default, and tries to request a lot of images per second. Even for modern phones, 4K is a limit for recording, and you are trying to capture ~8K video with real-time processing. Too many for the Raspberry Pi. :-)
Usually for the real-time OpenCV video processing onboard it is better to reduce the camera resolution.
But if you wish to get the highest processing quality (i.e. depth map resolution), you can capture 12Mpix photos (like one per 2-3 seconds).

Re: Capture still images from HQ Camera 12.3MP

Posted: Sat Sep 19, 2020 1:15 am
by tuannm
Hello Realizator,

I think my issues here are a bit different from the previous topic. Even though I tried with resolution 2028x1128 (or whatever), I got an error like this:

File "/usr/lib/python3/dist-packages/picamera/camera.py", line 123, in capture, 'Timed out waiting for capture to end'
picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end

My target is that I actually want to activate the view of two cameras to manually change the focus lens before decide to capture the stereo images. Then, I tend to perform the depth map on the desktop (not on raspberry pi).

I did that with 1_test.py or 1_tmp.py (according to your advice from the previous topic) but it still was an error like above.
By the way, I cannot visualize the focus lens of the two cameras using raspistill command.

Please help me with code using two HQ cameras,
Thank you so much.

Re: Capture still images from HQ Camera 12.3MP

Posted: Sat Sep 19, 2020 1:34 pm
by Realizator
Okay, some tips for you:

1. You can use raspistill for each camera, using a command "raspistill -cs 0 ..." for the first camera, and "raspistill -cs 1" for the second. Please check your system can show both images to be sure your cameras are connected correctly.
advanced tip: original raspivid can't show a stereoscopic preview, even in -3d mode. But we did a fixed version, which can do this. This fixed version is used in our SLP image. To add a stereoscopic mode you need to add "-fs" key after "raspivid". You can find the fixed binary here in our SLP image: /opt/StereoPi/bin/raspivid

2. HQ cameras have a bigger resolution, and some new sensor modes. Try to turn on 2nd mode.
I.e., before fixes you can see a row like this:

Code: Select all

camera = PiCamera(stereo_mode='side-by-side', stereo_decimate=False)
turn on 2nd sensor mode by adding 'sensor_mode = 2', to have a line like this:

Code: Select all

camera = PiCamera(stereo_mode='side-by-side', sensor_mode = 2, stereo_decimate=False)
3. raspistill and raspivid are extremely optimized C-based applications. You won't be able to get the same speed in Python (I mean a video with the 2028x1128 resolution). For your focus adjustment procedure, I'd recommend you to decrease your resolution to have a higher FPS. And at the moment of taking a picture, you can turn on a higher resolution. This way you will get a smooth preview video for a focus adjustment, and a high-resolution photos.

If you are curious about the details, take a look at this article, where we compared the performance of C++ and Python code for OpenCV.

Re: Capture still images from HQ Camera 12.3MP

Posted: Sun Sep 20, 2020 1:11 am
by tuannm
Hi Realizator,
I prefer the second tip and it works well for me.
Thank you for your support.

Re: Capture still images from HQ Camera 12.3MP

Posted: Sat Sep 26, 2020 11:47 pm
by tuannm
Hi Realizator,

I really want to receive your help with another problem.
I tried to capture stereo images with a resolution of greater than 2560x960 but it did not work well. As you can see in the attached photo, there is something wrong on the right side of the images.
Image Link: https://drive.google.com/file/d/1kK2mK9 ... sp=sharing
I set scale_factor=1 to get the exact above resolution. And I also set all things similar to your suggestion (in viewtopic.php?f=9&t=857).

When I reduce to 2560x960, it works well but the resolution is quite low for me. I want to increase it a little bit.

Thank you so much.

Re: Capture still images from HQ Camera 12.3MP

Posted: Sun Sep 27, 2020 12:16 am
by stereomaton
Someone else had a problem with vertical stripes, and it was related to the resolution used. See viewtopic.php?p=2057#p2057

Re: Capture still images from HQ Camera 12.3MP

Posted: Sun Sep 27, 2020 12:26 am
by tuannm
hi stereomaton,

I have already followed the rule for width and height values. For example width = 2592, height = 976, and the vertical stripes began to appear.
But it is fine for a resolution of 2560x960 or less. I expect to get a minimum resolution of 2688x1024 but it did not work.

I hope to receive your help.

Re: Capture still images from HQ Camera 12.3MP

Posted: Mon Sep 28, 2020 11:22 am
by Realizator
Hello Tuan,
Could you please share a code you are using for the image capture? I will try to run it on my device and find an issue.
I can suggest that automatic resolution adjustment in the code can cause this issue. The fastest way for me to fix this is to look at your code.

Re: Capture still images from HQ Camera 12.3MP

Posted: Tue Sep 29, 2020 2:34 am
by tuannm
hi Realizator,

Let me send you the capture file that I use to get stereo images with a resolution of 2592x976.
Link: https://drive.google.com/file/d/1MQDAny ... sp=sharing
I set scale_factor=1, gpu_mem=256, (0 < value.width <= self.MAX_RESOLUTION.width*2) as you suggested in the previous post.

Thank you.

Re: Capture still images from HQ Camera 12.3MP

Posted: Tue Sep 29, 2020 3:03 pm
by Realizator
Hello Tuan,
Solution: use image witdh multiple by 64, but not 32. It should work.

Explanation: PiCamera capture requirements (for the width multiple of 32) is used for 1 camera. And we have a couple, so buffer should be able to keep a couple of frames, with the width of each multiple to 32.

If you take a look at your captured image actual resolution, it is 2624x992. It means PiCamera automatically adjust the width to be multiple of 64 (as 2624/64 = 41). And if you are using 2592, it is not multiple of 64 (2592/64 = 40,5).

Re: Capture still images from HQ Camera 12.3MP

Posted: Wed Sep 30, 2020 12:33 am
by tuannm
hi Realizator,

Thank you for your kindly support.
But it still didn't work for me. So, please see the short video for this clear issue.
Link: https://drive.google.com/file/d/1zKUkuL ... sp=sharing
Even though, I changed cam_width = int((cam_width+63)/64)*64) but it still encoutered the same problem.
I don't know why 2560x960 seems to be a limited resolution for my case.

I hope to receive another solution.

Re: Capture still images from HQ Camera 12.3MP

Posted: Wed Sep 30, 2020 9:11 am
by Realizator
Hello Tuan,
I took a closer look at this issue. PiCamera video subsystem is not designed for the video with a very high resolution, and this caused a problem. I changed "use_video_port" to False, to use still image port, and it works. For the still port GPU does more processing work (like color adjustment, noise reduction, etc.), so you should achieve a relatively small actual FPS. As an example, I took a photo with the resolution, which exceeds your needs (3000x1100), and attached a sample code I used.
I also added image resize before showing it to the user, as it takes a lot of resources for Python to visualize this huge picture.

As we discussed in similar topics, direct capturing of extremely-high resolution images by means of Python is not the optimal way. It is better to use another approach for this task (like capturing by raspivid/raspiyuv and pass it to Python by pipe, for example).

Re: Capture still images from HQ Camera 12.3MP

Posted: Thu Oct 01, 2020 2:07 am
by tuannm
hi Realizator,

It finally works for me and I should accept that the average FPS is very low (~1.5 FPS with 2688x1024).
Thank you so much for your support.