用asp做网站出现空白,wordpress 国外免费主题,网络营销推广的方法,企业网站建设的基本标准是基于EBAZ4205矿板的图像处理#xff1a;12图像二值化(阈值可调)
我的项目是基于EBAZ4205矿板的阈值可调的图像阈值二值化处理#xff0c;可以通过按键调整二值化的阈值#xff0c;key1为阈值加1#xff0c;key4为阈值减1#xff0c;key2为阈值加10#xff0c;key5为阈值…基于EBAZ4205矿板的图像处理12图像二值化(阈值可调)
我的项目是基于EBAZ4205矿板的阈值可调的图像阈值二值化处理可以通过按键调整二值化的阈值key1为阈值加1key4为阈值减1key2为阈值加10key5为阈值减10key54为阈值重置为128。
先看效果 拿我的pynq当模特 可以清晰的看到xilinx的商标被划分了出来 阈值过大和过小就不行了这也是全局阈值二值化的缺点接下来我会完成基于卷积的局部阈值二值化它能得到更好的效果尽请期待。
项目解读
我的blockdesign你不按照我的接按照正点原子的开源代码接也是可以的只是我有强迫症能接的我都接了。 就是在标准的ov5640-VDMA-DDR-VDMA-DVI_Driver-HDMI的流程可以点击这个超链接看我说的标准流程的第一个箭头哪里加了三个模块一个负责将图像从RGB格式转化为灰度图像一个负责对灰度图像进行二值化处理最后一个为PS提供了访问PL端reg的AXILite端口以便实时调整阈值。
下面的代码里我都添加了(* X_INTERFACE_IGNORE “true” *) 是禁用vivado的interface自动推断可以不加
rgb2gray模块
该模块负责将图像从RGB格式转化为灰度图像 公式 Y 0.299R 0.587G 0.114B Y (77 R 150G 29 *B)8
timescale 1ns / 1ps
//作者抢公主的大魔王
//功能将来自ov5640视频流从RGB格式转化为灰度图像
//日期24.5.5
//版本1v0
//联系方式2376635586qq.com
module rgb2gray((* X_INTERFACE_IGNORE true *) input cmos_frame_vsync,
(* X_INTERFACE_IGNORE true *) input [23:0] cmos_frame_data,
(* X_INTERFACE_IGNORE true *) input cmos_frame_href,(* X_INTERFACE_IGNORE true *) input cmos_frame_clk,
(* X_INTERFACE_IGNORE true *) input cmos_rstn,//同步复位
(* X_INTERFACE_IGNORE true *) input cmos_frame_ce,(* X_INTERFACE_IGNORE true *) output dataout_frame_vsync,
(* X_INTERFACE_IGNORE true *) output [23:0] dataout_frame_data,
(* X_INTERFACE_IGNORE true *) output dataout_frame_href,
(* X_INTERFACE_IGNORE true *) output dataout_frame_ce);// Y 0.299R 0.587G 0.114B// Y (77 *R 150*G 29 *B)8reg [15:0] r_gray1;reg [15:0] g_gray1;reg [15:0] b_gray1;reg [15:0] y1;reg [7:0] y2;reg [2:0] dataout_frame_vsync_r;reg [2:0] dataout_frame_href_r;reg [2:0] dataout_frame_ce_r;always(posedge cmos_frame_clk)beginif(!cmos_rstn)beginr_gray1 8h00;g_gray1 8h00;b_gray1 8h00;endelse beginr_gray1 cmos_frame_data[23:16] * 8d77 ;g_gray1 cmos_frame_data[15:8] * 8d150;b_gray1 cmos_frame_data[7:0] * 8d29 ;endendalways(posedge cmos_frame_clk)beginif(!cmos_rstn)beginy1 16h0000;endelse beginy1 r_gray1 g_gray1 b_gray1;endendalways(posedge cmos_frame_clk)beginif(!cmos_rstn)beginy2 8h0000;endelse beginy2 y1[15:8];endendalways(posedge cmos_frame_clk)beginif(!cmos_rstn)begindataout_frame_ce_r 3b000;dataout_frame_vsync_r 3b000;dataout_frame_href_r 3b000;endelse begindataout_frame_ce_r {dataout_frame_ce_r[1:0] ,cmos_frame_ce};dataout_frame_vsync_r {dataout_frame_vsync_r[1:0] ,cmos_frame_vsync};dataout_frame_href_r {dataout_frame_href_r[1:0] ,cmos_frame_href};endendassign dataout_frame_data {y2,y2,y2};assign dataout_frame_ce dataout_frame_ce_r[2];assign dataout_frame_vsync dataout_frame_vsync_r[2];assign dataout_frame_href dataout_frame_href_r[2];endmodule
global_binary模块
负责根据阈值对灰度图像进行二值化处理
timescale 1ns / 1ps
//作者抢公主的大魔王
//功能根据阈值对灰度图像进行二值化处理
//日期24.5.5
//版本1v0
//联系方式2376635586qq.com
module global_binary(
(* X_INTERFACE_IGNORE true *) input datain_vsync,
(* X_INTERFACE_IGNORE true *) input [23:0] datain,
(* X_INTERFACE_IGNORE true *) input datain_href,(* X_INTERFACE_IGNORE true *) input datain_clk,
(* X_INTERFACE_IGNORE true *) input datain_rstn,//同步复位
(* X_INTERFACE_IGNORE true *) input datain_frame_ce,(* X_INTERFACE_IGNORE true *) input [7:0]threshold,(* X_INTERFACE_IGNORE true *) output dataout_vsync,
(* X_INTERFACE_IGNORE true *) output reg [23:0] dataout,
(* X_INTERFACE_IGNORE true *) output dataout_vaild,(* X_INTERFACE_IGNORE true *) output dataout_frame_ce);reg [1:0] dataout_vsync_r;
reg [1:0] dataout_valid_r;
reg [1:0] dataout_frame_ce_r;
always(posedge datain_clk)beginif(!datain_rstn)dataout 24hff_ff_ff;else if(datain[7:0]threshold)dataout 24hff_ff_ff;elsedataout 24h00_00_00;
end
always(posedge datain_clk)beginif(!datain_rstn) begindataout_vsync_r 3b000;dataout_valid_r 3b000;dataout_frame_ce_r 3b000;endelse begindataout_vsync_r {dataout_vsync_r[0] , datain_vsync};dataout_valid_r {dataout_valid_r[0] , datain_href};dataout_frame_ce_r {dataout_frame_ce_r[0] , datain_frame_ce};end
endassign dataout_vsync dataout_vsync_r[1];
assign dataout_vaild dataout_valid_r[1];
assign dataout_frame_ce dataout_frame_ce_r[1];endmoduleAXICtrlThreshold模块 这个就是自己打包的标准的AXILite IP核然后加了两句代码一句是将threshold的0到7为连接到这个IP内部的第一个reg的低八位另一句就是让这个reg复位是被复位为128而不是0因为我的图像阈值二值化算法的缺省阈值为128。 打包过程如下 下面要改名字和描述哦。 然后到了这个AXILite IP内部添加下面的代码
assign threshold slv_reg0[7:0];然后更改复位值 if ( S_AXI_ARESETN 1b0 )beginslv_reg0 32d128;slv_reg1 0;slv_reg2 0;slv_reg3 0;end 最后把它output出去
output wire [7:0] thresholdIP代码本身和她的top层都要output
然后在这一栏所有不是对号的要挨个点一遍挨个更新一下最后全是对号之后就可以打包了。
vitis端代码
IntrHandler是中断回调函数触发中断后会调用这个函数。 SetupInterruptSystem负责初始化中断配置触发中断方式使能中断。 Gpio_Init初始化GPIO包括key1-5led1-3和sccb总线配置OV5640的 binary_threshold就是我的图像阈值二值化的阈值啦可以通过按键进行调整。
//作者抢公主的大魔王
//功能阈值可调的图像二值化
//日期24.5.5
//版本1v0
//联系方式2376635586qq.com
#include stdio.h
#include stdlib.h
#include string.h
#include xil_types.h
#include xil_cache.h
#include xparameters.h
#include xgpiops.h
#include xscugic.h
#include xil_exception.h
#include xplatform_info.h
#include xaxivdma.h
#include xaxivdma_i.h
#include display_ctrl_hdmi/display_ctrl.h
#include vdma_api/vdma_api.h
#include emio_sccb_cfg/emio_sccb_cfg.h
#include ov5640/ov5640_init.h
#include sleep.h//宏定义
#define DYNCLK_BASEADDR XPAR_AXI_DYNCLK_0_BASEADDR //动态时钟基地址
#define VDMA_ID XPAR_AXIVDMA_0_DEVICE_ID //VDMA器件ID
#define DISP_VTC_ID XPAR_VTC_0_DEVICE_ID //VTC器件ID
#define THRESHOLD_BASEADDR XPAR_AXICTRLTHRESHOLD_0_S00_AXI_BASEADDR#define EMIO_SCL_NUM 54
#define EMIO_SDA_NUM 55
#define KEY1 56 //T19
#define KEY2 57 //P19
#define KEY3 58 //U20
#define KEY4 59 //U19
#define KEY5 60 //V20
#define LED1 61 //H18
#define LED2 62 //K17
#define LED3 63 //E19#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID
XGpioPs Gpio;
#define GPIO_BANK XGPIOPS_BANK0 /* Bank 0 of the GPIO Device */
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#define GPIO_INTERRUPT_ID XPAR_XGPIOPS_0_INTR//全局变量
//frame buffer的起始地址
unsigned int const frame_buffer_addr (XPAR_PS7_DDR_0_S_AXI_BASEADDR 0x1000000);
u8 binary_threshold 128;
XAxiVdma vdma;
DisplayCtrl dispCtrl;
VideoMode vd_mode;static XScuGic Intc; /* The Instance of the Interrupt Controller Driver */static void IntrHandler(void *CallBackRef, u32 Bank, u32 Status)
{XGpioPs *Gpio_cb (XGpioPs *)CallBackRef;if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY1)){binary_threshold;Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);xil_printf(The threshold has been changed\n\rThe threshold now is %d\n\r,binary_threshold);XGpioPs_IntrClearPin(Gpio_cb, KEY1);}else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY4)){binary_threshold--;Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);xil_printf(The threshold has been changed\n\rThe threshold now is %d\n\r,binary_threshold);XGpioPs_IntrClearPin(Gpio_cb, KEY4);}else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY2)){binary_threshold binary_threshold10;Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);xil_printf(The threshold has been changed\n\rThe threshold now is %d\n\r,binary_threshold);XGpioPs_IntrClearPin(Gpio_cb, KEY2);}else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY5)){binary_threshold binary_threshold-10;Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);xil_printf(The threshold has been changed\n\rThe threshold now is %d\n\r,binary_threshold);XGpioPs_IntrClearPin(Gpio_cb, KEY5);}else if (XGpioPs_IntrGetStatusPin(Gpio_cb, KEY3)){binary_threshold 128;Xil_Out32(THRESHOLD_BASEADDR, binary_threshold);xil_printf(The threshold has been reset\n\rThe threshold now is %d\n\r,binary_threshold);XGpioPs_IntrClearPin(Gpio_cb, KEY3);}XGpioPs_WritePin(Gpio, LED1, !XGpioPs_ReadPin(Gpio, LED1));
}void SetupInterruptSystem(XScuGic *GicInstancePtr, XGpioPs *Gpio,u16 GpioIntrId){XScuGic_Config *IntcConfig;Xil_ExceptionInit();IntcConfig XScuGic_LookupConfig(INTC_DEVICE_ID);XScuGic_CfgInitialize(GicInstancePtr, IntcConfig,IntcConfig-CpuBaseAddress);Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XScuGic_InterruptHandler,GicInstancePtr);XScuGic_Connect(GicInstancePtr, GpioIntrId,(Xil_ExceptionHandler)IntrHandler,(void *)Gpio);XScuGic_Enable(GicInstancePtr, GpioIntrId);XGpioPs_SetIntrTypePin(Gpio, KEY1, XGPIOPS_IRQ_TYPE_EDGE_FALLING);XGpioPs_SetIntrTypePin(Gpio, KEY2, XGPIOPS_IRQ_TYPE_EDGE_FALLING);XGpioPs_SetIntrTypePin(Gpio, KEY3, XGPIOPS_IRQ_TYPE_EDGE_FALLING);XGpioPs_SetIntrTypePin(Gpio, KEY4, XGPIOPS_IRQ_TYPE_EDGE_FALLING);XGpioPs_SetIntrTypePin(Gpio, KEY5, XGPIOPS_IRQ_TYPE_EDGE_FALLING);XGpioPs_IntrEnablePin(Gpio, KEY1);XGpioPs_IntrEnablePin(Gpio, KEY2);XGpioPs_IntrEnablePin(Gpio, KEY3);XGpioPs_IntrEnablePin(Gpio, KEY4);XGpioPs_IntrEnablePin(Gpio, KEY5);Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);
}void Gpio_Init(void){XGpioPs_Config *ConfigPtr;ConfigPtr XGpioPs_LookupConfig(GPIO_DEVICE_ID);XGpioPs_CfgInitialize(Gpio, ConfigPtr,ConfigPtr-BaseAddr);XGpioPs_SetDirectionPin(Gpio, LED1, 1);XGpioPs_SetOutputEnablePin(Gpio, LED1, 1);XGpioPs_WritePin(Gpio, LED1, 0);XGpioPs_SetDirectionPin(Gpio, LED2, 1);XGpioPs_SetOutputEnablePin(Gpio, LED2, 1);XGpioPs_WritePin(Gpio, LED2, 0);XGpioPs_SetDirectionPin(Gpio, LED3, 1);XGpioPs_SetOutputEnablePin(Gpio, LED3, 1);XGpioPs_WritePin(Gpio, LED3, 0);XGpioPs_SetDirectionPin(Gpio, KEY1, 0);XGpioPs_SetDirectionPin(Gpio, KEY2, 0);XGpioPs_SetDirectionPin(Gpio, KEY3, 0);XGpioPs_SetDirectionPin(Gpio, KEY4, 0);XGpioPs_SetDirectionPin(Gpio, KEY5, 0);SetupInterruptSystem(Intc, Gpio, GPIO_INTERRUPT_ID);}int main(void)
{u32 status;u16 cmos_h_pixel; //ov5640 DVP 输出水平像素点数u16 cmos_v_pixel; //ov5640 DVP 输出垂直像素点数u16 total_h_pixel; //ov5640 水平总像素大小u16 total_v_pixel; //ov5640 垂直总像素大小cmos_h_pixel 1280;cmos_v_pixel 720;total_h_pixel 2570;total_v_pixel 980;emio_init();status ov5640_init( cmos_h_pixel, //初始化ov5640cmos_v_pixel,total_h_pixel,total_v_pixel);//设置OV5640输出分辨率为1280*720 PCLK 72Mhzif(status 0)xil_printf(OV5640 detected successful!\r\n);elsexil_printf(OV5640 detected failed!\r\n);vd_mode VMODE_1280x720;//配置VDMArun_vdma_frame_buffer(vdma, VDMA_ID, vd_mode.width, vd_mode.height,frame_buffer_addr,0,0,BOTH);//初始化Display controllerDisplayInitialize(dispCtrl, DISP_VTC_ID, DYNCLK_BASEADDR);//设置VideoModeDisplaySetMode(dispCtrl, vd_mode);DisplayStart(dispCtrl);Gpio_Init();while(1){XGpioPs_WritePin(Gpio, LED3, !XGpioPs_ReadPin(Gpio, LED3));sleep(1);}return 0;
} 文章转载自: http://www.morning.kpfds.cn.gov.cn.kpfds.cn http://www.morning.shuanga.com.cn.gov.cn.shuanga.com.cn http://www.morning.lstmq.cn.gov.cn.lstmq.cn http://www.morning.dqwkm.cn.gov.cn.dqwkm.cn http://www.morning.lpbrp.cn.gov.cn.lpbrp.cn http://www.morning.lkmks.cn.gov.cn.lkmks.cn http://www.morning.qmqgx.cn.gov.cn.qmqgx.cn http://www.morning.ttryd.cn.gov.cn.ttryd.cn http://www.morning.fglth.cn.gov.cn.fglth.cn http://www.morning.psgbk.cn.gov.cn.psgbk.cn http://www.morning.nfzzf.cn.gov.cn.nfzzf.cn http://www.morning.jtfcd.cn.gov.cn.jtfcd.cn http://www.morning.ayftwl.cn.gov.cn.ayftwl.cn http://www.morning.qzglh.cn.gov.cn.qzglh.cn http://www.morning.nnhfz.cn.gov.cn.nnhfz.cn http://www.morning.mtrrf.cn.gov.cn.mtrrf.cn http://www.morning.yrsg.cn.gov.cn.yrsg.cn http://www.morning.kyjpg.cn.gov.cn.kyjpg.cn http://www.morning.xkyfq.cn.gov.cn.xkyfq.cn http://www.morning.gchqy.cn.gov.cn.gchqy.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.bwmm.cn.gov.cn.bwmm.cn http://www.morning.errnull.com.gov.cn.errnull.com http://www.morning.wfysn.cn.gov.cn.wfysn.cn http://www.morning.ftznb.cn.gov.cn.ftznb.cn http://www.morning.jxcwn.cn.gov.cn.jxcwn.cn http://www.morning.mkpqr.cn.gov.cn.mkpqr.cn http://www.morning.qsswb.cn.gov.cn.qsswb.cn http://www.morning.ypdhl.cn.gov.cn.ypdhl.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.gyfhk.cn.gov.cn.gyfhk.cn http://www.morning.rtbj.cn.gov.cn.rtbj.cn http://www.morning.pdmsj.cn.gov.cn.pdmsj.cn http://www.morning.bwfsn.cn.gov.cn.bwfsn.cn http://www.morning.jnptt.cn.gov.cn.jnptt.cn http://www.morning.xfrqf.cn.gov.cn.xfrqf.cn http://www.morning.qqklk.cn.gov.cn.qqklk.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.nlkjq.cn.gov.cn.nlkjq.cn http://www.morning.mxnrl.cn.gov.cn.mxnrl.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.irqlul.cn.gov.cn.irqlul.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.bkfdf.cn.gov.cn.bkfdf.cn http://www.morning.feites.com.gov.cn.feites.com http://www.morning.ccpnz.cn.gov.cn.ccpnz.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.dmkhd.cn.gov.cn.dmkhd.cn http://www.morning.lqjlg.cn.gov.cn.lqjlg.cn http://www.morning.yzzfl.cn.gov.cn.yzzfl.cn http://www.morning.txzqf.cn.gov.cn.txzqf.cn http://www.morning.qbfqb.cn.gov.cn.qbfqb.cn http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn http://www.morning.hqrkq.cn.gov.cn.hqrkq.cn http://www.morning.grxsc.cn.gov.cn.grxsc.cn http://www.morning.ljbpk.cn.gov.cn.ljbpk.cn http://www.morning.brbnc.cn.gov.cn.brbnc.cn http://www.morning.mlwhd.cn.gov.cn.mlwhd.cn http://www.morning.rgxll.cn.gov.cn.rgxll.cn http://www.morning.ptqbt.cn.gov.cn.ptqbt.cn http://www.morning.zxznh.cn.gov.cn.zxznh.cn http://www.morning.ngjpt.cn.gov.cn.ngjpt.cn http://www.morning.nbwyk.cn.gov.cn.nbwyk.cn http://www.morning.kztpn.cn.gov.cn.kztpn.cn http://www.morning.yqrfn.cn.gov.cn.yqrfn.cn http://www.morning.xysdy.cn.gov.cn.xysdy.cn http://www.morning.fksrg.cn.gov.cn.fksrg.cn http://www.morning.rtlth.cn.gov.cn.rtlth.cn http://www.morning.ksjnl.cn.gov.cn.ksjnl.cn http://www.morning.hsrpc.cn.gov.cn.hsrpc.cn http://www.morning.xzjsb.cn.gov.cn.xzjsb.cn http://www.morning.dzgyr.cn.gov.cn.dzgyr.cn http://www.morning.ktqtf.cn.gov.cn.ktqtf.cn http://www.morning.uqrphxm.cn.gov.cn.uqrphxm.cn http://www.morning.hgtr.cn.gov.cn.hgtr.cn http://www.morning.dmzqd.cn.gov.cn.dmzqd.cn http://www.morning.xltwg.cn.gov.cn.xltwg.cn http://www.morning.cfnht.cn.gov.cn.cfnht.cn http://www.morning.jrpmf.cn.gov.cn.jrpmf.cn