The OV7670 CMOS Camera [Product Link] is an image sensor + DSP that operates at a maximum of 30 fps and 640 x 480 (“VGA”) resolutions equivalent to 0.3Megapixels, and is used in object detection and tracking applications.
- Optical size 1/6 inch
- Resolution 640×480 VGA
- Onboard regulator requires only single 3.3V supply
- Standard 0.1inch pin pitch header connector
- Mounted with high quality F1.8 / 6mm lens
- Output support for Raw RGB, RGB (GRB 4:2:2, RGB565/555/444), YUV (4:2:2) and YCbCr (4:2:2) formats
- High sensitivity for low-light operation
- Low operating voltage for embedded portable apps
- Standard SCCB interface compatible with I2C interface
- Supports image sizes: VGA, CIF, and any size scaling down from CIF to 40×30
- Image quality controls including color saturation, hue, gamma, sharpness (edge enhancement), and anti-blooming
- ISP includes noise reduction and defect correction
- Supports LED and flash strobe mode
- Supports scaling
- Flicker (50/60 Hz) auto detection
- Edge enhancement level auto adjust
- Operating Voltage: 2.5 – 3V (internal LDO for nuclear power 1.8V)
A image captured using this module can be pre-processed by the DSP before sending it out which can be configured via the Serial Camera Control Bus (SCCB). This module comes without a FIFO buffer.
There are a total of 18 pins spaced 0.1″, in a 9×2 arrangement.
- VDD: Power supply 3.3V (3.0V – 3.6V)
- GND: Ground level
- SDIOC: SCCB clock (Input)
- SDIOD: SCCB data (Input/Output)
- VSYNC: Vertical synchronization (Output)
- HREF: Horizontal synchronization (Output)
- PCLK: Pixel clock (Output)
- XCLK: System clock (Input)
- D0-D7: Video parallel (Output)
- RESET: Active low – Reset (Input)
- PWDN: Active high – Power down(Input)
The I/O pins of the module work at 2.8V, with a maximum value of 3.0V being supplied to the input pins.
A 5V supply to the VDD must be avoided. If you use 3.3V on the I/O pins, the internal I/O protection diodes will clamp the I/O voltage to 2.8V which may however, with continuous use, degrade the OV7670 faster and cause more power loss.
A video is a succession of frames, where each frame is a still image taken at an instant of time. A frame is comprised of lines, and each line is further comprised of pixels. A pixel is the smallest part of a digital image, and it looks like a colored dot. An image with a resolution of 3×3 pixels has 3 rows (lines), each with 3 pixels.
A Monochrome/Grayscale images will have pixels which have shades of grey ranging from a value of black(0) to white(255), and each pixel is stored as 8 bits.
An RGB image stores each pixel as intensity gradient values of red, green and blue colors. In the RGB888 format each pixel is stored in 24 bits, where the red, green and blue intensity values are stored in 8 bits each. This means that the intensity of each color can go from 0 to 255, where 0 is the absence of that color, and 255 is the maximum intensity of that color. The RGB formats used by the OV7670 are:
Where the numbers represent the number of bits assigned to each color gradient. In the RGB565 format, the red color gradient is stored in 5 bits, the green color gradient in 6 bits and the blue color gradient in 5 bits. These formats take less memory during storage but sacrifice the number of colors that can be differentiated.
YCbCr is another format in which a color image can be digitally encoded. For a pixel, the Y (luminance) component is the amount of white light of a color, the Cb and Cr are the chroma components, which encode the blue and red color levels respectively, relative to the Y component. The Y channel encodes the gray scale levels of the image. Therefore, the easiest way to get a monochrome image from the OV7670 is to extract the Y channel of the YCbCr format. OV7670 uses the YCbCr422 format.
|Byte 0||Byte 1||Byte 2||Byte 3|
The Cb and Cr components are shared between two consecutive pixels (e.g. pixels 0 and 1 share Cb0 and Cr0), and their data is stored in 4 bytes. Data arrives in the order- Cb0, Y0, Cr0, Y1, Cb2, Y2, Cr2, Y3…
In the YCbCr422 format, two pixels are “compressed” into 4 bytes or 32 bits, this means each pixel is stored in 16 bits, and 12 bytes store 6 pixels. The extra advantage of YCbCr is that the Y channel is the Grayscale image which in RGB can be obtained only by averaging the values of the 3 color components.
The OV7670 sends the data in a parallel synchronous format. To get any data out of the OV7670, it is necessary to supply a clock signal on the XCLK pin, which must have a frequency between 10 and 48 MHz. To clock the OV7670, it is possible to alternatively use a micro-controller which can generally output its inner system clock pre-scaled by some factor. If the micro-controller doesn’t have clock output capability, but you’re using an external crystal, then connect the OSC_OUT pin to the OV7670.
After a clock signal has been applied to the XCLK pin, the OV7670 will start driving its VSYNC, HREF and D0-D7 pins.
The D0-D7 must be sampled at the rising edge of the PCLK signal and D0-D7 must be sampled only when HREF is high. The rising edge of HREF signals the start of a line, and the falling edge of HREF signals the end of the line.
All the bytes sampled when HREF was high, correspond to the pixels in one line. By default, the format is YCbCr422, this means that in average two bytes correspond to a pixel.
The signals for a “VGA” (640×480) frame are shown above. During HSYNC high state, we capture 640 pixels, equivalent to a line. The 480 lines, equivalent to a frame, are captured during the low state of VSYNC. This means that the falling edge of VSYNC signals the start of a frame, and its rising edge signals the end of a frame.
By default, the PCLK will have the same frequency of XCLK, however pre-scalers and PPLs can be configured using the SCCB, to produce a PCLK of different frequency. A PCLK of 24 MHz will produce 30 fps, a PCLK of 12 MHz will produce 15 fps and so on. All this is independent of the format of the image (VGA, CIF, QCIF, etc).
The inner DSP pre-processes the image before it is sent, making OV7670 versatile. The DSP can be accessed by using the SCCB (Serial Camera Control Bus) interface. The SCCB protocol is similar to the I2C protocol.
To change the frames per second (fps), change the frequency of PCLK by modifying the following registers via the SCCB.
For example, if we have a 8 MHz input clock and want a 24 MHz PCLK. The only possible configuration is prescaler by 2, and PLL x6; CLKRC Bit must be 0, to enable prescaler; CLKRC Bit[0-5] must be 1, to enable prescaler by 2; DBLV Bit[7-6] must be 10, to enable PLL x6.
SCCB Functional Specification [Link]
OV7670 with Arduino Uno and Mega [Arduino Forum Post]
Arduino Code to handle OV7670 [Github]
Reference 1 [Cheat Sheet by Jorge Aparicio]
Possible Application Areas
Some possible uses for this camera are in the object recognition, object tracking, image capture and image processing applications.
Did you create a project using this product? Leave details/links below!