BUG: 3.2.8_beta1 - picture's red and blue colours are swaped. using v4l2 sn9c102 driver
I am running Fedora Core 6(kernel 2.6.20-1.2948) and using motion 3.2.8_beta1 compiled without ffmpeg, mysql and postgresql.
Everything compiled without error and works fine except that the saved pictures have the colours wrong. The parts of the picture that are red should be blue, and the parts that are blue should be red. This only happens with motion, other programs display picture/video with normal colour. I'm guessing this is one of the v4l2 things that need a bit more work.
I also thought it was worth mentioning that as a quick workaround I modified the bayer2rgb24 function in video_common.c, swapping all the lines
*scanpt++ = ... /* R */
and
*scanpt++ = ... /* B */
e.g.
original state:
*scanpt++ = (*(rawpt + width) + *(rawpt - width)) / 2; /* R */
*scanpt++ = *rawpt; /* G */
*scanpt++ = (*(rawpt - 1) + *(rawpt + 1)) / 2; /* B */
modified state:
*scanpt++ = (*(rawpt - 1) + *(rawpt + 1)) / 2; /* B */
*scanpt++ = *rawpt; /* G */
*scanpt++ = (*(rawpt + width) + *(rawpt - width)) / 2; /* R */
After compiling, the pictures have the correct colour.
I've included all the relevent info I could think of, let me know if there is something else.
Output from motion when running in non-daemon mode
[jaredd@box2 ~]$ motion -c /etc/motion/motion.conf
[0] Processing thread 0 - config file /etc/motion/motion.conf
[0] Motion running in setup mode.
[0] Thread 1 is from /etc/motion/motion.conf
[0] Thread 1 is device: /dev/video0 input 8
[0] Waiting for threads to finish, pid: 2797
[1] Thread started
[1] cap.driver: "sn9c102"
[1] cap.card: "SN9C10x PC Camera"
[1] cap.bus_info: "usb-0000:00:07.2-1"
[1] cap.capabilities=0x05000001
[1] - VIDEO_CAPTURE
[1] - READWRITE
[1] - STREAMING
[1] v4l2_select_input: name = "Camera", type 0x00000002, status 00000000
[1] - CAMERA
[1] Device doesn't support VIDIOC_G_STD
[1] Supported palettes:
[1] 0: BA81 (bayer rgb)
[1] 1: S910 (compressed)
[1] Test palette BA81 (352x288)
[1] Using palette BA81 (352x288) bytesperlines 352 sizeimage 101376 colorspace 00000000
[1] found control 0x00980901, "contrast", range 0,7
[1] "contrast", default 0, current 0
[1] found control 0x0098090e, "red balance", range 0,31
[1] "red balance", default 4, current 4
[1] found control 0x0098090f, "blue balance", range 0,31
[1] "blue balance", default 6, current 6
[1] found control 0x00980911, "exposure", range 293,4095
[1] "exposure", default 320, current 320
[1] found control 0x00980913, "global gain", range 0,31
[1] "global gain", default 13, current 13
[1] found control 0x08000000, "DAC magnitude", range 0,31
[1] "DAC magnitude", default 1, current 8
[1] found control 0x08000001, "green balance", range 0,62
[1] "green balance", default 2, current 2
[1] mmap information:
[1] frames=4
[1] 0 length=101376
[1] 1 length=101376
[1] 2 length=101376
[1] 3 length=101376
[1] Using V4L2
[1] Raw changes: 12 - changes after 'EedDl': 0 - labels: 0 - noise level: 23
[1] Raw changes: 52 - changes after 'EedDl': 0 - labels: 0 - noise level: 23
[1] Raw changes: 80 - changes after 'EedDl': 0 - labels: 0 - noise level: 18
[1] Raw changes: 397 - changes after 'EedDl': 0 - labels: 0 - noise level: 18
[1] Raw changes: 752 - changes after 'EedDl': 0 - labels: 0 - noise level: 17
[1] Raw changes: 716 - changes after 'EedDl': 0 - labels: 2 - noise level: 17
...
Output from lsmod
[root@box2 ~]# lsmod
...
sn9c102 90957 0
videodev 29633 1 sn9c102
v4l1_compat 16581 1 videodev
v4l2_common 26945 2 sn9c102,videodev
...
Environment
Motion version: |
3.2.8_beta1 |
ffmpeg version: |
NA |
Shared libraries: |
curl-7.15.5-1 |
Server OS: |
Fedora Core 6, kernel 2.6.20-1.2948 |
--
JaredD - 05 Jun 2007
Follow up
Strange that behaviour , since people that has a webcam with the same driver sn9c102 , seems that had not problems , take a look to this
BugReport :
http://www.lavrsen.dk/twiki/bin/view/Motion/BugReport2007x03x30x175913
Lets see where is the problem :
- 1-. What driver / version are you using ?
- 2-. what is output from lsusb -v (vendor id / product id ) ?
Not sure but maybe you need to use some application to initialize some register on your webcam to switch R->B or B->R:
http://www.linux-projects.org/modules/mydownloads/viewcat.php?cid=5
Please try to reproduce your problem with :
http://sn-webcam.sourceforge.net/#download
Thanks !
--
AngelCarpintero - 05 Jun 2007
Note: the computer that the camera is plugged into has been upgraded to Fedora 7(kernel 2.6.21-1.3194) but the colour problem still exists. The following info is based on the upgraded machine.
sn9c102 driver version is 1.1.34 (I used v4l2-tool to find that)
I had a look at
http://www.linux-projects.org/modules/mydownloads/viewcat.php?cid=5 and I used videoview(the colours were nomal) but I'm not sure how to use the device controller/debugger.
I tried sn-webcam. Everything worked and the colours were normal. sn-webcam output:
[jaredd@box2 sn-webcam]$ ./sn-webcam
--------------------------------------------------
SN-WEBCAM - v 0.8.0
--------------------------------------------------
We enumerate controls on this device :
Please wait...
V4L2 Standard controls supported by device :
=> Control contrast
min: 0 max: 7 step: 1 def: 0
=> Control red balance
min: 0 max: 31 step: 1 def: 4
=> Control blue balance
min: 0 max: 31 step: 1 def: 6
=> Control exposure
min: 293 max: 4095 step: 1 def: 320
=> Control global gain
min: 0 max: 31 step: 1 def: 13
Device designer query controls :
=> Control DAC magnitude
min: 0 max: 31 step: 1 def: 1
=> Control green balance
min: 0 max: 62 step: 2 def: 2
--------------------------------------------------
res: 352 x 288 x 24 bpp, jpeg_q: 85
dev: /dev/video0
--------------------------------------------------
Now I'm playing...
--------------------------------------------------
CONTROLS
-/+ : gain | q/a : red balance
w/s : blue balance | : green balance
r/f : gamma balance | o/k : brighness balance
i/j : contrast balance | u/h : exposure
space : show this help | p : fastest refresh
z : restore ALL cam settings to factory default
g : grab and save image
ESC : stop playing and exit
--------------------------------------------------
USB: using SBGGR8 uncompressed pixel format
--------------------------------------------------
I played 17 frame(s) in 24 second(s) fps: 0.71
I uploaded 0 image(s) by FTP
Output from lsusb -v
[root@box2 motion]# lsusb -v
...
Bus 001 Device 002: ID 0c45:600d Microdia
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 64
idVendor 0x0c45 Microdia
idProduct 0x600d
bcdDevice 1.01
iManufacturer 0
iProduct 1 USB camera
iSerial 0
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 279
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0x80
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0000 1x 0 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 1
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0080 1x 128 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 2
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0100 1x 256 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 3
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0180 1x 384 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 4
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0200 1x 512 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 5
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x02a8 1x 680 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 6
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0320 1x 800 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 7
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x0384 1x 900 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 8
bNumEndpoints 3
bInterfaceClass 255 Vendor Specific Class
bInterfaceSubClass 255 Vendor Specific Subclass
bInterfaceProtocol 255 Vendor Specific Protocol
iInterface 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81 EP 1 IN
bmAttributes 1
Transfer Type Isochronous
Synch Type None
Usage Type Data
wMaxPacketSize 0x03ff 1x 1023 bytes
bInterval 1
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82 EP 2 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0x0001 1x 1 bytes
bInterval 100
Thank you for your quick response.
--
JaredD - 05 Jun 2007
I've made a patch against last revision svn -r185 , please get svn version and give a try to see if that solves your problem.
mkdir motion
cd motion
svn co http://www.lavrsen.dk/svn/motion/trunk/ .
patch < bayer.diff
--
AngelCarpintero - 06 Jun 2007
When I try to view or download the patch I get the following error:
Attachment 'bayer.diff' does not exist
Could you please upload the patch again?
--
JaredD - 13 Jun 2007
Uploaded again
--
AngelCarpintero - 14 Jun 2007
I tried the patch but it didn't fix the problem, the pictures look the same as without the patch.
Let me know if there is anything else I can do to help.
--
JaredD - 19 Jun 2007
Strange patch submitted was from sn-webcam so it should work fine ...
Did you try other software that works fine with your camera using bayer rgb ?
--
AngelCarpintero - 26 Jun 2007
Programs that that I've used with the camera are:
- Ekiga. The picture looks normal but I don't know if it's using the bayer format.
- sn-webcam. The picture looks normal and it reports: using SBGGR8 uncompressed pixel format
- videoview. The picture looks normal but I don't know if it's using the bayer format.
- motion
To answer your question, I've used other programs but apart from sn-webcam I'm not sure what format they use.
I'm not sure if the camera supports any other formats. V4l2-tool's "Frame Format" tab has 2 "Frame index No."'s.
Frame index 0 info:
Frame type: V4L2_BUF_TYPE_VIDEO_CAPTURE
Flags: 0
Description: bayer rgb
Pixel Format: BA81
Default Fram in use: BA81
Frame index 1 info:
Frame type: V4L2_BUF_TYPE_VIDEO_CAPTURE
Flags: 1
Description: compressed
Pixel Format: S910
Default Fram in use: BA81
--
JaredD - 28 Jun 2007
I've uploaded a new patch that swaps lines instead of RGB it uses BGR that seems that is the format of your camera ... lets see if that works for you.
--
AngelCarpintero - 28 Jun 2007
That patch did the trick,
the colours are now correct.
I still wonder what caused the problem. This sort of thing never happened using the older V4l(1) sn9c102 drivers and motion. Anyway, thank you very much for your hard work!
--
JaredD - 03 July 2007
Fix record
Hi Jared ,
No problem what it's strange is that i'm still thinking that something is rotten in your driver / camera ... because usually Bayer uses RGB and not BGR but maybe i'm wrong ... so i'll apply this patch to motion trunk but i'll keep an eye for the rest of users using :
Description: bayer rgb
Pixel Format: BA81
I think that i'll have to add a new config option for let users choose between bayer rgb and bayer bgr.
motion svn r190
--
AngelCarpintero - 04 Jul 2007