OV7670 host computer implementation

 OV7670 is a 1/6 inch CMOS VGA image sensor produced by OV (OmniVision). The sensor is small in size and low in operating voltage, providing all the functions of a single-chip VGA camera and image processor. Through SCCB bus control, it can output 8-bit image data of various resolutions in the form of whole frame, sub-sampling, and windowing. The product's VGA image is up to 30 frames per second. Users have complete control over image quality, data format and transmission method. All image processing functions including gamma curve, white balance, chromaticity, etc. can be programmed through the SCCB interface.


 Since the camera module is still being debugged by the author, the specific part of the lower computer will be recorded in the future.

 The source code of the author's host computer program is placed on github, which contains the project files. If you just need the program, you can email me. It should be noted that the upper computer communicates with the lower computer through the serial port. Therefore, different upper computers are required for different lower computers. The author's host computer still has imperfections. If you need to refer to it, remember to modify it according to your own subordinate computer, or modify your subordinate computer program to test according to my next method. Here is the color bar of OV7670 Test for example.

1. Lower computer (MCU, I use STM32ZET6 (core board) )

The following is the program segment for the MCU to simulate the generation of color bars

//MCU generates color bar test
void OV7670_CreatColor()
{
	uint16_t i, j, k = 0;
	uint16_t color = 0;
	//column buffer
	uint16_t buff[320];
  
	while(1)
	{
		//Data start (top to bottom, left to right)
		printf("data:\n");
		
		for(i=0;i<240;i++)
		{
			printf("L");//The column is valid
			for(j=0;j < 320;j++)//一列
			{
				//Generate color bars 9E F7, 8D EF, 9E 3F, 83 1F, FF F0, 43 D9, 95 28, 82 10
				if(i < 30)
				{
					color = 0x9EF7;
				}else if(i < 60)
				{
					color = 0x8DEF;
				}else if(i < 90)
				{
					color = 0x9E3F;
				}else if(i < 120)
				{
					color = 0x831F;
				}else if(i < 150)
				{
					color = 0xFFF0;
				}else if(i < 180)
				{
					color = 0x43D9;
				}else if(i < 210)
				{
					color = 0x9528;
				}else
				{
					color = 0x8210;
				}
				buff[j] = color;
			}
			// prepare a column of data
			for(k=0;k<320;k++)
			{
				printf("%04X", buff[k]);//Print color bar
			}
			printf("\n");
		}
	}
}

  2. Host computer (developed with C# and VS2015)

The upper computer mainly receives the data sent by the lower computer, and displays the data in the PictureBox, and needs to use the serial port class to monitor whether the data arrives in the middle.

DataReceived

/// <summary>
        /// Serial port data arrival event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            string data;
            Color[] colors;

            //Check if the serial port is open
            if (isOpen)
            {
                // Areas of code where unexpected errors may occur
                try
                {
                    //Check whether to start sending data
                    if (sp.ReadLine().Equals("data:"))
                    {
                        start = true;
                    }
                    //Start reading data
                    if (start)
                    {
                        // draw the image (drawing column by column)
                        for (int Xcount = 0; Xcount < 240; Xcount++)
                        {
                            if (isOpen)
                            {
                                // read a column
                                data = sp.ReadLine();
                                if (data.StartsWith("L"))//The column is valid
                                {
                                    colors = RGBToBitmap(data.Substring(1));
                                }
                                else
                                {
                                    return;
                                }
                            }
                            else
                            {
                                return;
                            }

                            for (int Ycount = 0; Ycount < 320; Ycount++)
                            {
                                OvImage.SetPixel(Xcount, Ycount, colors[Ycount]);
                            }
                            this.pbImage.Image = OvImage;
                        }
                        start = false;//End of receiving data
                    }
                }
                catch (Exception ex)
                {
                    return;
                }
            }
        }

For other parts of the code, please refer to the code on github. If there is any error, please criticize and correct it, and attach the simulated color bar test effect. 


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326767997&siteId=291194637