logo资料库

OV5640软件应用笔记(OV5640_camera_module_software_application_notes_1.3_Sonix).pdf

第1页 / 共100页
第2页 / 共100页
第3页 / 共100页
第4页 / 共100页
第5页 / 共100页
第6页 / 共100页
第7页 / 共100页
第8页 / 共100页
资料共100页,剩余部分请下载后查看
OV5640 Camera Module
Software Application Notes
1. How to Select Output format?
1.1 Back-end with full ISP
1.2 Back-end with YCbCr ISP
1.3 Back-end without ISP
1.4 Equations to Convert from One Format to Another
2. How to Select Output Resolution?
2.1 back-end with ISP
2.2 back-end without ISP
3. How to Adjust frame rate
4. How to set Night Mode Preview
4.1 Night Mode VGA Preview with Fixed Frame Rate
4.2 Night Mode VGA preview with Auto Frame Rate
5. How to Remove Light Band in Preview Mode
5.1 Light Band
5.2 Remove Light band
5.3 Select Banding Filter by Region Information
5.4 Select Banding Filter by Automatic Light Frequency Detection
5.5 Remove Light Band In Capture
5.6 When Light Band can not be Removed
6. White Balance
6.1 Simple White Balance
6.2 Advanced White Balance
6.3 How to select?
7. Defect Pixel Correction
8. BLC
9. Video Mode
10. Digital zoom
11. OV5640 Functions
11.1 Light Mode
11.2 Color Saturation
11.3 Brightness
11.4 Contrast
11.5 Hue
11.6 Special effects
11.7 Exposure level
11.8 Sharpness
11.9 Mirror/Flip
11.10 YUV Sequence
11.11 Clock Polarity
11.12 Compress quality
11.13 Test Pattern
12. Deal with Lens
12.1 Light fall off
12.2 Dark corner
12.3 Resolution
12.4 Optical contrast
12.5 Lens Cover
13. Reference Settings
13.1 YCbCr Reference Setting
13.1.1 VGA Preview
13.1.2 Other size preview
13.1.3 VGA 90fps video
13.1.4 QSXGA Capture
13.1.4.1 YUV mode capture
13.1.4.2 Jpg mode capture
13.1.5 Other Capture size DCW from QSXGA
13.1.6 Return to yuv mode
13.1.6.1 From 5M YUV to vga YUV
13.1.6.2 From 5M Jpg to vga yuv
13.1.7 YUV and JPEG mode change setting
13.1.7.1 YUV to JPEG setting
13.1.7.2 JPEG to YUV setting
13.1.8 Zoom function
13.2 Sensor Raw setting
13. 3 High Resolution Video
13.3.1 1080 P
13.3.2 720 P
13. 4 Mipi setting
13.4.1 VGA yuv_mipi_2lane_15fps
13.4.2 VGA yuv_mipi_2lane_15fps to 5M yuv_mipi_2lane_15fps
13.4.3 5M jpg_mipi_2lane_15fps
14. Capture Sequence
14.1 Shutter
14. 2 Dummy Lines
14. 3 Dummy Pixels
14.4 Gain
14.5 Banding Filter
14.5.1 Preview
14.5.2 Capture
14.6 Auto frame rate
14.7 Capture Sequence
14.7.1 Preview
14.7.2 Stop AEC/AGC
14.7.3 Single Focus for AF Module
14.7.4 Read preview register Value
14.7.5 Change resolution to QSXGA
14.7.6 Read capture register Value
14.7.7 Calculate Capture Exposure from preview
14.7.8 Calculate the banding filter value
14.7.9 Redistribute Exposure/Gain with target brightness unchanged
14.7.10 write back the gain/exposure value
14.7.11 Capture
14.7.12 Send finish command for AF module
14.7.13 Back to preview
14.8 Capture reference code
15. Strobe Flash Control
16. Auto Focus Application Solution
16.1 Embedded Resources
16.2 Embedded Auto Focus Solution
16.3 General Auto Focus Control Flow
16.4 How to use Embedded Auto Focus Solution
17. Frame exposure mode
17.1 Introduction
17.2 FREX function mode
17.2.1 Pad mode
17.2.2 I2c mode
17.3 System settings
17.3.1 Pad mode
17.3.2 I2c mode
17.4 Option settings
17.4.1 Exposure Time (unit: Tline)
17.4.2 Frame Delay (unit: Tframe), 3b06[7:4] default: 0
17.4.3 Flash Strobe Width (unit: Tline), 3b06[3:0] default: 4
17.4.4 Frex Shutter Signal Reverse, 3b07[2] default: 0
17.4.5 Frex Mode, 3b07[1:0] default: 0
17.4.6 Frex Precharge Time(ftx, frst width), 3817[2:0] default: 4
17.4.7 VSYNC ends time,
18. Some photos captured by 5640
OV5640 Camera Module Software Application Notes OV5640 Camera Module Software Application Notes Last Modified: May. 25th, 2011 Document Revision: 1.3 OmniVision Technologies, Inc. reserves the right to make changes without further notice to any product herein to improve reliability, function or design. OmniVision does not assume any liability arising out of the application or use of any project, circuit described herein; neither does it convey any license under its patent nor the right of others. This document contains information of a proprietary nature. None of this information shall be divulged to persons other than OmniVision Technologies, Inc. employee authorized by the nature of their duties to receive such information, or individuals or organizations authorized by OmniVision Technologies, Inc. 1 Company Confidential Confidential For Actions Only
OV5640 Camera Module Software Application Notes Table of Contents OV5640 Camera Module.....................................................................................................................1 Software Application Notes.................................................................................................................1 1. How to Select Output format?.....................................................................................................5 1.1 Back-end with full ISP..........................................................................................................5 1.2 Back-end with YCbCr ISP....................................................................................................6 1.3 Back-end without ISP...........................................................................................................6 1.4 Equations to Convert from One Format to Another.............................................................6 2. How to Select Output Resolution?...............................................................................................7 2.1 back-end with ISP.................................................................................................................7 2.2 back-end without ISP............................................................................................................7 3. How to Adjust frame rate.............................................................................................................7 4. How to set Night Mode Preview.................................................................................................7 4.1 Night Mode VGA Preview with Fixed Frame Rate..............................................................7 4.2 Night Mode VGA preview with Auto Frame Rate...............................................................8 5. How to Remove Light Band in Preview Mode............................................................................9 5.1 Light Band.............................................................................................................................9 5.2 Remove Light band...............................................................................................................9 5.3 Select Banding Filter by Region Information.......................................................................9 5.4 Select Banding Filter by Automatic Light Frequency Detection........................................10 5.5 Remove Light Band In Capture..........................................................................................10 5.6 When Light Band can not be Removed..............................................................................10 6. White Balance............................................................................................................................11 6.1 Simple White Balance.........................................................................................................11 6.2 Advanced White Balance....................................................................................................11 6.3 How to select?.....................................................................................................................11 7. Defect Pixel Correction.............................................................................................................12 8. BLC............................................................................................................................................12 9. Video Mode...............................................................................................................................12 10. Digital zoom............................................................................................................................12 11. OV5640 Functions...................................................................................................................12 11.1 Light Mode........................................................................................................................12 11.2 Color Saturation................................................................................................................14 11.3 Brightness..........................................................................................................................17 11.4 Contrast.............................................................................................................................19 11.5 Hue....................................................................................................................................21 11.6 Special effects...................................................................................................................24 11.7 Exposure level...................................................................................................................26 11.8 Sharpness..........................................................................................................................29 11.9 Mirror/Flip........................................................................................................................30 11.10 YUV Sequence................................................................................................................31 11.11 Clock Polarity.................................................................................................................31 11.12 Compress quality.............................................................................................................32 11.13 Test Pattern.....................................................................................................................32 12. Deal with Lens.........................................................................................................................33 12.1 Light fall off......................................................................................................................33 12.2 Dark corner.......................................................................................................................33 2 Company Confidential Confidential For Actions Only
OV5640 Camera Module Software Application Notes 12.3 Resolution.........................................................................................................................33 12.4 Optical contrast.................................................................................................................33 12.5 Lens Cover........................................................................................................................33 13. Reference Settings...................................................................................................................34 13.1 YCbCr Reference Setting..................................................................................................34 13.1.1 VGA Preview............................................................................................................34 13.1.2 Other size preview....................................................................................................42 13.1.3 VGA 90fps video.......................................................................................................44 13.1.4 QSXGA Capture......................................................................................................52 13.1.4.1 YUV mode capture............................................................................................52 13.1.4.2 Jpg mode capture...............................................................................................53 13.1.5 Other Capture size DCW from QSXGA ................................................................54 13.1.6 Return to yuv mode..................................................................................................57 13.1.6.1 From 5M YUV to vga YUV..............................................................................57 13.1.6.2 From 5M Jpg to vga yuv....................................................................................59 13.1.7 YUV and JPEG mode change setting.......................................................................60 13.1.7.1 YUV to JPEG setting.........................................................................................60 13.1.7.2 JPEG to YUV setting.........................................................................................60 13.1.8 Zoom function...........................................................................................................60 13.2 Sensor Raw setting............................................................................................................64 13. 3 High Resolution Video....................................................................................................66 13.3.1 1080 P........................................................................................................................66 13.3.2 720 P..........................................................................................................................71 13. 4 Mipi setting......................................................................................................................76 13.4.1 VGA yuv_mipi_2lane_15fps ...................................................................................76 13.4.2 VGA yuv_mipi_2lane_15fps to 5M yuv_mipi_2lane_15fps....................................81 13.4.3 5M jpg_mipi_2lane_15fps.......................................................................................82 14. Capture Sequence....................................................................................................................86 14.1 Shutter...............................................................................................................................86 14. 2 Dummy Lines...................................................................................................................86 14. 3 Dummy Pixels..................................................................................................................86 14.4 Gain...................................................................................................................................86 14.5 Banding Filter...................................................................................................................86 14.5.1 Preview......................................................................................................................86 14.5.2 Capture......................................................................................................................86 14.6 Auto frame rate.................................................................................................................87 14.7 Capture Sequence..............................................................................................................87 14.7.1 Preview......................................................................................................................87 14.7.2 Stop AEC/AGC........................................................................................................87 14.7.3 Single Focus for AF Module.....................................................................................87 14.7.4 Read preview register Value.....................................................................................87 14.7.5 Change resolution to QSXGA...................................................................................87 14.7.6 Read capture register Value......................................................................................87 14.7.7 Calculate Capture Exposure from preview..............................................................87 14.7.8 Calculate the banding filter value..............................................................................87 14.7.9 Redistribute Exposure/Gain with target brightness unchanged................................88 14.7.10 write back the gain/exposure value.........................................................................88 14.7.11 Capture....................................................................................................................88 3 Company Confidential Confidential For Actions Only
OV5640 Camera Module Software Application Notes 14.7.12 Send finish command for AF module.....................................................................88 14.7.13 Back to preview.......................................................................................................88 14.8 Capture reference code......................................................................................................88 15. Strobe Flash Control................................................................................................................91 16. Auto Focus Application Solution ........................................................................................93 16.1 Embedded Resources........................................................................................................93 16.2 Embedded Auto Focus Solution ......................................................................................93 16.3 General Auto Focus Control Flow...................................................................................93 16.4 How to use Embedded Auto Focus Solution..................................................................93 17. Frame exposure mode ............................................................................................................94 17.1 Introduction.......................................................................................................................94 17.2 FREX function mode........................................................................................................94 17.2.1 Pad mode...................................................................................................................94 17.2.2 I2c mode...................................................................................................................95 17.3 System settings..................................................................................................................96 17.3.1 Pad mode...................................................................................................................96 17.3.2 I2c mode ..................................................................................................................96 17.4 Option settings..................................................................................................................96 17.4.1 Exposure Time (unit: Tline).....................................................................................96 17.4.2 Frame Delay (unit: Tframe), 3b06[7:4] default: 0...................................................96 17.4.3 Flash Strobe Width (unit: Tline), 3b06[3:0] default: 4...........................................96 17.4.4 Frex Shutter Signal Reverse, 3b07[2] default: 0.....................................................96 17.4.5 Frex Mode, 3b07[1:0] default: 0.............................................................................97 17.4.6 Frex Precharge Time(ftx, frst width), 3817[2:0] default: 4.....................................97 17.4.7 VSYNC ends time,...................................................................................................97 18. Some photos captured by 5640 ...............................................................................................97 4 Company Confidential Confidential For Actions Only
NOTE: OV5640 use 16bits Register address and 8bits Register data. 1. How to Select Output format? OV5640 support 5 output format: YcbCr422/420, RGB565/555/444, Bayer raw RGB, CCIR656, YUV422 JPEG. How to choose the right output format for camera phone design or other applications? Let's look at the back-end chip first. The general diagram of back-end chip is as below: Camera Interface YCbCr RGB Bayer raw RGB Processed raw RGB Compression Mode X LCD Driver RGB Memory Interface JPEG The data format at LCD driver are always RGB. For example, RGB444, RGB565, RGB555, RGB888 etc. The data format and memory interface are always JPEG. The JPEG data is compressed from YCbCr data. So Both RGB and YCbCr data are needed inside the back-end chip. The “X” block is different for different back-end chips. 1.1 Back-end with full ISP This kind of back-end has full ISP. It takes raw RGB input, doing interpolation to generate RGB24 and doing translation to generate YCbCr. This kind of back-end could take Bayer raw RGB or processed raw RGB. The advantage of CIP RAW over sensor Bayer raw RGB is the output data are processed. Sensor functions such as defect pixel correction, lens correction, gamma, color matrix, de-noise, sharpness, BLC ,defect pixel correction etc. could be applied. Since the life time of back-end chip is longer than image sensor, sometimes back-end chips could not fix defects of new sensors if taken Bayer raw RGB. If back-end take Bayer raw RGB format from sensor, all the image process operations such as defect pixel correction, lens correction, gamma, color matrix, de-noise, sharpness, BCL etc should be done by back-end. If back-end take processed raw RGB format from sensor, the image process Confidential For Actions Only
operations such as defect pixel correction, lens correction, gamma, color matrix, de-noise, sharpness, BCL etc could be done either inside sensor or by back-end chips. In other words, user could select the image process operation be done by which side. 1.2 Back-end with YCbCr ISP This kind of back-end has ISP, but could take only YCbCr format. The ISP could convert YCbCr to RGB format for LCD display and compress YCbCr to JPEG for storage. 1.3 Back-end without ISP This kind of back-end doesn't have ISP built-in. It can not convert from one format to another by hardware. Actually the format conversion is done by software. There are 3 possible solution for this kind of back-end chips. a. Sensor output YCbCr. back-end chip convert YCbCr to RGB for display by software. b. Sensor output RGB565 . Back-end chip convert RGB565 to YCbCr for JPEG compression. c. Sensor output RGB565 for preview, output YCbCr for capture (JPEG compression). Solution a. provide the best picture quality. Since the input data is 24-bit RGB equivalent. It could converted to RGB888 for LCD display. Solution b. provide the worst picture quality. Since the input data is only 16-bit RGB565, even it is converted to YCbCr, the color depth is still 16-bit. The solution c. provide similar picture quality as solution a. But since preview is RGB565, capture is YCbCr, preview picture may looks a little different than captured picture. 1.4 Equations to Convert from One Format to Another YCbCr to RGB24 Y = 0.299R + 0.587G + 0.114B Cb = 0.568(B-Y) + 128 = –0.172R – 0.339G + 0.511B + 128 Cr = 0.713(R-Y) + 128 = 0.511R – 0.428G – 0.083B + 128 Y = ((77 * R + 150 * G + 29 * B) >> 8); Cb = ((-43 * R - 85 * G + 128 * B) >> 8) + 128; Cr = ((128 * R - 107 * G - 21 * B) >> 8) + 128; RGB24 to YCbCr R = Y + 1.371(Cr – 128) G = Y – 0.698(Cr – 128) – 0.336(Cb – 128) Confidential For Actions Only
B = Y + 1.732(Cb – 128) R = Y + (351*(Cr – 128)) >> 8 G = Y – (179*(Cr – 128) + 86*(Cb – 128))>>8 B = Y + (443*(Cb – 128)) >> 8 2. How to Select Output Resolution? 2.1 back-end with ISP If back-end chip has built-in ISP (Full ISP or YCbCr ISP), the ISP could do image scale. So OV5640 outputs only VGA format or SXGA format for preview and capture, ISP scaled VGA or SXGA image to other resolution that mobile device needed for LCD display and capture when image size below VGA or SXGA image . But for the image size bigger than SXGA format, OV5640 would output the size needed. 2.2 back-end without ISP If back-end chip doesn't have image scale capability, then the LCD scaler of OV5640 must be used to scale output resolution exactly the LCD size. For example, if the LCD size is 176x220, then the LCD scaler will scale the output size to 176x220. In this case, OV5640 output small resolution for preview, and several other resolution for capture. The resolution for capture may include: QQVGA, QVGA, QCIF, CIF, VGA, SVGA,SXGA,UXGA, QXGA, QSXGA . For best quality, all capture size are all downscaled from QSXGA . 3. How to Adjust frame rate The recommended frame rates is 15fps preview for 60/50Hz light environment. The recommended frame rate for capture is 7.5fps for 60/50hz light environment. The frame rate for night mode is lower, we'll discuss night mode later. 4. How to set Night Mode Preview There are 2 types of settings for night mode. One type is set to fixed low frame rate, for example 3.75fps. The other type is set to auto frame rate, for example from 15fps to 3.75fps. When environment is bright, the frame rate is increased to 15fps. When environment is dark, the frame rate is decreased to 3.75fps. 4.1 Night Mode VGA Preview with Fixed Frame Rate 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,6Mhz PCLK i2c_salve_Address = 0x78; Confidential For Actions Only
write_I2c(0x3034 ,0x1a); write_I2c(0x3035 ,0x61); write_I2c(0x3036 ,0x46); write_I2c(0x3037 ,0x13); write_I2c(0x3038 ,0x00); write_I2c(0x3039 ,0x00); write_I2c(0x3a00 ,0x78); write_I2c(0x3a08 ,0x01); write_I2c(0x3a09 ,0x27); write_I2c(0x3a0a ,0x00); write_I2c(0x3a0b ,0xf6); write_I2c(0x3a0d ,0x04); write_I2c(0x3a0e ,0x04); write_I2c(0x3a02 ,0x03); write_I2c(0x3a03 ,0xd8); write_I2c(0x3a14 ,0x03); write_I2c(0x3a15 ,0xd8); 4.2 Night Mode VGA preview with Auto Frame Rate 15fps ~ 3.75fps night mode for 60/50Hz light environment, 24Mhz clock input,24Mhz PCLK i2c_salve_Address = 0x78; write_I2c(0x3034 ,0x1a); write_I2c(0x3035 ,0x21); write_I2c(0x3036 ,0x46); write_I2c(0x3037 ,0x13); write_I2c(0x3038 ,0x00); write_I2c(0x3039 ,0x00); write_I2c(0x3a00 ,0x7c); write_I2c(0x3a08 ,0x01); write_I2c(0x3a09 ,0x27); write_I2c(0x3a0a ,0x00); write_I2c(0x3a0b ,0xf6); write_I2c(0x3a0d ,0x04); write_I2c(0x3a0e ,0x04); write_I2c(0x3a02 ,0x0b); write_I2c(0x3a03 ,0x88); write_I2c(0x3a14 ,0x0b); write_I2c(0x3a15 ,0x88); Confidential For Actions Only
分享到:
收藏