求助各位大佬~~这个迭代法图像二值化的程序设定的长宽是180*320,但是我屏幕是240*320,所以有一部分屏幕是看不到东西的,但是我把宽调成240以后整个屏幕都不亮了!是数据类型定义出问题了么?求助各位大佬帮帮小弟!
#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<PIXEL_H; i++)
{
for(j = 0; j<PIXEL_W; 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<PIXEL_H; i++ )
{
for( j=0; j<PIXEL_W; 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<gray_itera_threshold[cnt] )
{
Pmax = gray_itera_threshold[cnt];
}
}
printf("the Pmax is %d\r \n",Pmax);
printf("the Pmin is %d \r\n",Pmin);
//³õʼãÐÖµ
threshold_h[0] = ( Pmax + Pmin ) / 2;
//Ñ°ÕÒ×î¼ÑãÐÖµ
for( k=0; k<256; k++ )
{
//·Ö¸îÇ°¾°ºÍ±³¾°
for( cnt=0; cnt<threshold_h[k]; 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 %d\r\n",newthreshold);
// //ÔÚÒº¾§ÆÁÉÏÃæдÈëͼÏñ·Ö¸îºóµÄͼÏñ
// LCD_SetCursor(0,0);
// LCD_WriteIndex(0x22); //×¼±¸Ð´ÈëÊý¾Ý
//¸ù¾Ý×î¼ÑãÐÖµ½«Í¼Ïñ¶þÖµ»¯
ILI9341_GramScan ( 3 );
// ILI9341_Clear ( 0, 0, 240, 320, macWHITE);
for( i=0; i<PIXEL_H; i++ )
{
for( j=0; j<PIXEL_W; j++ )
{
mux = pixel[i][j]; //»ñÈ¡»Ò¶ÈͼµÄÊý¾Ý
//ͼÏñ¶þÖµ»¯
if( mux > newthreshold )
{
mux = 255;
}
else
{
mux = 0;
}
Camera_Data = GRAY_TO_RGB(mux);
ILI9341_Write_Data(Camera_Data);
}
}
}
|