1
1
"""
2
+ DESCRIPTION: ...
2
3
"""
3
4
4
5
import os
5
6
import sys
6
7
import subprocess
7
8
from pathlib import Path
8
9
import shutil
9
- import numpy as np
10
+ from datetime import datetime
10
11
import yaml
11
12
from util import utils
12
- from datetime import datetime
13
13
14
14
# define module under test, must be the same as defined in the config
15
- # DUT options = ['crop', 'dead_pixel_correction', 'hdr_stitching', 'black_level_correction', 'OECF', 'digital_gain', 'lens_shading_correction',
16
- # 'bayer_noise_reduction', 'white_balance', 'demosaic', 'auto_white_balance', 'color_correction_matrix', 'gamma_correction',
17
- # 'auto_exposure', 'color_space_conversion', 'ldci', 'sharpen', '2d_noise_reduction', 'scale', 'yuv_conversion_format']
15
+ # DUT options = ['crop', 'dead_pixel_correction', 'hdr_stitching', 'black_level_correction',
16
+ # 'OECF', 'digital_gain', 'lens_shading_correction','bayer_noise_reduction',
17
+ # 'auto_white_balance', 'white_balance', 'demosaic', 'color_correction_matrix',
18
+ # 'gamma_correction', 'auto_exposure', 'color_space_conversion', 'ldci', 'sharpen',
19
+ # '2d_noise_reduction', 'scale', 'yuv_conversion_format']
18
20
19
21
20
- DUT = ["dead_pixel_correction" , "black_level_correction" , "digital_gain" ]
22
+ DUT = ["dead_pixel_correction" ]
21
23
22
24
23
25
# Modules:
24
- CROP = {"isEnable" : False ,
25
- "new_width" : 1280 ,
26
- "new_height " : 720 }
26
+ CROP = {"isEnable" : False , "new_width" : 1280 , "new_height" : 720 }
27
+
28
+ DPC = { "isEnable" : True , "dp_threshold " : 80 }
27
29
28
- DPC = {"isEnable" : True ,
29
- "dp_threshold" : 80 }
30
-
31
30
32
31
HDR = {"isEnable" : False }
33
32
34
- BLC = {"isEnable" : True ,
35
- "isLinear" : True ,
36
- "r_offset" : 200 ,
37
- "gr_offset" : 200 ,
38
- "gb_offset" : 200 ,
39
- "b_offset" : 200 }
33
+ BLC = {
34
+ "isEnable" : False ,
35
+ "isLinear" : True ,
36
+ "r_offset" : 200 ,
37
+ "gr_offset" : 200 ,
38
+ "gb_offset" : 200 ,
39
+ "b_offset" : 200 ,
40
+ }
40
41
41
42
OECF = {"isEnable" : False }
42
- DG = {"is_save" : True }
43
+ DG = {"is_save" : False }
43
44
44
45
LSC = {"isEnable" : False }
45
46
46
- BNR = {"isEnable" : False ,
47
- "filt_window" : 9 }
47
+ BNR = {"isEnable" : False , "filt_window" : 9 }
48
48
49
- WB = {"isEnable" : False ,
50
- "isAuto " : False }
49
+ AWB = {"isEnable" : False }
50
+ WB = { "isEnable " : False }
51
51
DEM = {"is_save" : False }
52
- AWB = {}
53
52
CCM = {"isEnable" : False }
54
- GC = {"isEnable" : True }
53
+ GC = {"isEnable" : False }
55
54
AE = {"isEnable" : False }
56
55
57
56
CSC = {"is_save" : False }
58
- LDCI = {"isEnable" : True }
57
+ LDCI = {"isEnable" : False }
59
58
60
- SHARPEN = {"isEnable" : False }
59
+ SHARPEN = {"isEnable" : False }
61
60
NR2D = {"isEnable" : False }
62
61
63
- SCALE = {"isEnable" : False ,
64
- "isHardware" : True }
62
+ SCALE = {"isEnable" : False , "isHardware" : True }
65
63
66
- YUV = {"isEnable" : False ,
67
- "conv_type" : '444' }
64
+ YUV = {"isEnable" : False , "conv_type" : "444" }
68
65
69
66
# These modules are currently not a part of isp pipeline, but are included in config
70
67
# PRE_GAMMA = {"isEnable": False}
74
71
# define folder name to save outputs
75
72
folder_name = datetime .now ().strftime ("%Y%m%d_%H%M%S" )
76
73
77
- input_ext = ".raw"
74
+ INPUT_EXT = ".raw"
78
75
79
76
# Setting this flag to True saves yvu array
80
- swap_uv = True
77
+ SWAP_UV = False
81
78
82
79
# Set this flag to True if all input files need to be saved in a single folder
83
- in_single_folder = True
80
+ IN_SINGLE_FOLDER = True
84
81
85
82
# The path of the dataset
86
83
DATASET_PATH = "./in_frames/normal/data/"
87
84
88
85
# Parent folder for Images (Path is relative to ./in_frames/normal/)
89
- PARENT_FOLDER = DATASET_PATH .rsplit (' ./in_frames/normal/' , maxsplit = 1 )[- 1 ]
86
+ PARENT_FOLDER = DATASET_PATH .rsplit (" ./in_frames/normal/" , maxsplit = 1 )[- 1 ]
90
87
91
88
# The path of the default config file
92
89
CONFIG_PATH = "./config/configs.yml"
97
94
98
95
# load, update and resave config file according to above parameters
99
96
with open (CONFIG_PATH , "r" , encoding = "utf-8" ) as file :
100
- config = yaml .safe_load (file )
97
+ config = yaml .safe_load (file )
101
98
102
99
module_tags = list (config .keys ())[2 :]
103
- remove = ["swap_uv_channels" ,"pre_gamma" , "tone_mapping" , "jpeg_conversion" ]
100
+ remove = ["swap_uv_channels" , "pre_gamma" , "tone_mapping" , "jpeg_conversion" ]
104
101
[module_tags .remove (module ) for module in remove ]
105
102
106
103
# Set is_RTl to True to indicate that automation file is being executed
107
104
config ["sensor_info" ]["is_RTL" ] = True
108
105
109
106
# ensure that the modules are in same order as they are in the config file
110
- new_params = [CROP , DPC , HDR , BLC , OECF , DG , LSC , BNR , WB , DEM , AWB , CCM , GC , AE ,
111
- CSC , LDCI , SHARPEN , NR2D , SCALE , YUV ]
107
+ new_params = [
108
+ CROP ,
109
+ DPC ,
110
+ HDR ,
111
+ BLC ,
112
+ OECF ,
113
+ DG ,
114
+ LSC ,
115
+ BNR ,
116
+ AWB ,
117
+ WB ,
118
+ DEM ,
119
+ CCM ,
120
+ GC ,
121
+ AE ,
122
+ CSC ,
123
+ LDCI ,
124
+ SHARPEN ,
125
+ NR2D ,
126
+ SCALE ,
127
+ YUV ,
128
+ ]
112
129
113
130
default_modules = ["digital_gain" , "demosaic" , "color_space_conversion" ]
114
131
115
132
for idx , module in enumerate (module_tags ):
116
133
# save the input and output arrays of module under test with is_save flag
117
- try :
118
- if module in DUT or module_tags [idx + 1 ] in DUT :
119
- is_save = True
134
+ try :
135
+ if module in DUT or module_tags [idx + 1 ] in DUT :
136
+ IS_SAVE = True
120
137
elif module in default_modules :
121
138
122
- is_save = new_params [idx ]["is_save" ]
123
- else :
124
- is_save = False
125
-
139
+ IS_SAVE = new_params [idx ]["is_save" ]
140
+ else :
141
+ IS_SAVE = False
142
+
126
143
# update swap_uv flag to save yuv or yvu array
127
- if module in module_tags [module_tags .index ("color_space_conversion" ):] and is_save :
128
- config ["swap_uv_channels" ][str (module )] = swap_uv
144
+ if (
145
+ module in module_tags [module_tags .index ("color_space_conversion" ) :]
146
+ and IS_SAVE
147
+ ):
148
+ config ["swap_uv_channels" ][str (module )] = SWAP_UV
129
149
130
150
if module in DUT and module not in default_modules :
131
- assert new_params [idx ]["isEnable" ]== True , "DUT not enabled in this script."
132
-
133
- utils .update_config (config , module ,new_params [idx ].keys (), new_params [idx ].values (), is_save )
151
+ assert (
152
+ new_params [idx ]["isEnable" ] is True
153
+ ), "DUT not enabled in this script."
154
+
155
+ utils .update_config (
156
+ config , module , new_params [idx ].keys (), new_params [idx ].values (), IS_SAVE
157
+ )
134
158
except IndexError :
135
159
pass
136
160
137
- # Empty the Results folder in temp folder
161
+ # Empty the Results folder in temp folder
138
162
shutil .copytree ("./out_for_RTL/Results" , "./out_for_RTL/temp" )
139
163
shutil .rmtree ("./out_for_RTL/Results" )
140
164
os .mkdir ("./out_for_RTL/Results" )
141
165
142
166
# save the config file along with its results
143
167
yaml .add_representer (list , utils .represent_list )
144
168
145
- with open (f "./out_for_RTL/Results/configs_automate.yml" , "w" , encoding = "utf-8" ) as file :
169
+ with open ("./out_for_RTL/Results/configs_automate.yml" , "w" , encoding = "utf-8" ) as file :
146
170
yaml .dump (config , file , sort_keys = False , Dumper = utils .CustomDumper , width = 17000 )
147
171
148
172
# loop over images
157
181
for i , raw_filename in enumerate (RAW_FILENAMES ):
158
182
# update filename in config
159
183
config ["platform" ]["filename" ] = PARENT_FOLDER + raw_filename
160
-
184
+
161
185
# update the config file in cofig file
162
- with open (f "config/configs.yml" , "w" , encoding = "utf-8" ) as file :
186
+ with open ("config/configs.yml" , "w" , encoding = "utf-8" ) as file :
163
187
yaml .safe_dump (config , file , sort_keys = False , default_flow_style = False )
164
-
188
+
165
189
# direct standard output stream to a text file
166
- with open (f"./out_for_RTL/Results/{ folder_name } _isp_pipeline_log.txt" , "a" ) as text_file :
167
- subprocess .run ([sys .executable , "isp_pipeline.py" ], check = True , stdout = text_file , text = True )
190
+ with open (
191
+ f"./out_for_RTL/Results/{ folder_name } _isp_pipeline_log.txt" ,
192
+ "a" ,
193
+ encoding = "utf-8" ,
194
+ ) as text_file :
195
+ subprocess .run (
196
+ [sys .executable , "isp_pipeline.py" ], check = True , stdout = text_file , text = True
197
+ )
168
198
169
199
shutil .copy (RETAINED_CONFIG , CONFIG_PATH )
170
200
os .remove (RETAINED_CONFIG )
174
204
path = f"./out_for_RTL/{ folder_name } /"
175
205
176
206
if "crop" in DUT :
177
- utils .rename_for_RTL (path , "Inpipeline_crop_" )
207
+ utils .rename_for_rtl (path , "Inpipeline_crop_" )
178
208
else :
179
- input_module = module_tags [module_tags .index (DUT [0 ])- 1 ]
180
- utils .rename_for_RTL (path , "Out_" + input_module + "_" )
209
+ input_module = module_tags [module_tags .index (DUT [0 ]) - 1 ]
210
+ utils .rename_for_rtl (path , "Out_" + input_module + "_" )
181
211
182
- # restructure the directory
183
- utils .restructure_dir (path , in_single_folder , DUT [- 1 ])
212
+ # restructure the directory
213
+ utils .restructure_dir (path , IN_SINGLE_FOLDER , DUT [- 1 ])
184
214
185
215
186
216
# convert the saved numpy arrays to bin files as required by the RTL
187
- utils .get_RTL_input (path , in_single_folder , input_ext )
217
+ utils .get_rtl_input (path , IN_SINGLE_FOLDER , INPUT_EXT )
188
218
189
219
# place back the contents of the Results folder
190
220
shutil .copytree ("./out_for_RTL/temp" , "./out_for_RTL/Results" )
191
221
shutil .rmtree ("./out_for_RTL/temp" )
192
222
193
223
194
224
# with open(f"./out_for_RTL/{folder_name}/{folder_name}_comparison_log.txt", "a") as text_file:
195
- # subprocess.run([sys.executable, "compare_output.py"], stdout=text_file, text= True)
225
+ # subprocess.run([sys.executable, "compare_output.py"], stdout=text_file, text= True)
0 commit comments