标题: 基于stm32的摄像头ov7670颜色识别源码 [打印本页]

作者: xuyu3344    时间: 2018-7-13 20:32
标题: 基于stm32的摄像头ov7670颜色识别源码
//读取某点的颜色
static void ReadColor( uint16_t usX, uint16_t usY, COLOR_RGB* color_rgb )
{
        unsigned short rgb;
        
        rgb = LCD_ReadPoint( usX, usY );                                        //获取颜色数据
        
        //转换成值域为[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转换为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;
        
        //计算l,亮度
        l = ( max + min ) * 240 / 255 / 2;
        
        //计算h,色度
        if( max == min )//无定义
        {
                s = 0;
                h = 0;
        }
        else
{
                //计算色度
                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;
                }
               
                //计算饱和度
                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, 下载次数: 236, 下载积分: 黑币 -5


作者: Marauder    时间: 2018-9-9 22:59
东西很好,值得学习
作者: ebingyu    时间: 2018-10-11 17:57
学习了
作者: 979960947    时间: 2018-10-13 11:35
附件里哪有文件???
作者: plj213    时间: 2019-5-14 10:38

感谢楼主分享。。。
作者: 肖玉千    时间: 2019-5-18 22:07
敢问使用stm32f1还是f4
作者: 柏禺    时间: 2019-7-11 11:23
怎么更改识别的颜色,现在只能识别绿色
作者: queen1210    时间: 2019-7-28 13:30
非常好用
作者: 三个字符    时间: 2019-8-1 21:01
楼主有没有一些原理的简单介绍
作者: ABCg    时间: 2019-8-3 19:28
柏禺 发表于 2019-7-11 11:23
怎么更改识别的颜色,现在只能识别绿色

我的能识别蓝色,哥,换下代码嘛。




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1