Raspberry Pi 4 with Camera Module v2 no video input with higher resolutions

Greetings!
I am writing a program in C++ for face detection in a room. The camera supports up to 3280x2464 pixel resolution, but if I change it in the code I can’t get input from it when the resolution is higher then 1280x720 pixels. The default value is 640x480 and I want to use as much as possible for the best results. The initial test showed that HD is still not enough.
I use the V4L2 driver, as the manifacturer suggested it as the best one for this camera. I store the VideoCapture object in a vector (I will need multi camera support in the future), and I tried it on my laptop with an USB camera with similar parameters (it is an Arducam, 8MP) and everything worked perfectly. I tried as well looking for answer on forums and I may missed it, but did not managed to find anything related to this problem.
Thanks for any help in advance!

welcome.

you’ll need to provide details.

What details I should provide exactly?

you won’t get the full resolution for video, only for stills. OpenCV’s VideoCapture can only do video mode, not still capture mode.

I’m no expert. I don’t have the hardware. I can guess but I can’t test.

if this was python, I’d say use the picamera package. I don’t know what it does underneath. it might just be V4L, but with crucial and specific settings.

why do you need such a high resolution for face detection ?
what exactly are you doing there ?

just a funny idea: what about using dnn based superresolution instead of cranking up the camera ?

But I would have to get input when the res is set to 1920x1080 as the camera is supporting it with 30fps, but nothing above 1280x720 pixels work.
Sadly python is out of the picture as I need performance, the first code was in python actually, and so slow on raspberry that we needed to work with C++ instead. But I will look for some similar library as the picamera.

It’s a school project, we need to achive a presence monitoring system into a school classroom. As it is not that small room, we decided to use a higher resolution camera. With the current backend (it’s not yet optimized in any ways as we could not start testing due to covid) is unable to recognise everyone in the room with the given maximum HD resolution. And as I said, nothing else works above it, not even FHD which is supported for sure, and it’s just really sad, because with other testing enviroments we had no problems so far.

The idea is not bad, but already there are two dnns running on the Raspberry, and the goal is to remain as much in real time as much we can.

ok, can you talk a bit about your face detection method ?

webcams can run slower or not at all when the wrong pixel format is selected.

you might have to use V4L2 directly, or find some wrapper specific to the pi camera.

you will certainly need something other than OpenCV’s VideoCapture if you want a still resolution frame… is my suspicion. I can’t say it’s impossible with OpenCV VideoCapture but I would guess that it is impossible.

if your python code was “slow”, you did something silly such as using python loops over individual pixels (instead of using OpenCV or numpy functions). all the heavy lifting happens in libraries, which are often written in C++. good python code uses libraries. there’s no reason not to use python.

We use a neural network for face detection, it is loaded from an example prototxt file with weights from a caffemodel (it was a free OpenCV example if I remember correctly).
So basically the dnn does the face detection.

It is strange for me, because I tested it this morning again on my computer with an Arducam 8MP 1080p USB Camera Module IMX219 (sadly I cannot connect the raspberry camera to the computer directly), and it worked without problems on the highest resolution with OpenCV’s VideoCapture. I was able to set the resolution and then I had input from it, I saved the frame to disk and checked, it was a 3264x2448p picture. But I will search for an alternative to pythons picamera.

That can be, it is my very first experience with computer vision and with OpenCV also I have a lot less experience with python compared to C++.

so, do you resize the input to some fixed size, like 192x144, like here ?
(the OpenFace recognition network, if youre using this, also has a fixed window of 96x128)

i’m still arguing, that you probably won’t get much from a higher image resolution

high resolution makes sense here because the faces are far away/small. it also makes sense to not resize. the point is to find small faces. the area to search being large is an obvious consequence.

I don’t resize the input. The dnn’s height and widht value are set to the cameras dimensions.

I agree with @crackwitz, the faces are really small on the picture mainly the ones that are sitting in the back of the room. We want to cut the places where won’t ever be faces (like left and right side or the upper area of the picutre). With this we will speed up the whole process a bit. But not even FHD resolution was enough for the dnn to recognize the faces far away.

For now I found a RaspiCam library similar to the picamera. It has OpenCV integration as well if the libraries are found while compiling the source. I just hope it can use USB cameras as well, because we want to add multi-camera support later.

1 Like