Setting up the exposure time of a webcam
Hello. I have this very cheap webcam that I sent a patch to support on gspca the other day. The specific driver is the t613.
I changed the lens of this camera, and now my images are all too bright, what I believe is due to the much larger aperture of this new lens. So I would like to try setting up a smaller exposure time on the camera (I would like to do that for other reasons too).
The problem is there's no "exposure" option to be set when I call programs such as v4lctl. Does that mean there is definitely no way for me to control the exposure time? The hardware itself was not designed to allow me do that? Or is there still a chance I can create some C program that might do it, for example?
It looks like the camera has some kind of automatic exposure control. If I cover the lens, and then uncover it quickly, the image is all white at first, and then it gradually becomes darker. Should that give me some hope of being able to control the exposure, or is it common for cheaper cameras to have just an automatic exposure control that cannot be overrun?
Thanks,
++nicolau
Signature · 3 lines
Nicolau Werneck <[email protected]> 1AAB 4050 1999 BDFF 4862 http://www.lti.pcs.usp.br/~nwerneck 4A33 D2B5 648B 4789 0327 Linux user #460716
Quoted 14 lines · Nicolau Werneck
Hello. I have this very cheap webcam that I sent a patch to support on gspca the other day. The specific driver is the t613.
I changed the lens of this camera, and now my images are all too bright, what I believe is due to the much larger aperture of this new lens. So I would like to try setting up a smaller exposure time on the camera (I would like to do that for other reasons too).
The problem is there's no "exposure" option to be set when I call programs such as v4lctl. Does that mean there is definitely no way for me to control the exposure time? The hardware itself was not designed to allow me do that? Or is there still a chance I can create some C program that might do it, for example?
Quoted 6 lines
It looks like the camera has some kind of automatic exposure control. If I cover the lens, and then uncover it quickly, the image is all white at first, and then it gradually becomes darker. Should that give me some hope of being able to control the exposure, or is it common for cheaper cameras to have just an automatic exposure control that cannot be overrun?
Nicolau,
Having had some experience with cheap cameras, I would say that they come with all kinds of variations. Thus, this particular camera (with which I am _not_ experienced) could either have a built-in automatic exposure control, or it could require monitoring from software with periodic correction of various settings. It just depends.
Thus, one thing to do is to look carefully at some usbsnoop logs and try to see if there are occasional correction sequences in between big hunks of data. If there are, then the next thing is to figure out what those correction sequences are doing. Then build those correction sequences into the driver. An example of this kind of thing going on can be seen in lots of the camera drivers in gspca, but not in all of them.
Second thing, try to look for sensor setup commands which give initial settings. If there are such, then one or more of them might control exposure settings.
Third, if there are no occurences of either of the previous items at all, then either the camera does not self-adjust and can not be adjusted (i. e. really, really cheap), or the adjustment mechanism is completely built-in. In that case, I would say that you are probably up a tree about getting the exposure reset.
Hope this helps you.
Theodore Kilgore
Thanks for the reply, I'll look out for those possible correction commands... But the adjustment when I cover the lens already happens in the Linux driver, so I guess it's just something internal, right?
I went back to the original driver to see if I could make the camera usable again, and I succeeded by turning off the automatic white balance, and changing the values of the balance by hand. There are three values for R G and B that can be set from 0 to 127. Can gspca support something like that? v4lctl doesn't offer anything like that out of the box, and I couldn't find possible functions in the code. Does that array in the setwhitebalance function (t613.c) set these values that the win driver offers the user to set?
thanks,
++nicolau
Quoted 53 lines · Theodore Kilgore
Quoted 14 lines · Nicolau Werneck
Hello. I have this very cheap webcam that I sent a patch to support on gspca the other day. The specific driver is the t613.
I changed the lens of this camera, and now my images are all too bright, what I believe is due to the much larger aperture of this new lens. So I would like to try setting up a smaller exposure time on the camera (I would like to do that for other reasons too).
The problem is there's no "exposure" option to be set when I call programs such as v4lctl. Does that mean there is definitely no way for me to control the exposure time? The hardware itself was not designed to allow me do that? Or is there still a chance I can create some C program that might do it, for example?
Quoted 6 lines
It looks like the camera has some kind of automatic exposure control. If I cover the lens, and then uncover it quickly, the image is all white at first, and then it gradually becomes darker. Should that give me some hope of being able to control the exposure, or is it common for cheaper cameras to have just an automatic exposure control that cannot be overrun?
Nicolau,
Having had some experience with cheap cameras, I would say that they come with all kinds of variations. Thus, this particular camera (with which I am _not_ experienced) could either have a built-in automatic exposure control, or it could require monitoring from software with periodic correction of various settings. It just depends.
Thus, one thing to do is to look carefully at some usbsnoop logs and try to see if there are occasional correction sequences in between big hunks of data. If there are, then the next thing is to figure out what those correction sequences are doing. Then build those correction sequences into the driver. An example of this kind of thing going on can be seen in lots of the camera drivers in gspca, but not in all of them.
Second thing, try to look for sensor setup commands which give initial settings. If there are such, then one or more of them might control exposure settings.
Third, if there are no occurences of either of the previous items at all, then either the camera does not self-adjust and can not be adjusted (i. e. really, really cheap), or the adjustment mechanism is completely built-in. In that case, I would say that you are probably up a tree about getting the exposure reset.
Hope this helps you.
Theodore Kilgore
Signature · 3 lines
Nicolau Werneck <[email protected]> 1AAB 4050 1999 BDFF 4862 http://www.lti.pcs.usp.br/~nwerneck 4A33 D2B5 648B 4789 0327 Linux user #460716
Quoted 8 lines · On Tue, 26 Jan 2010 15:00:53 -0200 Nicolau Werneck <[email protected]> wrote:
Hello. I have this very cheap webcam that I sent a patch to support on gspca the other day. The specific driver is the t613.
I changed the lens of this camera, and now my images are all too bright, what I believe is due to the much larger aperture of this new lens. So I would like to try setting up a smaller exposure time on the camera (I would like to do that for other reasons too).
Quoted 5 lines
The problem is there's no "exposure" option to be set when I call programs such as v4lctl. Does that mean there is definitely no way for me to control the exposure time? The hardware itself was not designed to allow me do that? Or is there still a chance I can create some C program that might do it, for example?
[snip]
Hello Nicolau,
There are brightness, contrast, colors, autogain and some other video controls for the t613 webcams. You must use a v4l2 compliant program to change them, as vlc or v4l2ucp (but not cheese).
Regards.
Signature · 2 lines
Ken ar c'hentañ | ** Breizh ha Linux atav! ** Jef | http://moinejf.free.fr/
HI Nicolau....
remember to send a SOB if the patch is working, and any change let me know so i can test with others t613 users.
Best Regards
Quoted 34 lines · Jean-Francois Moine
Quoted 8 lines · On Tue, 26 Jan 2010 15:00:53 -0200 Nicolau Werneck <[email protected]> wrote:
Hello. I have this very cheap webcam that I sent a patch to support on gspca the other day. The specific driver is the t613.
I changed the lens of this camera, and now my images are all too bright, what I believe is due to the much larger aperture of this new lens. So I would like to try setting up a smaller exposure time on the camera (I would like to do that for other reasons too).
Quoted 5 lines
The problem is there's no "exposure" option to be set when I call programs such as v4lctl. Does that mean there is definitely no way for me to control the exposure time? The hardware itself was not designed to allow me do that? Or is there still a chance I can create some C program that might do it, for example?
[snip]
Hello Nicolau,
There are brightness, contrast, colors, autogain and some other video controls for the t613 webcams. You must use a v4l2 compliant program to change them, as vlc or v4l2ucp (but not cheese).
Regards.
--
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Setting up white balance on a t613 camera
In reply to Jean-Francois MoineHello again, people. I believe I have found in my log the commands that are setting up that white balance parameters. I am pasting an excerpt of the log at the end. (I changed the subject now that is seems this is actually the way I should follow)
It looks to me that in that SetupPacket vector the "88" encodes what channel to set. 87 for red, 88 for blue and 89 for green. The following value is the level, which is default to 0x20.
The question now is how do I offer to set up that parameter in the driver? What function can I use to transmits a vector that way, so I can make a hacky test?
In other words: would it be possible or me to just cut and paste some code in the driver to implement that? Or will I be finally forced to actually learn what I am doing? :)
regards,
++nicolau
(...)
[61857 ms] <<< URB 393 coming back <<<
-- URB_FUNCTION_CONTROL_TRANSFER:
PipeHandle = 89fecb10
TransferFlags = 0000000a (USBD_TRANSFER_DIRECTION_OUT,
USBD_SHORT_TRANSFER_OK)
TransferBufferLength = 00000000
TransferBuffer = 00000000
TransferBufferMDL = 00000000
UrbLink = 00000000
SetupPacket =
00000000: 40 00 00 00 88 1c 00 00[61910 ms] UsbSnoop - DispatchAny(bac00610) :IRP_MJ_INTERNAL_DEVICE_CONTROL
[61910 ms] UsbSnoop - MyDispatchInternalIOCTL(bac01e80) :
fdo=89cf58b0, Irp=89473e48, IRQL=0
[61910 ms] >>> URB 394 going down >>>
-- URB_FUNCTION_VENDOR_DEVICE:
TransferFlags = 00000000 (USBD_TRANSFER_DIRECTION_OUT,
~USBD_SHORT_TRANSFER_OK)
TransferBufferLength = 00000000
TransferBuffer = 00000000
TransferBufferMDL = 00000000
no data supplied
UrbLink = 00000000
RequestTypeReservedBits = 00000000
Request = 00000000 Value = 00000000 Index = 00001e88
[61913 ms] UsbSnoop - MyInternalIOCTLCompletion(bac01db0) :
fido=00000000, Irp=89473e48, Context=898d8fe8, IRQL=2
[61913 ms] <<< URB 394 coming back <<<
-- URB_FUNCTION_CONTROL_TRANSFER:
PipeHandle = 89fecb10
TransferFlags = 0000000a (USBD_TRANSFER_DIRECTION_OUT,
USBD_SHORT_TRANSFER_OK)
TransferBufferLength = 00000000
TransferBuffer = 00000000
TransferBufferMDL = 00000000
UrbLink = 00000000
SetupPacket =
00000000: 40 00 00 00 88 1e 00 00[61950 ms] UsbSnoop - DispatchAny(bac00610) :
IRP_MJ_INTERNAL_DEVICE_CONTROL
[61950 ms] UsbSnoop - MyDispatchInternalIOCTL(bac01e80) :
fdo=89cf58b0, Irp=89f97008, IRQL=0
[61950 ms] >>> URB 395 going down >>>
-- URB_FUNCTION_VENDOR_DEVICE:
TransferFlags = 00000000 (USBD_TRANSFER_DIRECTION_OUT,
~USBD_SHORT_TRANSFER_OK)
TransferBufferLength = 00000000
TransferBuffer = 00000000
TransferBufferMDL = 00000000
no data supplied
UrbLink = 00000000
RequestTypeReservedBits = 00000000
Request = 00000000 Value = 00000000 Index = 00002088
(...)
Quoted 33 lines · Jean-Francois Moine
Quoted 8 lines · On Tue, 26 Jan 2010 15:00:53 -0200 Nicolau Werneck <[email protected]> wrote:
Hello. I have this very cheap webcam that I sent a patch to support on gspca the other day. The specific driver is the t613.
I changed the lens of this camera, and now my images are all too bright, what I believe is due to the much larger aperture of this new lens. So I would like to try setting up a smaller exposure time on the camera (I would like to do that for other reasons too).
Quoted 5 lines
The problem is there's no "exposure" option to be set when I call programs such as v4lctl. Does that mean there is definitely no way for me to control the exposure time? The hardware itself was not designed to allow me do that? Or is there still a chance I can create some C program that might do it, for example?
[snip]Hello Nicolau,
There are brightness, contrast, colors, autogain and some other video controls for the t613 webcams. You must use a v4l2 compliant program to change them, as vlc or v4l2ucp (but not cheese).
Regards.
Signature · 6 lines
Ken ar c'hentañ | ** Breizh ha Linux atav! ** Jef | http://moinejf.free.fr/ -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Nicolau Werneck <[email protected]> 1AAB 4050 1999 BDFF 4862 http://www.lti.pcs.usp.br/~nwerneck 4A33 D2B5 648B 4789 0327 Linux user #460716
Re: Setting up white balance on a t613 camera
Answering my own question, and also a question in the t613 source code...
Yes, the need for the "reg_w(gspca_dev, 0x2087);", 0x2088 and 0x2089 commands are definitely tied to the white balance. These three set up the default values I found out. And (X << 8 + 87) sets up the red channel parameter in general, and 88 is for green and 89 for blue.
That means I can already just play with them and see what happens. My personal problem is that I bought this new lens, and the image is way too bright, and changing that seems to help. But I would like to offer these as parameters the user can set using v4l2 programs. I can try making that big change myself, but help from a more experienced developer would be certainly much appreciated!...
++nicolau
Quoted 20 lines · Nicolau Werneck
Hello again, people. I believe I have found in my log the commands that are setting up that white balance parameters. I am pasting an excerpt of the log at the end. (I changed the subject now that is seems this is actually the way I should follow)
It looks to me that in that SetupPacket vector the "88" encodes what channel to set. 87 for red, 88 for blue and 89 for green. The following value is the level, which is default to
0x20.The question now is how do I offer to set up that parameter in the driver? What function can I use to transmits a vector that way, so I can make a hacky test?
In other words: would it be possible or me to just cut and paste some code in the driver to implement that? Or will I be finally forced to actually learn what I am doing? :)
regards,
++nicolau
Signature · 3 lines
Nicolau Werneck <[email protected]> 1AAB 4050 1999 BDFF 4862 http://www.lti.pcs.usp.br/~nwerneck 4A33 D2B5 648B 4789 0327 Linux user #460716
Re: Setting up white balance on a t613 camera
Quoted 8 lines · On Wed, 27 Jan 2010 15:17:53 -0200 Nicolau Werneck <[email protected]> wrote:
Answering my own question, and also a question in the t613 source code...
Yes, the need for the "
reg_w(gspca_dev, 0x2087);",0x2088and0x2089commands are definitely tied to the white balance. These three set up the default values I found out. And (X << 8 + 87) sets up the red channel parameter in general, and 88 is for green and 89 for blue.
Quoted 6 lines
That means I can already just play with them and see what happens. My personal problem is that I bought this new lens, and the image is way too bright, and changing that seems to help. But I would like to offer these as parameters the user can set using v4l2 programs. I can try making that big change myself, but help from a more experienced developer would be certainly much appreciated!...
Hello Nicolau,
The white balance is set in setwhitebalance(). Four registers are
changed: 87, 88, 89 and 80.
Looking at the traces I have, these 4 registers are loaded together only one time in an exchange at startup time. Then, the white balance control adjusts only blue and red values while reloading the same value for the green register (that's what is done for other webcams), and the register 80 is not touched. In the different traces, the register 80 may be initialized to various values as 3c, ac or 38 and it is not touched later. I do not know what it is used for.
I may also notice that the green value in the white balance exchanges may have an other value than the default 20. I do not know which is the associated control in the ms-win driver. If it is exposure, you are done. So, one trivial patch is:
- add the exposure control with min: 0x10, max: 0x40, def: 0x20.
- modify the whitebalance control with min: -16, max +16, def:0.
- there is no function setexposure() because the exposure is the value of green register. Both controls exposure and white balance call the function setwhitebalance().
- in the function setwhitebalance(), set the green value to the exposure, the red value to (exposure + whitebalance) and blue value to (exposure - whitebalance) and load only the registers 87, 88 and 89.
An other way could be to implement the blue and red balances in the same scheme, and to remove the whitebalance.
Cheers.
Signature · 2 lines
Ken ar c'hentañ | ** Breizh ha Linux atav! ** Jef | http://moinejf.free.fr/
Re: Setting up white balance on a t613 camera
Yes, as wrote in the code, it tied to whitebalance.
Also note that , as Jean wrote, there's are many different values wrote on some registers, that we don't really know what they are used for, so,
i would like to go for the most non intrusive option, since, some of this whitebalance regs, have been adjusted time to time to meet other t613 users requirment's, and maybe implementing the r/b balance would be the way to go.
If you want, i can write it so you can test it, or if you prefeer you can take a look at
http://linuxtv.org/hg/~jfrancois/gspca/file/21f2eeb240db/linux/drivers/media/video/gspca/sonixj.c
at how its done as an example.
Since i only had this webcam for 1 week, i always relay on the some group of users that are willing to test each change always.
Best Regadrs.
Costantino Leandro
Quoted 62 lines · Jean-Francois Moine
Quoted 8 lines · On Wed, 27 Jan 2010 15:17:53 -0200 Nicolau Werneck <[email protected]> wrote:
Answering my own question, and also a question in the t613 source code...
Yes, the need for the "
reg_w(gspca_dev, 0x2087);",0x2088and0x2089commands are definitely tied to the white balance. These three set up the default values I found out. And (X << 8 + 87) sets up the red channel parameter in general, and 88 is for green and 89 for blue.Quoted 6 lines
That means I can already just play with them and see what happens. My personal problem is that I bought this new lens, and the image is way too bright, and changing that seems to help. But I would like to offer these as parameters the user can set using v4l2 programs. I can try making that big change myself, but help from a more experienced developer would be certainly much appreciated!...
Hello Nicolau,
The white balance is set in
setwhitebalance(). Four registers are
changed: 87, 88, 89 and 80.Looking at the traces I have, these 4 registers are loaded together only one time in an exchange at startup time. Then, the white balance control adjusts only blue and red values while reloading the same value for the green register (that's what is done for other webcams), and the register 80 is not touched. In the different traces, the register 80 may be initialized to various values as 3c, ac or 38 and it is not touched later. I do not know what it is used for.
I may also notice that the green value in the white balance exchanges may have an other value than the default 20. I do not know which is the associated control in the ms-win driver. If it is exposure, you are done. So, one trivial patch is:
- add the exposure control with min:
0x10, max:0x40, def:0x20.- modify the whitebalance control with min: -16, max +16, def:0.
- there is no function
setexposure()because the exposure is the value of green register. Both controls exposure and white balance call the functionsetwhitebalance().- in the function
setwhitebalance(), set the green value to the exposure, the red value to (exposure + whitebalance) and blue value to (exposure - whitebalance) and load only the registers 87, 88 and 89.An other way could be to implement the blue and red balances in the same scheme, and to remove the whitebalance.
Cheers.
--
Ken ar c'hentañ | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
--
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: Setting up white balance on a t613 camera
In reply to Jean-Francois MoineHi,
Quoted 18 lines · Jean-Francois Moine
Quoted 8 lines · On Wed, 27 Jan 2010 15:17:53 -0200 Nicolau Werneck<[email protected]> wrote:
Answering my own question, and also a question in the t613 source code...
Yes, the need for the "
reg_w(gspca_dev, 0x2087);",0x2088and0x2089commands are definitely tied to the white balance. These three set up the default values I found out. And (X<< 8 + 87) sets up the red channel parameter in general, and 88 is for green and 89 for blue.Quoted 6 lines
That means I can already just play with them and see what happens. My personal problem is that I bought this new lens, and the image is way too bright, and changing that seems to help. But I would like to offer these as parameters the user can set using v4l2 programs. I can try making that big change myself, but help from a more experienced developer would be certainly much appreciated!...
Quoted 5 lines
Hello Nicolau,
The white balance is set in
setwhitebalance(). Four registers are
changed: 87, 88, 89 and 80.
Hi,
About whitebalancing, currently libv4l does whitebalancing completely in software for camera's which cannot do it automatically in hardware.
That is libv4l calculates and applies 3 software gains to get the average green red and blue values the same.
In the future it might be an idea to start supporting hardware per color gains for this, but there are a number of issues with that:
1) The controls used for this then need to be standardized.
2) As we don't know the exact dB scale of the hardware gains we need some sort of approximation algorithm, like with autogain / exposure. Leading to potential overshoot, oscilating etc.
Esp 2. makes me wonder if we want to use the hardware color gains (when the hardware cannot autoadjust them) at all. Calculating a software gain so that the averages become equal is trivial, and does not need any settling time etc.
Note that in case of whitebalance the color correction gain can easily be done in software (as it is in the range of circa 0.7 - 1.3) unlike things like exposure and the main gain which we really must set correctly at the hardware level for a usable picture.
To give libv4l's software whitebalance a try do:
export LIBV4LCONTROL_FLAGS=8
And then run a webcam viewing app from the same commandline
You can also run a control panel like v4l2ucp like this:
export LIBV4LCONTROL_FLAGS=8 LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so v4l2ucp
To get a whitebalance control with which you can toggle the whitebalance on/off while streaming so that you can see the effect it has on the picture.
Regards,
Hans