├── .gitignore
├── Disparity_Window_5_simulation.pdf
├── Disparity_Window_7_simulation.pdf
├── Img
├── FlowChart.png
├── Tsukuba_L.bmp
├── Tsukuba_L.png
├── Tsukuba_R.bmp
├── Tsukuba_R.png
├── Tsukuba_R_t.png
├── VerilogSimulationTime.png
├── maskL.bmp
├── maskL.png
├── maskR.bmp
├── maskR.png
├── test.png
├── toyL.bmp
├── toyL.png
├── toyR.bmp
└── toyR.png
├── Python_test_implementation
├── Disparity_Python_implementation_scratch.ipynb
├── Disparity_TSukuba_5.jpg
├── Disparity_Tsukuba.jpg
├── Disparity__colorMap_Toy_5_python.jpg
├── Disparity__colorMap_Tsukuba.jpg
├── Disparity__colorMap_Tsukuba_5_python.jpg
├── Disparity_toy_5.jpg
├── img2hex.ipynb
├── imgtohex.ipynb
├── number.txt
└── python.py
├── README.md
├── Tsukuba_L.hex
├── Tsukuba_R.hex
├── Tsukuba_output_3.bmp
├── Tsukuba_output_5.bmp
├── Tsukuba_output_7.bmp
├── image.hex
├── image_read.v
├── image_write.v
├── imgtohex.ipynb
├── output.bmp
├── output.png
├── parameter.v
├── simulation.pdf
└── tb_simulation.v
/.gitignore:
--------------------------------------------------------------------------------
1 | .ipynb_checkpoints/
2 | _xmsgs/
3 | iseconfig/
4 | isim/
5 |
6 | *.log
7 | *.xmsgs
8 | *.html
9 | *.htm
10 | *.cmd
11 | *.ini
12 | *.exe
13 | *.xise
14 | *.gise
15 | *.wdb
16 | *.prj
17 | *.bld
18 | *.cmd_log
19 |
20 | # intermediate build files
21 | *.bgn
22 | *.bit
23 | *.bld
24 | *.cmd_log
25 | *.drc
26 | *.ll
27 | *.lso
28 | *.msd
29 | *.msk
30 | *.ncd
31 | *.ngc
32 | *.ngd
33 | *.ngr
34 | *.pad
35 | *.par
36 | *.pcf
37 | *.prj
38 | *.ptwx
39 | *.rbb
40 | *.rbd
41 | *.stx
42 | *.syr
43 | *.twr
44 | *.twx
45 | *.unroutes
46 | *.ut
47 | *.xpi
48 | *.xst
49 | *_bitgen.xwbt
50 | *_envsettings.html
51 | *_map.map
52 | *_map.mrp
53 | *_map.ngm
54 | *_map.xrpt
55 | *_ngdbuild.xrpt
56 | *_pad.csv
57 | *_pad.txt
58 | *_par.xrpt
59 | *_summary.html
60 | *_summary.xml
61 | *_usage.xml
62 | *_xst.xrpt
63 |
64 | # iMPACT generated files
65 | _impactbatch.log
66 | impact.xsl
67 | impact_impact.xwbt
68 | ise_impact.cmd
69 | webtalk_impact.xml
70 |
71 | # Core Generator generated files
72 | xaw2verilog.log
73 |
74 | # project-wide generated files
75 | *.gise
76 | par_usage_statistics.html
77 | usage_statistics_webtalk.html
78 | webtalk.log
79 | webtalk_pn.xml
80 |
81 | # generated folders
82 | iseconfig/
83 | xlnx_auto_0_xdb/
84 | xst/
85 | _ngo/
86 | _xmsgs/
--------------------------------------------------------------------------------
/Disparity_Window_5_simulation.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Disparity_Window_5_simulation.pdf
--------------------------------------------------------------------------------
/Disparity_Window_7_simulation.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Disparity_Window_7_simulation.pdf
--------------------------------------------------------------------------------
/Img/FlowChart.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/FlowChart.png
--------------------------------------------------------------------------------
/Img/Tsukuba_L.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/Tsukuba_L.bmp
--------------------------------------------------------------------------------
/Img/Tsukuba_L.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/Tsukuba_L.png
--------------------------------------------------------------------------------
/Img/Tsukuba_R.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/Tsukuba_R.bmp
--------------------------------------------------------------------------------
/Img/Tsukuba_R.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/Tsukuba_R.png
--------------------------------------------------------------------------------
/Img/Tsukuba_R_t.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/Tsukuba_R_t.png
--------------------------------------------------------------------------------
/Img/VerilogSimulationTime.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/VerilogSimulationTime.png
--------------------------------------------------------------------------------
/Img/maskL.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/maskL.bmp
--------------------------------------------------------------------------------
/Img/maskL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/maskL.png
--------------------------------------------------------------------------------
/Img/maskR.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/maskR.bmp
--------------------------------------------------------------------------------
/Img/maskR.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/maskR.png
--------------------------------------------------------------------------------
/Img/test.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/test.png
--------------------------------------------------------------------------------
/Img/toyL.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/toyL.bmp
--------------------------------------------------------------------------------
/Img/toyL.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/toyL.png
--------------------------------------------------------------------------------
/Img/toyR.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/toyR.bmp
--------------------------------------------------------------------------------
/Img/toyR.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Img/toyR.png
--------------------------------------------------------------------------------
/Python_test_implementation/Disparity_TSukuba_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Python_test_implementation/Disparity_TSukuba_5.jpg
--------------------------------------------------------------------------------
/Python_test_implementation/Disparity_Tsukuba.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Python_test_implementation/Disparity_Tsukuba.jpg
--------------------------------------------------------------------------------
/Python_test_implementation/Disparity__colorMap_Toy_5_python.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Python_test_implementation/Disparity__colorMap_Toy_5_python.jpg
--------------------------------------------------------------------------------
/Python_test_implementation/Disparity__colorMap_Tsukuba.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Python_test_implementation/Disparity__colorMap_Tsukuba.jpg
--------------------------------------------------------------------------------
/Python_test_implementation/Disparity__colorMap_Tsukuba_5_python.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Python_test_implementation/Disparity__colorMap_Tsukuba_5_python.jpg
--------------------------------------------------------------------------------
/Python_test_implementation/Disparity_toy_5.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Python_test_implementation/Disparity_toy_5.jpg
--------------------------------------------------------------------------------
/Python_test_implementation/img2hex.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 66,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import cv2\n",
10 | "import base64\n",
11 | "import numpy as np"
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 83,
17 | "metadata": {},
18 | "outputs": [
19 | {
20 | "name": "stdout",
21 | "output_type": "stream",
22 | "text": [
23 | "77878\n",
24 | "76800\n"
25 | ]
26 | }
27 | ],
28 | "source": [
29 | "image = cv2.imread('Img/image.jpg')\n",
30 | "gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n",
31 | "#buffer = cv2.imencode('.jpg', image)\n",
32 | "(tmp,buffer) = cv2.imencode('.bmp', gray)\n",
33 | "#imcode = base64.b64encode(buffer)\n",
34 | "#print(tmp)\n",
35 | "print (len(buffer))\n",
36 | "#230454\n",
37 | "buffer=buffer[1078:]\n",
38 | "print (len(buffer))"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 88,
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "name": "stderr",
48 | "output_type": "stream",
49 | "text": [
50 | "c:\\users\\aruna\\appdata\\local\\programs\\python\\python36\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead\n",
51 | " \"\"\"Entry point for launching an IPython kernel.\n"
52 | ]
53 | },
54 | {
55 | "ename": "TypeError",
56 | "evalue": "bad argument type for built-in operation",
57 | "output_type": "error",
58 | "traceback": [
59 | "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
60 | "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
61 | "\u001b[1;32m
66 | Left image and Right Tsukuba images
67 |
80 |
82 | Python results
83 |
25 |
26 |
27 | Hardware used for this project
28 |
29 | - Basys 3 FPGA board
30 | - 2x OV7670 image sensor modules
31 |
32 |
33 |
34 |
35 |
36 | This project has 3 major sections
37 |
38 | 1. [Functional verification of disparity generator based on Verilog](https://github.com/Archfx/FPGA_depthMap)
39 | 2. [Stereo camera implementation using OV7670 sensors based on VHDL](https://github.com/Archfx/FPGA-stereo-Camera-Basys3)
40 | 3. [Real time disparity generation on Basys3 FPGA](https://github.com/Archfx/FPGA-DepthMap-Basys3)
41 |
42 |
43 | ## Functional verification
44 |
45 | Hardware description languages(HDL) are not meant to be for rapid prototyping. Therefore, in this case, I have used python as the prototyping tool. The SAD algorithm was implemented on python from scratch without using any external library. I refrained from using 2D image arrays to store data because then the HDL implementation is straight forward.
46 |
47 | **SAD/SSD theory**
48 |
49 | Sum of Absolute difference and Sum of Squared Difference Disparity calculation theory is based on a simple geometric concept. Where they use the stereo vision to calculate the distance to the objects. For the implementation, two cameras should be on the same plane and they should not have any vertical offsets in their alignments.
50 |
51 |
52 |
53 |
54 |
55 | **Python implementation**
56 |
57 | The python implementation can be found [here](https://github.com/Archfx/FPGA_depthMap/blob/master/Python_test_implementation/Disparity_Python_implementation_scratch.ipynb)
58 |
59 | Test images used
60 | For the functional verification, I have used the most famous stereo image pair "Tsukuba" stereo pair
61 |
62 |
63 |
64 |
65 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
81 |
90 |
91 |
92 | Disparity generation Flow chart 93 |
94 | 95 | 96 | Then this algorithm is directly ported to Verilog. The implementation was done using ISE design suite by Xilinx. The image files were converted to hex and imported to the simulation and the output is directly saved as a Bitmap image. 97 | 98 | 99 |
100 |
101 |
102 | Timing diagrams at 50MHz 103 |
104 | 105 | 106 |
107 |
108 |
109 | Simulation Output 110 |
111 | 112 | 113 | *** these modules are only for simulation purposes, Do not synthesize the code. 114 | 115 | 116 | ## Stereo Camera implementation 117 | 118 | The cameras that were used for this project is very inexpensive OV7670 modules. They are commonly available and the output can be configured to 8bit parallel. 119 | These cameras are using I2C interface to communicate with the master. We can configure the camera output by changing the internal registers of the cameras. 120 |
121 |
122 |
123 | Pmod connections with Cameras 124 |
125 | 126 |
127 |
128 |
129 | Pmod connector pinouts 130 |
131 | 132 |
133 |
134 |
135 | Basys3 Pmod pinout diagram 136 |
137 | 138 | This repo contains VHDL implementation for image read from two cameras and displaying the average of two images from the VGA output. 139 | 140 | OV7670 dual camera mount was designed using a cad tool and 3D printed to mount the cameras. STL files for camera mount can be found from [here](https://github.com/Archfx/FPGA-stereo-Camera-Basys3/tree/master/CamMountCAD). 141 |
142 |
143 |
144 | CAD Stereo camera mount 145 |
146 | 147 |
148 |
149 |
150 | Hardware connected together 151 |
152 | 153 | 154 | **Camera configuration** 155 | 156 | OV7670 camera module comes with I2C interface to configure it's internal registers. The problem here is we are using two cameras with the same type. By taking the advantage of paralel hardware implementation on FPGA two seperate I2C buses were used for the dual camera intergration. Fortunatly prioir work related to OV7670 Camera intergration to Zedboard FPGA has been done by the Engineer [Mike Field](https://github.com/hamsternz) at [here](http://hamsterworks.co.nz/mediawiki/index.php/OV7670_camera). 157 | This I2C driver was direcly ported to the Basys3 FPGA. Camera register configuration was done inorder to get required output from the Camera. 158 | 159 | ## Real-time depth map generation on FPGA 160 | 161 | When converting the functional verification module into synthesizable code due to limited functionalities in Verilog, VHDL was selected as the developing language. 162 | 163 | **Resource Utilization** 164 | 165 | Basys 3 is a entry level FPGA board. Hence it is not designed for image processing tasks. The Challange here was to run complex image processing algorithm on limited resources. Basys 3 Trainer FPGA board consists of following resources. 166 | 167 |Resource | 170 |Available | 171 |
---|---|
LUT |
174 | 20800 | 175 |
LUTRAM | 178 |9600 | 179 |
FF | 182 |41600 | 183 |
BRAM | 186 |50 | 187 |
DSP | 190 |90 | 191 |
IO | 194 |106 | 195 |
BUFG | 198 |32 | 199 |
MMCM | 202 |5 | 203 |
218 |
219 |
220 | LUT bottleneck for 160x120 resolution 221 |
222 | 223 | 224 | Therefore a blockwise disparity calculation was used in order to utilize the full 320x240 resolution with available resources. The caching is done in block wise and then the caculated dispairty values are saved to the disparity_buffer circuit. 225 | 226 | ```diff 227 | - Although there are 9600 LUTRAMS are available we cannot ulilize 100% of that due to routing issues. 228 | 229 | ``` 230 |
231 |
232 |
233 | Routing failure 234 |
235 | 236 |
237 |
238 |
239 | Blockwise disparity calculation Utilization at 320x240 resolution 240 |
241 | 242 | 243 | **VGA Output** 244 | 245 | The system outputs the generated disparity map using the VGA output of the FPGA. 246 | Following are recorded output from the monitor using a camera. 247 | 248 |
249 |
250 |
251 | Demo -1 252 |
253 | 254 | 255 |
256 |
257 |
258 | Demo -2 259 |
260 | 261 | 262 | In both the demonstrations you may observe that camera exposure changes with the environement changes. Improvements are needed to fix this. It will reduce the noise in the output. 263 | Auto Exposure Correction (AEC) has been disabled from the cameras by editing the internal register modules. After disableing AEC, the result was much more clear and the noise was removed from the background. 264 | 265 | **Image Rectification and Camera Caliberation** 266 | 267 | The offsets of the two cameras are fixed using a image rectification module. Although the Automatic Exposure Caliberation is turned of one of the Cameras output is very darker while the other one is too bright. This should be corrected for the Disparity aldorithm to work correctly. 268 | 269 |
270 |
271 |
272 | Demo -3 ( Left : Disparity output | Right : average image of two cameras ) 273 |
274 | 275 | If we observe closely left camera brightness is too lower than the right hand side camera. 276 | 277 | After caliberation of exposure in cameras individually and improving the Image rectification module final output was in a good condition. There are noice and miss calculated points due to the inability of the cameras to identify the features correctly. But the output is smooth and clear. 278 | 279 |
280 |
281 |
282 | Demo -4 ( Left : Disparity output | Right : average image of two cameras ) 283 |
284 | 285 | 286 |
287 |
288 |
289 | Optimized system demo ( Left : Disparity output | Right : average image of two cameras ) 290 |
291 | 292 | 293 | 294 | 295 | -------------------------------------------------------------------------------- /Tsukuba_output_3.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Tsukuba_output_3.bmp -------------------------------------------------------------------------------- /Tsukuba_output_5.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Tsukuba_output_5.bmp -------------------------------------------------------------------------------- /Tsukuba_output_7.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Archfx/FPGA_depthMap/e718aa9433c02baa277ddcdabe67d3d3c6d78a10/Tsukuba_output_7.bmp -------------------------------------------------------------------------------- /image_read.v: -------------------------------------------------------------------------------- 1 | /******************************************************************************/ 2 | /****************** Module for reading and processing image **************/ 3 | /******************************************************************************/ 4 | `include "parameter.v" // Include definition file 5 | module image_read 6 | #( 7 | parameter WIDTH = 320, // Image width 8 | HEIGHT = 240, // Image height 9 | INFILE_L = "Tsukuba_L.hex", // image file 10 | INFILE_R = "Tsukuba_R.hex", // image file 11 | START_UP_DELAY = 100, // Delay during start up time 12 | HSYNC_DELAY = 160, // Delay between HSYNC pulses 13 | VALUE= 100, // value for Brightness operation 14 | THRESHOLD= 90, // Threshold value for Threshold operation 15 | SIGN=0 // Sign value using for brightness operation 16 | // SIGN = 0: Brightness subtraction 17 | // SIGN = 1: Brightness addition 18 | ) 19 | ( 20 | input HCLK, // clock 21 | input HRESETn, // Reset (active low) 22 | output VSYNC, // Vertical synchronous pulse 23 | // This signal is often a way to indicate that one entire image is transmitted. 24 | // Just create and is not used, will be used once a video or many images are transmitted. 25 | output reg HSYNC, // Horizontal synchronous pulse 26 | // An HSYNC indicates that one line of the image is transmitted. 27 | // Used to be a horizontal synchronous signals for writing bmp file. 28 | output reg [7:0] DATA_0_L, // 8 bit Red data (even) 29 | output reg [7:0] DATA_1_L, // 8 bit Green data (even) 30 | output reg [7:0] DATA_0_R, // 8 bit Blue data (even) 31 | output reg [7:0] DATA_1_R, // 8 bit Red data (odd) 32 | // Process and transmit 2 pixels in parallel to make the process faster, you can modify to transmit 1 pixels or more if needed 33 | output ctrl_done // Done flag 34 | ); 35 | //------------------------------------------------- 36 | // Internal Signals 37 | //------------------------------------------------- 38 | 39 | parameter sizeOfWidth = 8; // data width 40 | parameter sizeOfLengthReal = 76800; // image data : 1179648 bytes: 512 * 768 *3 41 | // local parameters for FSM 42 | localparam ST_IDLE = 2'b00, // idle state 43 | ST_VSYNC = 2'b01, // state for creating vsync 44 | ST_HSYNC = 2'b10, // state for creating hsync 45 | ST_DATA = 2'b11; // state for data processing 46 | reg [1:0] cstate, // current state 47 | nstate; // next state 48 | reg start; // start signal: trigger Finite state machine beginning to operate 49 | reg HRESETn_d; // delayed reset signal: use to create start signal 50 | reg ctrl_vsync_run; // control signal for vsync counter 51 | reg [8:0] ctrl_vsync_cnt; // counter for vsync 52 | reg ctrl_hsync_run; // control signal for hsync counter 53 | reg [8:0] ctrl_hsync_cnt; // counter for hsync 54 | reg ctrl_data_run; // control signal for data processing 55 | reg [31 : 0] in_memory [0 : sizeOfLengthReal/4]; // memory to store 32-bit data image 56 | reg [7 : 0] total_memory_L [0 : sizeOfLengthReal-1]; // memory to store 8-bit data image 57 | reg [7 : 0] total_memory_R [0 : sizeOfLengthReal-1]; // memory to store 8-bit data image 58 | // temporary memory to save image data : size will be WIDTH*HEIGHT*3 59 | integer temp_BMP_L [0 : WIDTH*HEIGHT - 1]; 60 | integer temp_BMP_R [0 : WIDTH*HEIGHT - 1]; 61 | integer org_L[0 : WIDTH*HEIGHT - 1]; // temporary storage for R component 62 | integer org_R [0 : WIDTH*HEIGHT - 1]; // temporary storage for G component 63 | //integer org_B [0 : WIDTH*HEIGHT - 1]; // temporary storage for B component 64 | // counting variables 65 | integer i, j; 66 | // temporary signals for calculation: details in the paper. 67 | integer temp0,temp1;//,tempG0,tempG1,tempB0,tempB1; // temporary variables in contrast and brightness operation 68 | 69 | integer value,value1,value2,value4;// temporary variables in invert and threshold operation 70 | reg [ 8:0] row; // row index of the image 71 | reg [8:0] col; // column index of the Left image 72 | integer window = 7; 73 | integer x,y; // column index of the Right image 74 | reg [4:0] offset, best_offset, best_offset_1; 75 | localparam [4:0] maxoffset = 10; // Maximum extent where to look for the same pixel 76 | reg offsetfound; 77 | reg offsetping; 78 | reg compare,SSD_calc; 79 | reg [20:0] ssd, ssd_1; // sum of squared difference 80 | reg [20:0] prev_ssd, prev_ssd_1; 81 | reg [18:0] data_count; // data counting for entire pixels of the image 82 | //-------------------------------------------------// 83 | // -------- Reading data from input file ----------// 84 | //-------------------------------------------------// 85 | initial begin 86 | $readmemh(INFILE_L,total_memory_L,0,sizeOfLengthReal-1); // read file from INFILE 87 | $readmemh(INFILE_R,total_memory_R,0,sizeOfLengthReal-1); // read file from INFILE 88 | end 89 | // use 3 intermediate signals RGB to save image data 90 | always@(start) begin 91 | if(start == 1'b1) begin 92 | for(i=0; i