本帖最后由 FPGA课程 于 2024-10-22 19:58 编辑
软件版本:VIVADO2021.1
操作系统:WIN10 64bit
硬件平台:适用 XILINX A7/K7/Z7/ZU/KU 系列 FPGA
实验平台:米联客-MLK-H3-CZ08-7100开发板
板卡获取平台:https://milianke.tmall.com/
登录“米联客”FPGA社区 http://www.uisrc.com 视频课程、答疑解惑!
1 图像肤色识别算法简介在《human skin color clustering for face detection》一篇文章中,讲解了如何使用肤色识别进行了人脸检测, 算法的推理过程,这里不讲解,感兴趣的可以去看看原文。这里只拿来论文中的结论进行实践,论文中提到了基于 RGB 颜色空间的肤色识别,判别式如下: R>95and G>40 and B>20 and R>G and R>B and Max(R,G,B)-Min(R,G,B)>15 and abs(R-G)>15 基于 YCbCr 颜色空间的肤色识别,将图像转换到 YCbCr 颜色空间,然后按下述计算式判断是否属于皮肤域: (Cb > 77 and Cb7 < 127) and (Cr > 133 and Cr < 173) 肤色识别算法计算量小,算法实践简单,缺点也很明显,容易受到外界背景干扰。 具体的计算过程是,将实时的帧图像从 RGB 转换成 YCbCr,然后按照上述的肤色识别计算公式,将肤色的区 域标记,然后进行图像二值化运算,区分出背景和肤色部分,进行膨胀、腐蚀去除噪点,最后将肤色区域进行框选 叠加在实时的视频中。 2设计分析
2.1Verilog 代码分析
- // ycbcr0(:,:,1) = 0.2568*image_in_r + 0.5041*image_in_g + 0.0979*image_in_b + 16;
- // ycbcr0(:,:,2) = -0.1482*image_in_r - 0.2910*image_in_g + 0.4392*image_in_b + 128;
- // ycbcr0(:,:,3) = 0.4392*image_in_r - 0.3678*image_in_g - 0.0714*image_in_b + 128;
- // ycbcr0(:,:,1) = 256*( 0.2568*image_in_r + 0.5041*image_in_g + 0.0979*image_in_b + 16 )>>8;
- // ycbcr0(:,:,2) = 256*(-0.1482*image_in_r - 0.2910*image_in_g + 0.4392*image_in_b + 128)>>8;
- // ycbcr0(:,:,3) = 256*( 0.4392*image_in_r - 0.3678*image_in_g - 0.0714*image_in_b + 128)>>8;
- // ycbcr0(:,:,1) = (66*image_in_r + 129*image_in_g + 25*image_in_b + 4096 )>>8;
- // ycbcr0(:,:,2) = (-38*image_in_r - 74*image_in_g + 112*image_in_b + 32768)>>8;
- // ycbcr0(:,:,3) = (112*image_in_r - 94*image_in_g - 18*image_in_b + 32768 )>>8;
- reg [15:0] r_d0;
- reg [15:0] g_d0;
- reg [15:0] b_d0;
- reg [15:0] r_d1;
- reg [15:0] g_d1;
- reg [15:0] b_d1;
- reg [15:0] r_d2;
- reg [15:0] g_d2;
- reg [15:0] b_d2;
- reg [15:0] y_d0;
- reg [15:0] cb_d0;
- reg [15:0] cr_d0;
- reg [7:0] y_d1;
- reg [7:0] cb_d1;
- reg [7:0] cr_d1;
- reg [7:0] skin_color_r;
- reg [7:0] skin_color_g;
- reg [7:0] skin_color_b;
- reg [3:0] hsyn;
- reg [3:0] vsyn;
- reg [3:0] de;
- always@(posedge i_clk ornegedge i_rst_n) begin
- if(!i_rst_n) begin
- r_d0 <= 16'd0;
- g_d0 <= 16'd0;
- b_d0 <= 16'd0;
- r_d1 <= 16'd0;
- g_d1 <= 16'd0;
- b_d1 <= 16'd0;
- r_d2 <= 16'd0;
- g_d2 <= 16'd0;
- b_d2 <= 16'd0;
- end
- else begin
- r_d0 <= 66 * i_r;
- g_d0 <= 129 * i_g;
- b_d0 <= 25 * i_b;
- _d1 <= 38 * i_r;
- g_d1 <= 74 * i_g;
- b_d1 <= 112 * i_b;
- r_d2 <= 112 * i_r;
- g_d2 <= 94 * i_g;
- b_d2 <= 18 * i_b;
- end
- end
- always@(posedge i_clk ornegedge i_rst_n) begin
- if(!i_rst_n) begin
- y_d0 <= 16'd0;
- cb_d0 <= 16'd0;
- cr_d0 <= 16'd0;
- end
- else begin
- y_d0 <= r_d0 + g_d0 + b_d0 + 4096 ;
- cb_d0 <= b_d1 - r_d1 - g_d1 + 32768;
- cr_d0 <= r_d2 - g_d2 - b_d2 + 32768;
- end
- end
- always@(posedge i_clk ornegedge i_rst_n) begin
- if(!i_rst_n) begin
- y_d1 <= 16'd0;
- cb_d1 <= 16'd0;
- cr_d1 <= 16'd0;
- end
- else begin
- y_d1 <= y_d0[15:8];
- cb_d1 <= cb_d0[15:8];
- cr_d1 <= cr_d0[15:8];
- end
- end
- always@(posedge i_clk ornegedge i_rst_n) begin
- if(!i_rst_n) begin
- skin_color_r <= 8'd0;
- skin_color_g <= 8'd0;
- skin_color_b <= 8'd0;
- end
- else if(cb_d1 > 77 && cb_d1 < 127 && cr_d1 > 133 && cr_d1 < 173) begin
- skin_color_r <= 8'd255;
- skin_color_g <= 8'd255;
- skin_color_b <= 8'd255;
- end
- else begin
- skin_color_r <= 8'd0;
- skin_color_g <= 8'd0;
- skin_color_b <= 8'd0;
- end
- end
复制代码
2.2 工程结构分析
我们将图像算法的模块做成 IP 后,在vivado 中进行工程的搭建,工程结构如图所示:
3 搭建 Vitis-sdk 工程
创建 soc_base sdk platform 和 APP 工程的过程不再重复,可以阅读 3-3-01_sdk_base_app。以下给出创建好 soc_base sdk platform 的截图和对应工程 APP 的截图。 3.1 创建 SDK Platform 工程
3.2SDK APP 工程
4 硬件连接
硬件连接如图所示
5 上板实验结果实验结果如图所示:
|