迭代法
- #define PIXEL_W 320
- #define PIXEL_H 180
- #define PIXEL_BREAK 100
- //»Ò¶ÈÖ±·½Í¼ÊýÖµ£¬ÓÃÀ´Åжϰ´Í¼ÏñÖÊÁ¿
- u32 gray_test_value[26]; //ÏñËصãÊýÊý¾Ý
- u8 gray_test_send[28]; //·¢Ë͸øÉÏλ»úµÄÊý¾Ý
- //ãÐÖµ·Ö¸î»Ò¶Èͼ
- u8 gray_itera_threshold[256];
- u16 threshold_h[256];
- #define GRAY_BREAK_RANGE 1 //ãÐÖµÔÊÐí²ÎÊý
- static u8 pixel[PIXEL_H][PIXEL_W];
- /* 320
- * -------------------
- *| |
- *| |
- *| | 240
- *| |
- *| |
- * -------------------
- */
- void ImagDisp_T(void)
- {
- uint16_t i=0, j=0;
- uint16_t Camera_Data;
- uint16_t R,G,B;uint32_t mux;
- //mux_later;
- // float data = 0.0;
- // LCD_SetCursor(0,0); È·¶¨Òº¾§É¨Ãè·½Ïò
- // LCD_WriteIndex(0x22);ÇåÆÁ×¼±¸Ð´ÈëÊý¾Ý
- ILI9341_GramScan ( 3 );
-
-
- for(i = 0; i
- {
- for(j = 0; j
- {
- //READ_FIFO_PIXEL(Camera_Data); /* ´ÓFIFO¶Á³öÒ»¸örgb565ÏñËص½Camera_Data±äÁ¿ */
- //ת»»³É»Ò¶Èͼ
- READ_FIFO_PIXEL(Camera_Data); /* ´ÓFIFO¶Á³öÒ»¸örgb565ÏñËص½Camera_Data±äÁ¿ */
- R = (uint16_t)GETR_FROM_RGB16(Camera_Data);
- G = (uint16_t)GETG_FROM_RGB16(Camera_Data);
- B = (uint16_t)GETB_FROM_RGB16(Camera_Data);
- mux = (R*30+G*59+B*11)/100;
- //// mux = G;
- //
- pixel[i][j] = mux;
-
- //pixel[i][j] = GETGRAY_FROM_RGB16(R,G,B);
-
- // mux = pixel[i][j];
- // Camera_Data = GRAY_TO_RGB(mux);
- // ILI9341_Write_Data(Camera_Data);
-
- }
- }
- }
- /****************************************************
- * º¯ÊýÃû£ºItera_Threshold
- * ¹¦ ÄÜ£ºµü´úãÐÖµ·¨£¬Äܹ»ÕÒµ½»Ò¶ÈͼµÄ×î¼Ñ¶þÖµ»¯µã
- ****************************************************/
- void Itera_Threshold(void)
- {
- u16 i=0,j=0,k=0,cnt=0,mux=0,Camera_Data=0;
- u8 newthreshold=0;
- u16 Pmax=0,Pmin=0;
- u32 sum_h1=0,sum_h2=0;
-
-
- //Êý¾ÝÇå¿Õ
- for( i=0; i<256; i++ )
- {
- gray_test_value[i] = 0;
- }
-
- for( i=0; i
- {
- for( j=0; j
- {
- mux = pixel[i][j];//»ñÈ¡»Ò¶ÈͼµÄÊý¾Ý
- //ÏñËصãÊý×ÔÔö
- gray_itera_threshold[mux]++;
- }
- }
-
- Pmin = gray_itera_threshold[0];
- Pmax = gray_itera_threshold[0];
- for( cnt=0; cnt<256; cnt++ )
- {
- if( Pmin>gray_itera_threshold[cnt] )
- {
- Pmin = gray_itera_threshold[cnt];
- }
- if( Pmax
- {
- Pmax = gray_itera_threshold[cnt];
- }
- }
-
- printf("the Pmax is %dr n",Pmax);
- printf("the Pmin is %d rn",Pmin);
-
- //³õʼãÐÖµ
- threshold_h[0] = ( Pmax + Pmin ) / 2;
-
- //Ñ°ÕÒ×î¼ÑãÐÖµ
- for( k=0; k<256; k++ )
- {
- //·Ö¸îÇ°¾°ºÍ±³¾°
- for( cnt=0; cnt
- {
- sum_h1 += gray_itera_threshold[cnt];
- }
- for( cnt=threshold_h[k]; cnt<256; cnt++ )
- {
- sum_h2 += gray_itera_threshold[cnt];
- }
- sum_h1 /= threshold_h[k];
- sum_h2 /= (256-threshold_h[k]);
-
- //¼ÆËã³öеÄãÐÖµ
- threshold_h[k+1] = ( sum_h1 + sum_h2 ) / 2;
-
- if( fabs(threshold_h[k]-threshold_h[k+1]) <= GRAY_BREAK_RANGE )
- {
- newthreshold = threshold_h[k+1];
- break;
- }
-
- sum_h1 = 0;
- sum_h2 = 0;
- }
- printf("the newthreshold is %drn",newthreshold);
-
- // //ÔÚÒº¾§ÆÁÉÏÃæдÈëͼÏñ·Ö¸îºóµÄͼÏñ
- // LCD_SetCursor(0,0);
- // LCD_WriteIndex(0x22); //×¼±¸Ð´ÈëÊý¾Ý
- //¸ù¾Ý×î¼ÑãÐÖµ½«Í¼Ïñ¶þÖµ»¯
- ILI9341_GramScan ( 3 );
- // ILI9341_Clear ( 0, 0, 240, 320, macWHITE);
- for( i=0; i
- {
- for( j=0; j
- {
- mux = pixel[i][j]; //»ñÈ¡»Ò¶ÈͼµÄÊý¾Ý
- //ͼÏñ¶þÖµ»¯
- if( mux > newthreshold )
- {
- mux = 255;
- }
- else
- {
- mux = 0;
- }
-
- Camera_Data = GRAY_TO_RGB(mux);
- ILI9341_Write_Data(Camera_Data);
-
- }
- }
- }
这个程序代码在板子上只能显示一部分,因为设定的长宽只有180*320
但是把宽改成240之后整个屏幕不显示了,我试了试这个宽度只能到189就不行了,是不是数据类型定义的问题啊~各位大佬帮帮小弟吧!!万分感谢
更多回帖