Thanks for the function. It translates to C++ seamlessly! Thanks again, Mechi
PS I'm using the MT9T001 3Mp and the MT9P031 5Mp cameras. We decided to let the PC do the Bayer conversion, sine the data stream is so big. On Jan 15, 7:06 pm, wangrui <[email protected]> wrote: > Hi Derek, > > If we turn the auto exposure on, the frame rate will drop from 13fps > to 3fps in an indoor environment. But if we change to manual exposure > and use a low exposure. Then the frame rate will be back to 13fps but > the image will be dark again. The exposure value in the code is > exactly how much time the image sensor will wait between two frames > (the value is measured by rows). The windows driver shows a poor image > with high frame rate. I guess they use a low exposure, acquire a dark > image then light it by software. > > Sorry about the pixel format. But I'm not interested much at the pixel > encodings now. I only intend to use the camera in my own java > application. And I only need the raw unprocessed 1280x1024BayerGRBG > data. The raw data which is generated directly by the sensor pixel > array consists of 1280*1024 8-bit values. Each value represent only > one color in the following sequence, > > G R G R ... > B G B G ... > .... > > But after we process it to a color image, we lost the precise pixel > location. So the raw image is more valuable although it can't be seen > directly. I wrote a JAVA function which can convertBayerdata to a > color image, in this function the missing colors are calculated by the > two or four nearest pixels which represent the same color. > > public static void decodeSBGGR8(int width, int height, byte[] bs, > int start, BufferedImage image) { > boolean evenRow = true; > int[][] is = new int[width + 2][height + 2]; > for (int y = 0; y < height; y++) { > for (int x = 0; x < width; x++) { > is[x][y] = bs[y * width + x + start] & 0xFF; > } > } > for (int y = 1; y <= height; y++, evenRow = !evenRow) { > boolean evenColumn = true; > for (int x = 1; x <= width; x++, evenColumn = > !evenColumn) { > int data = is[x][y]; > int lr = (is[x - 1][y] + is[x + 1][y]) >> 1; > int tb = (is[x][y - 1] + is[x][y + 1]) >> 1; > int r, g, b; > if (evenRow) { > // G R > // B G > if (evenColumn) { > r = lr; > g = data; > b = tb; > } else { > r = data; > g = (lr + tb) >> 1; > b = (is[x - 1][y - 1] + is[x > + 1][y - 1] > + is[x - 1][y > + 1] + is[x + 1][y + 1]) >> 2; > } > } else { > // G R > // B G > if (evenColumn) { > r = (is[x - 1][y - 1] + is[x > + 1][y - 1] > + is[x - 1][y > + 1] + is[x + 1][y + 1]) >> 2; > g = (lr + tb) >> 1; > b = data; > } else { > r = tb; > g = data; > b = lr; > } > } > int rgb = 0; > rgb = (r << 16) + (g << 8) + b; > rgb |= 0xFF000000; > image.setRGB(x - 1, y - 1, rgb); > } > } > } > > The driver defined the following pixel format, > > V4L2_PIX_FMT_SBGGR8,"Bayer8bit (BGGR)", 8,0x2d > V4L2_PIX_FMT_YUV420,"I420 (YUV 4:2:0)", 12, 0x2f > V4L2_PIX_FMT_YUYV,"YUYV (YUV 4:2:0)", 16, 0x2e > V4L2_PIX_FMT_JPEG,"JPEG (YUV 4:2:2)", 16, 0x2c > > If we choose a format, the driver will write the value in the last > column to the bridge register 0x10e0. (For example, write 0x2d for > V4L2_PIX_FMT_SBGGR8 format). For JPEG format, the driver will attach a > JPEG header to the data. But the JPEG image doesn't seem to be right > at colors. For other format, the driver will directly send the data > from SN9C202 to applications. I guess most application will use the > V4L2_PIX_FMT_JPEG format so the color is not right. > > Most problems of MT9M111 sensor have be solved by now. Today I found a > bug at the function sn9c20x_set_resolution, the line > clrwindow[4] = ((mode->width >> 10) & 0x01) | > ((mode->height >> 10) & 0x06); > should to be changed to > clrwindow[4] = ((mode->width >> 10) & 0x01) | > ((mode->height >> 8) & 0x06); > Otherwise in 1280x960 and 1280x1024 mode, SN9C202 will only return > 1280x0 and 1280x0 image. Besides this, > we also need to tell the image sensor MT9M111 to switch to full > resolution mode by adding the following code. It switchs the sensor to > a predefined context. We can also set other registers to tell the > sensor to not skip rows and columns. But switching context is easier. > > int data; > if (mode->width==1280) { > data=0x170F; // Context B output 1280x1024 > sn9c20x_write_i2c_data16(dev, 1, 0xC8, &data); > } else { > data=0x0004; // Context A output 640x512 > sn9c20x_write_i2c_data16(dev, 1, 0xC8, &data); > } > > I can get 1280x1024 image from WebCam now. It's very close to make > MT9M111 fully supported. --~--~---------~--~----~------------~-------~--~----~ Lets make microdia webcams plug'n play, (currently plug'n pray) To post to this group, send email to [email protected] Visit us online https://groups.google.com/group/microdia -~----------~----~----~----~------~----~------~--~---
