Modify camera driver (resolution)

Source: Internet
Author: User

Article transferred from: http://blog.csdn.net/zpf03/article/details/5903484

 

During this time, I developed an image recognition project based on wince6.0 + 6410, using the Development Board of youjian hengtian. This development board has an ov9650 camera connection port, but one of the biggest problems is that the image obtained by the camera is too small and only 320*240 images can be seen. I need 1280*1024 images, therefore, it can only be modified. If you want the driver to provide an interface, you can modify the pixels in the application. However, you can analyze the driver source code and find that the camera pixels are set to dead in the driver, so you can only modify the driver. A lot of detours were taken in the process of modifying the driver, but today we finally succeeded. We can successfully display 640*480.
And 1280*1024 images.

The files to be modified in the driver include setting. H, ov9650_modual.cpp, sensorformat. H, and initi6410_camera.h.camera_pdd.cpp.

First, modify the register settings of CMOS. The driver initializes the ov9650 register in the ov9650_modual.cpp file. The Code is as follows:

For (I = 0; I <ov9650_regs; I ++)

{

Hw_writeregisters (& ov9650_reg [I] [0], 2 );

Retailmsg (ov9650_debug, (text ("hw_writeregisters: Reg [0x % x] = 0x % x, I = % d. /R/N "), ov9650_reg [I] [0], ov9650_reg [I] [1], I ));

}

Modulesetimagesize (VGA );

After checking, the camera driver provided by the general development board sets the ov9650 pixel to the VGA (640*480) format, so a larger pixel such as 1280*1024 must be displayed, you need to modify the register initialization value, which can be obtained from ov. The ov9650 registers are complex and the datasheet writes poorly. Therefore, we recommend that you set the Fae in China from ov. In the setting. h file, the two-dimensional array ov9650_reg [] [2] is the initialization list of ov9650, which is the register address and register value respectively. The following items are modified:

{0x6a, 0x41}, // 3E

{0x12, 0x00}, // 40

{0x0c, 0x00}, // 04

{0x0d, 0x00}, // 80

{0x18, 0xbe}, // C6

{0x17, 0x1e}, // 26

{0x32, 0xbf}, // ad

{0x03,0x12}, // 00

{0x1a, 0x81}, // 3D

{0x2a, 0x10}, // 00

{0x2b, 0x34}, // 00

The comment value is 640*480.

In fact, after careful study of the code, we can find that pixels are not set elsewhere in the driver. We only set the pixels after register initialization using the modulesetimagesize () function, so after the pixels are set during initialization, modulesetimagesize (VGA) can be removed from this line of code. If you want to retain the function to display an image of 1280*1024 pixels, you need to change it to modulesetimagesize (sxga). However, the sxga option is not defined in the modulesetimagesize () function, therefore, some code needs to be added. The modified definition is as follows:

Int modulesetimagesize (INT imagesize)
{
Byte sizevalue [2];

Sizevalue [0] = 0x12;
Switch (imagesize)
{
Case sxga: // Add item
Sizevalue [1] = 0x00;
Break;

Case VGA:
Sizevalue [1] = 0x40;
Break;
Case CIF:
Sizevalue [1] = 0x20;
Break;
Case qvga:
Sizevalue [1] = 0x10;
Break;
Case qcif:
Sizevalue [1] = 0x08;
Break;
Case raw_rgb:
Sizevalue [1] = 0x04;
Break;
}

Hw_writeregisters (sizevalue, 2 );
Return true;
}


You also need to modify the preview cache size, which is in the file "s36410_camera.h:

# Define preview_buffer_size 10485760 // 1280*1024*2*4


// 2457600 // 640*480*2*4

// 614400 // (320*240*2) * max_hw_frames

Among them, 10485760 is the cache size for previewing 1280*1024 pixel images, and 2457600 is the cache size for previewing 640*480 images. You can set the cache Size Based on your needs.

Next, modify the sensorformat. h file:

/*
Original part

Make_stream_mode_rgb565 (dcam_streammode_0, 160,120, 16, 30 );

Make_stream_mode_rgb565 (dcam_streammode_1, 176,144, 16, 30 );

Make_stream_mode_rgb565 (dcam_streammode_2, 320,240, 16, 15 );

Make_stream_mode_rgb565 (dcam_streammode_3, 320,240, 16, 30 );

Make_stream_mode_yv12 (dcam_streammode_5, 176,-144, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_6, 320,-240, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_7, 176,-144, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_8, 640,-480, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_9, 240,-180, 12, 15 );

*/

// The modified part:

Make_stream_mode_rgb565 (dcam_streammode_0, 160,120, 16, 30 );

Make_stream_mode_rgb565 (dcam_streammode_1, 176,144, 16, 30 );

// Make_stream_mode_rgb565 (dcam_streammode_2, 320,240, 16, 15 );

Make_stream_mode_rgb565 (dcam_streammode_2, 320,240, 16, 30 );

Make _ stream_mode_rgb565 (dcam_streammode_3, 640,480, 16, 15 );

Make_stream_mode_rgb565 (dcam_streammode_4, 1280,102 4, 16, 15); // added

Make_stream_mode_yv12 (dcam_streammode_5, 176,-144, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_6, 320,-240, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_7, 176,-144, 12, 15 );

Make_stream_mode_yv12 (dcam_streammode_8, 640,-480, 12, 15); // added

Make_stream_mode_yv12 (dcam_streammode_9, 1280,-1024, 12, 15); // added

Finally, modify the camera_pdd.cpp file. The comments are the original driver code. Note that this part must correspond to the modified part.

/* M_pmodevideoformat [capture]. pcsdatarangevideo [0] = & dcam_streammode_5;

M_pmodevideoformat [capture]. pcsdatarangevideo [1] = & dcam_streammode_6;

M_pmodevideoformat [capture]. pcsdatarangevideo [2] = & dcam_streammode_7;

M_pmodevideoformat [capture]. pcsdatarangevideo [3] = & dcam_streammode_8;

M_pmodevideoformat [capture]. pcsdatarangevideo [4] = & dcam_streammode_9;

*/

M_pmodevideoformat [capture]. pcsdatarangevideo [0] = & dcam_streammode_9;

M_pmodevideoformat [capture]. pcsdatarangevideo [1] = & dcam_streammode_8;

M_pmodevideoformat [capture]. pcsdatarangevideo [2] = & dcam_streammode_7;

M_pmodevideoformat [capture]. pcsdatarangevideo [3] = & dcam_streammode_6;

M_pmodevideoformat [capture]. pcsdatarangevideo [4] = & dcam_streammode_5;

/* M_pmodevideoformat [Preview]. pcsdatarangevideo [0] = & dcam_streammode_0;

M_pmodevideoformat [Preview]. pcsdatarangevideo [1] = & dcam_streammode_1;

M_pmodevideoformat [Preview]. pcsdatarangevideo [2] = & dcam_streammode_2;

M_pmodevideoformat [Preview]. pcsdatarangevideo [3] = & dcam_streammode_3;

*/

M_pmodevideoformat [Preview]. pcsdatarangevideo [0] = & dcam_streammode_4; // 1280*1024

M_pmodevideoformat [Preview]. pcsdatarangevideo [1] = & dcam_streammode_3;

M_pmodevideoformat [Preview]. pcsdatarangevideo [2] = & dcam_streammode_2;

M_pmodevideoformat [Preview]. pcsdatarangevideo [3] = & dcam_streammode_1;

After the above modification, the big work is finished.

The above is my own summary of the modification process. If there are errors and omissions, I hope you can give me more advice.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.