標(biāo)題: 基于stm32的攝像頭ov7670顏色識(shí)別源碼 [打印本頁(yè)]

作者: xuyu3344    時(shí)間: 2018-7-13 20:32
標(biāo)題: 基于stm32的攝像頭ov7670顏色識(shí)別源碼
//讀取某點(diǎn)的顏色
static void ReadColor( uint16_t usX, uint16_t usY, COLOR_RGB* color_rgb )
{
        unsigned short rgb;
        
        rgb = LCD_ReadPoint( usX, usY );                                        //獲取顏色數(shù)據(jù)
        
        //轉(zhuǎn)換成值域?yàn)閇0,255]的三原色值
        color_rgb->Red                 = (unsigned char)( ( rgb & 0xF800 ) >> 8 );
        color_rgb->Green  = (unsigned char)( ( rgb & 0x07E0 ) >> 3 );
        color_rgb->Blue         = (unsigned char)( ( rgb & 0x001F ) << 3 );        
}
/*************************************/
//RGB轉(zhuǎn)換為HLS
//H:色度
//L:亮度
//S:飽和度
static void RGB2HSL( const COLOR_RGB* color_rgb, COLOR_HLS* color_hls )
{
        int r, g, b;
        int h, l, s;
        int max, min, dif;
        
        r = color_rgb->Red;
        g = color_rgb->Green;
        b = color_rgb->Blue;
        
        max = maxOf3Values( r, g, b );
        min = minOf3Values( r, g, b );
        dif = max - min;
        
        //計(jì)算l,亮度
        l = ( max + min ) * 240 / 255 / 2;
        
        //計(jì)算h,色度
        if( max == min )//無(wú)定義
        {
                s = 0;
                h = 0;
        }
        else
{
                //計(jì)算色度
                if( max == r )
                {
                        if( min == b )//h介于0到40
                        {
                                h = 40 * ( g - b ) / dif;
                        }
                        else if( min == g )//h介于200到240
                        {
                                h = 40 * ( g - b ) / dif + 240;
                        }
                        
                }
                else if( max == g )
                {
                        h = 40 * ( b - r ) / dif + 80;
                }
                else if( max == b )
                {
                        h = 40 * ( r - g ) / dif + 160;
                }
               
                //計(jì)算飽和度
                if( l == 0 )
                {
                        s = 0;
                }
                else if( l <= 120 )
                {
                        s = dif * 240 / ( max + min );
                }
                else

{
                        s = dif * 240 / ( 480 - ( max + min ) );
                }                 
        }   
    color_hls->Hue = h;                                                        //色度
        color_hls->Lightness = l;                                //亮度
        color_hls->Saturation = s;                        //飽和度
}


攝像頭(顏色捕捉).rar

395.78 KB, 下載次數(shù): 236, 下載積分: 黑幣 -5


作者: Marauder    時(shí)間: 2018-9-9 22:59
東西很好,值得學(xué)習(xí)
作者: ebingyu    時(shí)間: 2018-10-11 17:57
學(xué)習(xí)了
作者: 979960947    時(shí)間: 2018-10-13 11:35
附件里哪有文件???
作者: plj213    時(shí)間: 2019-5-14 10:38

感謝樓主分享。。。
作者: 肖玉千    時(shí)間: 2019-5-18 22:07
敢問(wèn)使用stm32f1還是f4
作者: 柏禺    時(shí)間: 2019-7-11 11:23
怎么更改識(shí)別的顏色,現(xiàn)在只能識(shí)別綠色
作者: queen1210    時(shí)間: 2019-7-28 13:30
非常好用
作者: 三個(gè)字符    時(shí)間: 2019-8-1 21:01
樓主有沒(méi)有一些原理的簡(jiǎn)單介紹
作者: ABCg    時(shí)間: 2019-8-3 19:28
柏禺 發(fā)表于 2019-7-11 11:23
怎么更改識(shí)別的顏色,現(xiàn)在只能識(shí)別綠色

我的能識(shí)別藍(lán)色,哥,換下代碼嘛。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1