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

相关推荐
weixin_4080996712 小时前
OCR批量识别图片方案:从手动处理到自动化API系统(Python/Java/PHP实战)
图像处理·python·ocr·文字识别·api调用·批量识别·石榴智能
2zcode18 小时前
免费开源项目文档:基于MATLAB图像处理的药片检测与计数系统设计与实现
开发语言·图像处理·matlab
techdashen21 小时前
从网络栈继续往下:micro:bit、2.4GHz、调制方式,以及一个不太靠谱但很有趣的想法
网络·fpga开发
FPGA小徐21 小时前
FIR 数字滤波器 --verilog设计实现
fpga开发
zlinear数据采集卡21 小时前
从协议解析到波形实时显示:硬核拆解ZLinear采集卡上位机软件的开发架构
arm开发·单片机·嵌入式硬件·fpga开发·架构·开源
pcjiushizhu21 小时前
ModelSim 仿真时 Simulate 无反应或只显示 Loading 的解决方法:网卡问题排查
fpga开发
这张生成的图像能检测吗1 天前
(论文速读)CWNet:用于微光图像增强的因果小波网络
图像处理·人工智能·深度学习·机器学习·低照度图像增强
FPGA小迷弟1 天前
vivado中的AXI Interconnect到底应该怎么用,他的底层原理是什么,一篇文档全部理清楚!!!
网络协议·tcp/ip·fpga开发·verilog·fpga
2zcode1 天前
基于MATLAB图像处理的苹果质量智能分级系统设计与实现
图像处理·人工智能·matlab
国科安芯1 天前
ASC4T245S分组双向控制架构深度解析:独立DIR/OE控制、QFN16封装与混合方向总线桥接
单片机·嵌入式硬件·物联网·fpga开发·架构·risc-v