FPGA图像处理(四)------ 图像裁剪

复制代码
`timescale 1ns / 1ps
//
// Description:  图像裁剪算法
//
module image_crop(
   input wire clk,
   input wire reset,
   
   input wire [10:0] img_width,
   input wire [10:0] img_height,
   input wire [10:0] img_x_start,
   input wire [10:0] img_x_end,
   input wire [10:0] img_y_start,
   input wire [10:0] img_y_end,
   
   input wire valid_i,
   input wire [23:0] img_data_i,
   
   output reg valid_o,
   output reg [23:0] img_data_o
   );

    //参数声明
    reg [10:0] x_cnt_r; //行计数器
    reg [10:0] y_cnt_r; //列计数器

    //计数
    always@(posedge clk or posedge reset) begin
        if(reset) begin
            x_cnt_r <= 'b0;
            y_cnt_r <= 'b0;
        end else begin
            x_cnt_r <= valid_i ? ((x_cnt_r == img_width - 1) ? 0 : x_cnt_r + 1) : x_cnt_r;
            y_cnt_r <= valid_i&&(x_cnt_r == img_width - 1) ? ((y_cnt_r == img_height - 1) ? 0 : y_cnt_r + 1) : y_cnt_r;
        end
    end    
    
    always@(posedge clk or posedge reset) begin
        if(reset) begin
            valid_o <= 'b0;
            img_data_o <= 'b0;
        end else begin
            valid_o <= valid_i&&(x_cnt_r >= img_x_start)&&(x_cnt_r < img_x_end)&&(y_cnt_r >= img_y_start)&&(y_cnt_r < img_y_end) ? 1'b1 : 1'b0;
            img_data_o <= img_data_i;
        end
    end
    
endmodule

相关推荐
minglie11 小时前
黑金AX301的EEPROM 24LC04
fpga开发
Hello-FPGA1 小时前
量子计算滨松c15550-22up单光子相机与PCIe1004采集卡
人工智能·计算机视觉·fpga开发
9527华安3 小时前
FPGA实现CameraLink转SFP光口,基于GT Transceivers Wizard Aurora8B10B编解码架构,提供4套工程源码和技术支持
fpga开发·sfp·cameralink·aurora8b10b·transceivers
AndrewHZ21 小时前
图像处理入门020 | 图像二值化:阈值分割基础 —— cv2.threshold 五种类型与自适应阈值铺垫
图像处理·opencv·文档扫描·阈值分割·图像二值化·trackbar·自适应阈值
笑霸final1 天前
不用上传服务器!用 Vue3 + ONNX Runtime Web 在浏览器本地实现智能抠图
运维·前端·图像处理·ai·onnx·canva可画·web性能优化
ALINX技术博客1 天前
【期刊共读】如何应对 FPGA 短缺常态?
嵌入式硬件·fpga开发·fpga
156082072191 天前
短波接收机灵敏度测试
fpga开发
Riwuarua2 天前
从近似0基础开始FPGA开发 -- part.6 逻辑设计与状态机
fpga开发
LCG元2 天前
【实战】Vivado FPGA 从零实现 UART 串口收发:波特率生成、状态机设计与仿真调试
fpga开发
郭郭的柳柳在学FPGA2 天前
紫光DDR3工程仿真遇到的坑
fpga开发