Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to disable auto exposure and set manual exposure time? #15

Open
chenliang1986 opened this issue Jan 22, 2021 · 0 comments
Open

How to disable auto exposure and set manual exposure time? #15

chenliang1986 opened this issue Jan 22, 2021 · 0 comments

Comments

@chenliang1986
Copy link

chenliang1986 commented Jan 22, 2021

I follows your guide and enable raspberrypi camera_v2 as a USB Camera for Windows PC.
The bmControls changed as follows:
cat /sys/kernel/config/usb_gadget/pi4/functions/uvc.usb0/control/processing/default/bmControls
255
47

cat /sys/kernel/config/usb_gadget/pi4/functions/uvc.usb0/control/terminal/camera/default/bmControls
14
0
0

Now the brightness/saturation/sharpness/contrast can runtime change and take effect, but the auto exposure mode is always 0 and change the exposure time don't take effect.
I also change the /usr/bin/v4l2-ctl -c auto_exposure=1, then the auto exposure mode is fixed to manual mode, the exposure time can runtime change and take effect, but the auto exposure mode can't change to auto mode any more.
It looks like the auto exposure mode is fixed by below codes and can be changed. If delete the line /usr/bin/v4l2-ctl -c auto_exposure=0, the result is the auto exposure mode is fixed to auto mode.

#!/bin/bash

sudo /home/pi/uvc-gadget/multi-gadget.sh
/usr/bin/v4l2-ctl -c auto_exposure=0 // change to 1 manual mode
/usr/bin/v4l2-ctl -c auto_exposure_bias=8
/usr/bin/v4l2-ctl -c contrast=20
/usr/bin/v4l2-ctl -c video_bitrate=25000000
sudo /home/pi/uvc-gadget/uvc-gadget -u /dev/video1 -v /dev/video0

The test application as follows, the Auto Exposure Mode is always 0 even if I call cap.set(CV_CAP_PROP_AUTO_EXPOSURE, 1) to change to manual AE mode. The application can work well is use Windows PC default front camera.

#include "opencv2/opencv.hpp"
#include

using namespace cv;
using namespace std;

int main()
{
VideoCapture cap(1);
Mat frame;

auto exp_time = cap.get(CV_CAP_PROP_EXPOSURE);
cout << "Init Exposure Time: " << exp_time << endl;

auto gain = cap.get(CV_CAP_PROP_GAIN);
cout << "Init Gain: " << gain << endl;

auto ae_mode = cap.get(CV_CAP_PROP_AUTO_EXPOSURE);
cout << "Init Auto Exposure Mode: " << ae_mode << endl << endl;

cap.set(CV_CAP_PROP_AUTO_EXPOSURE, 1);

exp_time = cap.get(CV_CAP_PROP_EXPOSURE);
cout << "Exposure Time: " << exp_time << endl;

gain = cap.get(CV_CAP_PROP_GAIN);
cout << "Gain: " << gain << endl;

ae_mode = cap.get(CV_CAP_PROP_AUTO_EXPOSURE);
cout << "Auto Exposure Mode: " << ae_mode << endl << endl;

cap >> frame;

int i = 0;
while (waitKey(30) != 27)
{
	i++;
	i %= 100;
	cap.set(CV_CAP_PROP_EXPOSURE, (i / 10) - 10);

	exp_time = cap.get(CV_CAP_PROP_EXPOSURE);
	cout << "Exposure Time:" << exp_time << endl;

	gain = cap.get(CV_CAP_PROP_GAIN);
	cout << "Gain: " << gain << endl;

	ae_mode = cap.get(CV_CAP_PROP_AUTO_EXPOSURE);
	cout << "Auto Exposure Mode: " << ae_mode << endl << endl;

	cap >> frame;
	putText(frame, "Exposure:" + to_string(i / 10 - 10), Point(20, 30), 3, 1.0, Scalar(255, 0, 0));
	imshow("Piwebcam", frame);
}

return 0;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant