集创赛分析(图像处理部分)

四月份进度

1.分析多少个资源单元

图像采集和存储数据:先驱动摄像头进行数据采集(ov5640),再驱动存储器(SDRAM),将数据存到存储器

数据处理:简单的滤波(中值/均值),根据采集的数据进行颜色识别,再做一个Sobel识别边缘,进行简单的形状匹配

摄像头采集数据,摄像头的数据是把16位的RGB拆分为高八位和低八位发送的,通过移位+位拼接的方式把两个8bit的数据合并成16bit数据输出,同时为了SDRAM模块更好的识别帧头和帧尾,在图像的第一个像素点以及最后一个像素点的时候分别拉高sop和eop信号,其他像素点这拉低。

这里的16位数据是RGB565,RGB565的高5位是红色,中间6位是绿色,最低5位是蓝色。

摄像头的驱动时钟是24M,SDRAM接口的驱动时钟是100M

颜色识别,HSV颜色阈值空间,或者进行简单的颜色识别,判断R、G、B的那个颜色值比较大,那个值比较大,就是那个颜色,这是实现一个简单的功能,比较不准确,

module RGB_to_HSV (
    input        [7:0]    iRed,
    input        [7:0]    iGreen,
    input        [7:0]    iBlue,
    input                iCLK,
    input                iRST_N,
    output reg          oRed,
    output reg          oYellow,
    output reg          oBlue
);
    always @(posedge iCLK or negedge iRST_N)
    begin
        if(!iRST_N)
        begin
            oRed <= 0;
            oYellow <= 0;
            oBlue <= 0;
        end
        else
        begin
            // 这里只是简单的判断,实际上你需要进行RGB到HSV的转换,并把HSV空间的值用来判断颜色
            if(iRed > iGreen && iRed > iBlue) 
                oRed <= 1;
            else
                oRed <= 0;

            if(iGreen > iRed && iGreen > iBlue) 
                oYellow <= 1;
            else
                oYellow <= 0;

            if(iBlue > iGreen && iBlue > iRed) 
                oBlue <= 1;
            else
                oBlue <= 0;
        end
    end

endmodule

最近发现如果用YCbCr也可以判断,

module color_detector(
    input [7:0] Y_in, Cb_in, Cr_in,
    output reg is_red, is_blue, is_yellow, is_gray);

always @* begin
    // 判断是否为蓝色
    if ((Cb_in >= 240) && (Cr_in <= 125) ) 
        is_blue = 1;
    else 
        is_blue = 0;
    
    // 判断是否为红色
    if ((Cb_in <= 100) && (Cr_in >= 220)) 
        is_red = 1;
    else 
        is_red = 0;
    
    // 判断是否为黄色
    if ((Cb_in <= 80) && (Cr_in <= 170 && Cr_in >= 140)) 
        is_yellow = 1;
    else 
        is_yellow = 0;
    
    // 判断是否为灰色
    if ((Cb_in >= 125 && Cb_in <= 130) && (Cr_in >= 125 && Cr_in <= 130)) 
        is_gray = 1;
    else 
        is_gray = 0;
end

endmodule

总体来说颜色的实现还是比较简单的

module color_detector_rgb(
    input [7:0] R, G, B,
    output reg is_red, is_blue, is_yellow, is_gray);

always @* begin
    // 判断是否为红色
    if (R > 128 && G < 100 && B < 100)
        is_red = 1;
    else 
        is_red = 0;

    // 判断是否为蓝色
    if (B > 128 && R < 100 && G < 100)
        is_blue = 1;
    else
        is_blue = 0;

    // 判断是否为黄色
    if (R > 128 && G > 128 && B < 100) 
        is_yellow = 1;
    else
        is_yellow = 0;

    // 判断是否为灰色
    if ((R == G) && (G == B)) 
        is_gray = 1;
    else 
        is_gray = 0;
end

endmodule

形状识别:先进行Sobel边缘检测,然后对于物体形状的识别,要对Sobel运算符的输出进行形状识别,比如说轮廓跟踪(常用的轮廓跟踪算法有韦更斯托姆链码,Freeman链码,K方向链码等。这些算法的基本思想是从某一个边缘像素开始,搜索其邻域像素,寻找边缘点,然后将其连在一起,形成一个链。遇到分叉,则优先选择右方向的像素。这些算法用于轮廓跟踪的Verilog实现可以很复杂,需要处理大量的边缘点和可能的轮廓形状。)、特征提取(存储图像数据,并实现一个简单的面积计算模块)、Hough变换(可以判断图像中有几条线段来判断形状)

让chatgpt写的关于特征提取的代码如下:

module shape_detector(
    input [7:0] pixel_data,
    input pixel_valid,
    input pixel_clk,
    output wire is_square,
    output wire is_triangle,
    output wire is_circle
);
    // Parameters for image dimensions
    parameter WIDTH = 640;
    parameter HEIGHT = 480;
    
    // Memory for image
    reg [WIDTH-1:0] img [0:HEIGHT-1];
    integer x, y;
    
    // Area calculation
    integer area;
    always @(posedge pixel_clk) begin
        if(pixel_valid) begin
            // Store pixel data in memory
            img[x][y] <= pixel_data;
            
            // Simple area calculation
            area = area + (pixel_data ? 1 : 0);
            
            // Update x and y coordinates
            x = x + 1;
            if(x == WIDTH) begin
                x <= 0;
                y <= y + 1;
            end
            if(y == HEIGHT) begin
                y <= 0;
            end
        end
    end
    
    // Shape recognition logic
    // These are placeholders - actual logic will need to be much more complex!
    assign is_square = (area > 5000 && area < 10000) ? 1 : 0;
    assign is_triangle = (area > 10000 && area < 20000) ? 1 : 0;
    assign is_circle = (area > 20000) ? 1 : 0;
endmodule

参考文献:

1】https://blog.csdn.net/qq_47281915/article/details/126041967

2】

相关推荐

  1. 分析图像处理部分

    2024-04-03 09:06:03       16 阅读
  2. 图像处理中的图像分割

    2024-04-03 09:06:03       7 阅读
  3. 图像处理工具包Pillow的使用分享

    2024-04-03 09:06:03       40 阅读
  4. 图像处理工具包Pillow的使用分享

    2024-04-03 09:06:03       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 09:06:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 09:06:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 09:06:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 09:06:03       20 阅读

热门阅读

  1. ActiViz中的图像处理vtkImageActor

    2024-04-03 09:06:03       32 阅读
  2. 设计模式面试题(一)

    2024-04-03 09:06:03       17 阅读
  3. 鸿蒙原生应用开发-网络管理Socket连接(二)

    2024-04-03 09:06:03       15 阅读
  4. Amazon API Gateway 配置自定义域名

    2024-04-03 09:06:03       16 阅读
  5. FPGA在深度学习领域的应用的优势

    2024-04-03 09:06:03       19 阅读
  6. 安装编译cpprest sdk

    2024-04-03 09:06:03       15 阅读
  7. SSH中私钥和公钥的使用

    2024-04-03 09:06:03       18 阅读
  8. Echart(多雷达图展示)

    2024-04-03 09:06:03       22 阅读
  9. openmmlab系列框架多GPU训练

    2024-04-03 09:06:03       12 阅读