From 1ad504cb9f8627eaede2bfe9dd62dd043309a712 Mon Sep 17 00:00:00 2001 From: SikongJueluo Date: Fri, 17 May 2024 16:47:28 +0800 Subject: [PATCH] fix some bugs --- Crop/crop.v | 2 +- Demosaic/demosaic2.v | 9 ++++++++- isp.v | 6 ++++-- sim/sc_main.cpp | 4 +--- sim/transform/raw_to_image.py | 6 +++--- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Crop/crop.v b/Crop/crop.v index edf77b1..f8e998e 100644 --- a/Crop/crop.v +++ b/Crop/crop.v @@ -22,7 +22,7 @@ module crop #( localparam SEND_DATA = 2; reg [1:0] state, nextState; - reg [11:0] cnt_x, cnt_y; + reg [31:0] cnt_x, cnt_y; reg [3 * COLOR_DEPTH - 1:0] data; // 状态切换 diff --git a/Demosaic/demosaic2.v b/Demosaic/demosaic2.v index 01a115a..db0300d 100644 --- a/Demosaic/demosaic2.v +++ b/Demosaic/demosaic2.v @@ -150,8 +150,15 @@ module demosaic2 #( cnt_data <= 0; pos_x <= 0; pos_y <= pos_y + 1; - if (pos_y >= IM_HEIGHT - 2 - 1) + if (pos_y >= IM_HEIGHT - 2 - 1) begin pos_y <= 0; + case (RAW_TYPE) + 0: raw_type <= 2; + 1: raw_type <= 3; + 2: raw_type <= 0; + 3: raw_type <= 1; + endcase + end end else begin cnt_data <= 2; diff --git a/isp.v b/isp.v index 1326faa..24d228e 100644 --- a/isp.v +++ b/isp.v @@ -21,6 +21,8 @@ module isp #( output wire out_en, output reg [3 * COLOR_DEPTH - 1:0] data_out ); + localparam BAYER_WIDTH = IN_WIDTH - 2; + localparam BAYER_HEIGHT = IN_HEIGHT - 2; // 三通道合成RGB图像 wire rgb_en; wire [15:0] im_red, im_green, im_blue; @@ -66,8 +68,8 @@ module isp #( ); crop #( - .IN_WIDTH(IN_WIDTH), - .IN_HEIGHT(IN_HEIGHT), + .IN_WIDTH(BAYER_WIDTH), + .IN_HEIGHT(BAYER_HEIGHT), .OUT_WIDTH(OUT_WIDTH), .OUT_HEIGHT(OUT_HEIGHT), .COLOR_DEPTH(COLOR_DEPTH) diff --git a/sim/sc_main.cpp b/sim/sc_main.cpp index 57a9dfb..0d94667 100644 --- a/sim/sc_main.cpp +++ b/sim/sc_main.cpp @@ -119,7 +119,7 @@ int sc_main(int argc, char* argv[]) { ifstream in_image; ofstream out_image; in_image.open("./transform/test.bin", ios::in | ios::binary); - out_image.open("./out.bin", ios::out | ios::binary); + out_image.open("./transform/out.bin", ios::out | ios::binary); if (!in_image.is_open()) { cout << "Open image fail" << endl; exit(0); @@ -128,13 +128,11 @@ int sc_main(int argc, char* argv[]) { } // Read image - // uint8_t buf[IN_SIZE * 2] = {0}; auto buf = make_unique(2 * IN_SIZE); // vector> buf(IN_HEIGHT, vector(IN_WIDTH, 0)); in_image.read((char*)buf.get(), IN_SIZE * 2); in_image.close(); // Reshape data - // uint16_t image[IN_HEIGHT][IN_WIDTH] = {0}; auto image = make_unique(IN_SIZE); uint32_t i = 0; for (int y = 0; y < IN_HEIGHT; y++) { diff --git a/sim/transform/raw_to_image.py b/sim/transform/raw_to_image.py index 960ba24..3959ce5 100644 --- a/sim/transform/raw_to_image.py +++ b/sim/transform/raw_to_image.py @@ -1,10 +1,10 @@ import imageio import numpy as np -im_width = 512 -im_height = 256 +im_width = 640 +im_height = 480 if __name__ == '__main__': - raw = np.fromfile('./out.bin', dtype=np.int16) + raw = np.fromfile('./out.bin', dtype=np.int32) image = raw.reshape((im_height, im_width)) imageio.imsave("./out.png", image)