00001
00002 package require image
00003 package require model3d
00004
00005 namespace eval stereo {
00006 00007 00008 00009
00010 proc rectification { {image_dir "/home/ayman/images/dala/indoor/serie08/"}
00011 {image_name "image.059"}
00012 {type_rectification 1}
00013 {rectified_suffix "_rec"}
00014 {filtrage 0}
00015 {type_interpolation 1}
00016 {window_size 11}
00017 {i_min 0.0}
00018 {i_max 1.0}
00019 {j_min 0.0}
00020 {j_max 1.0}
00021 {do_display true}
00022 {delcorrelimages true}
00023 {debayer false}
00024 {parameter_file "param.stereo"}
00025 } {
00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052
00053
00054 00055 set oldPath [pwd]
00056 cd $image_dir
00057
00058
00059 00060 set param_stereo_file "${image_dir}/${parameter_file}"
00061 set calibrageMatrices [::stereo::new_CalibrageMatrices]
00062 ::stereo::CalibrageMatrices_readFromFile $calibrageMatrices \
00063 $param_stereo_file
00064
00065 00066 00067 00068
00069 00070 if { [file exists $image_dir/$image_name.d] } then {
00071 set separateur "."
00072 set extension ""
00073 } elseif { [file exists $image_dir/$image_name.d.gz] } then {
00074 set separateur "."
00075 set extension ".gz"
00076 } elseif { [file exists $image_dir/$image_name.d.Z] } then {
00077 set separateur "."
00078 set extension ""
00079 } elseif { [file exists $image_dir/$image_name.d.tif] } then {
00080 set separateur "."
00081 set extension ".tif"
00082 } elseif { [file exists $image_dir/$image_name.d.tif.gz] } then {
00083 set separateur "."
00084 set extension ".tif.gz"
00085 } elseif { [file exists $image_dir/$image_name.d.tiff] } then {
00086 set separateur "."
00087 set extension ".tiff"
00088 } elseif { [file exists $image_dir/$image_name.d.tiff.gz] } then {
00089 set separateur "."
00090 set extension ".tiff.gz"
00091 } elseif { [file exists $image_dir/$image_name.d.ras] } then {
00092 set separateur "."
00093 set extension ".ras"
00094 } elseif { [file exists $image_dir/$image_name.d.ras.gz] } then {
00095 set separateur "."
00096 set extension ".ras.gz"
00097 } elseif { [file exists $image_dir/$image_name-d] } then {
00098 set separateur "-"
00099 set extension ""
00100 } elseif { [file exists $image_dir/$image_name-d.gz] } then {
00101 set separateur "-"
00102 set extension ".gz"
00103 } elseif { [file exists $image_dir/$image_name.d.Z] } then {
00104 set separateur "."
00105 set extension ".Z"
00106 } elseif { [file exists $image_dir/$image_name.d.jpeg] } then {
00107 set separateur "."
00108 set extension ".jpeg"
00109 } elseif { [file exists $image_dir/$image_name-d.tif] } then {
00110 set separateur "-"
00111 set extension ".tif"
00112 } elseif { [file exists $image_dir/$image_name-d.tif.gz] } then {
00113 set separateur "-"
00114 set extension ".tif.gz"
00115 } elseif { [file exists $image_dir/$image_name-d.ras] } then {
00116 set separateur "-"
00117 set extension ".ras"
00118 } elseif { [file exists $image_dir/$image_name-d.ras.gz] } then {
00119 set separateur "-"
00120 set extension ".ras.gz"
00121 } elseif { [file exists $image_dir/${image_name}_d] } then {
00122 set separateur "_"
00123 set extension ""
00124 } elseif { [file exists $image_dir/${image_name}_d.gz] } then {
00125 set separateur "_"
00126 set extension ".gz"
00127 } elseif { [file exists $image_dir/$image_name.d.Z] } then {
00128 set separateur "."
00129 set extension ".Z"
00130 } elseif { [file exists $image_dir/${image_name}_d.tif] } then {
00131 set separateur "_"
00132 set extension ".tif"
00133 } elseif { [file exists $image_dir/${image_name}_d.tif.gz] } then {
00134 set separateur "_"
00135 set extension ".tif.gz"
00136 } elseif { [file exists $image_dir/${image_name}_d.ras] } then {
00137 set separateur "_"
00138 set extension ".ras"
00139 } elseif { [file exists $image_dir/${image_name}_d.ras.gz] } then {
00140 set separateur "_"
00141 set extension ".ras.gz"
00142 } else {
00143 puts "images files not found"
00144 return
00145 }
00146
00147 00148 set img_file_name_g ${image_dir}${image_name}${separateur}g$extension
00149 set img_file_name_d ${image_dir}${image_name}${separateur}d$extension
00150
00151 00152 set img_red_file_name_g ${image_dir}${image_name}${separateur}g${rectified_suffix}.jpg
00153 set img_red_file_name_d ${image_dir}${image_name}${separateur}d${rectified_suffix}.jpg
00154
00155 puts "loading of image : $img_file_name_g"
00156 set source_image_left [image::Image_loadImage $img_file_name_g]
00157
00158 puts "loading of image : $img_file_name_d"
00159 set source_image_right [image::Image_loadImage $img_file_name_d]
00160
00161
00162 if { $debayer } {
00163 set interm [image::new_Image [$source_image_left width] \
00164 [$source_image_left height] \
00165 [$source_image_left depth] 3]
00166 image::Image_convertColorMode $source_image_left $interm \
00167 $::image::Image_bayerRG2bgr
00168 image::Image_convertColorMode $interm $source_image_left \
00169 $::image::Image_rgb2grey
00170 image::Image_convertColorMode $source_image_right $interm \
00171 $::image::Image_bayerRG2bgr
00172 image::Image_convertColorMode $interm $source_image_right \
00173 $::image::Image_rgb2grey
00174 image::delete_Image $interm
00175 }
00176
00177
00178
00179 set LEFT_IMAGE_ID 0
00180 set RIGHT_IMAGE_ID 1
00181
00182 00183 00184 00185 set do_reduction 1;
00186
00187 00188 00189 00190 set type_reduction 1;
00191
00192
00193 00194 00195 00196 set do_interpolation 1;
00197
00198 00199 00200 00201 00202 00203 00204 00205 00206 set distorsion_type 2;
00207
00208 00209
00210 set disp_min -200;
00211
00212 00213 00214 00215 00216 00217 00218 00219 00220 set type_census 4;
00221
00222 00223 if {$filtrage == 1} {
00224 set size_low 3;
00225 set size_high 7;
00226 set coefficient 2;
00227 }
00228
00229 set th_sigma 1.0; 00230 set th_score 0.0; 00231 set th_delta 0.0; 00232 set th_voisins 0.0; 00233 set espilon_inverse 1; 00234 00235
00236
00237 00238 00239 00240 00241 00242 00243 00244 00245 00246
00247 00248 if { $do_display } {
00249 ::display::show $source_image_left "image source gauche"
00250 #::display::show $source_image_right "image source droite"
00251 }
00252
00253
00254 00255 00256 set nbcol [::image::CvImage_width $source_image_left]
00257 set nblig [::image::CvImage_height $source_image_left]
00258
00259
00260 00261 set images_sizes [::stereo::new_ImagesSizes]
00262 ::stereo::ImagesSizes_initialize $images_sizes \
00263 $nblig $nbcol 1 1 \
00264 $i_min $i_max $j_min $j_max
00265
00266
00267
00268
00269 00270 ::stereo::ImagesSizes_initialize $images_sizes $calibrageMatrices
00271
00272
00273
00274 00275 set images_tmp_g [::stereo::new_ImagesTemporary]
00276 ::stereo::ImagesTemporary_initialize $images_tmp_g $images_sizes
00277
00278 set images_tmp_d [::stereo::new_ImagesTemporary]
00279 ::stereo::ImagesTemporary_initialize $images_tmp_d $images_sizes
00280
00281 set rectif_params_droite [::stereo::new_RectificationParams]
00282 ::stereo::RectificationParams_initialize $rectif_params_droite \
00283 $images_sizes $calibrageMatrices $RIGHT_IMAGE_ID
00284
00285
00286 set rectif_params_gauche [::stereo::new_RectificationParams]
00287 ::stereo::RectificationParams_initialize $rectif_params_gauche \
00288 $images_sizes $calibrageMatrices $LEFT_IMAGE_ID
00289
00290
00291 00292 if {$type_rectification == 2} {
00293 ::stereo::RectificationParams_initializeTables_michel \
00294 $rectif_params_gauche $distorsion_type
00295 ::stereo::RectificationParams_initializeTables_michel \
00296 $rectif_params_droite $distorsion_type
00297 }
00298
00299
00300
00301 00302 00303 00304 00305 set nRectifiedImageWidth \
00306 [::stereo::ImagesSizes_getRectifiedImageWidth $images_sizes]
00307 set nRectifiedImageHeight \
00308 [::stereo::ImagesSizes_getRectifiedImageHeight $images_sizes]
00309 set img_depth $::image::IPL_DEPTH_8U
00310 set color_space $::image::JfrImage_CS_GRAY
00311
00312 set im_reduite_gauche [::image::new_Image \
00313 $nRectifiedImageWidth \
00314 $nRectifiedImageHeight\
00315 $img_depth \
00316 $color_space]
00317
00318
00319 set im_reduite_droite [::image::new_Image \
00320 $nRectifiedImageWidth \
00321 $nRectifiedImageHeight\
00322 $img_depth \
00323 $color_space]
00324
00325
00326 ::stereo::jfrRectification $source_image_left $im_reduite_gauche \
00327 $images_sizes $rectif_params_gauche \
00328 $do_reduction $type_rectification\
00329 $distorsion_type $do_interpolation
00330
00331
00332 ::stereo::jfrRectification $source_image_right $im_reduite_droite \
00333 $images_sizes $rectif_params_droite \
00334 $do_reduction $type_rectification\
00335 $distorsion_type $do_interpolation
00336
00337 00338 if { $do_display } {
00339 ::display::show $im_reduite_gauche "image reduite gauche"
00340 ::display::show $im_reduite_droite "image reduite droite"
00341 }
00342
00343
00344 puts "save reduced image to file $img_red_file_name_g"
00345 puts "save reduced image to file $img_red_file_name_d"
00346 image::Image_saveImage $im_reduite_gauche $img_red_file_name_g
00347 image::Image_saveImage $im_reduite_droite $img_red_file_name_d
00348
00349
00350 ::stereo::delete_CalibrageMatrices $calibrageMatrices
00351 ::image::delete_Image $source_image_left
00352 ::image::delete_Image $source_image_right
00353
00354
00355 00356 ::stereo::delete_ImagesSizes $images_sizes
00357 00358 ::stereo::delete_ImagesTemporary $images_tmp_g
00359 ::stereo::delete_ImagesTemporary $images_tmp_d
00360 ::stereo::delete_RectificationParams $rectif_params_droite
00361 ::stereo::delete_RectificationParams $rectif_params_gauche
00362
00363 if { $delcorrelimages} {
00364 ::image::delete_Image $im_reduite_gauche
00365 ::image::delete_Image $im_reduite_droite
00366 }
00367
00368
00369 00370 cd $oldPath
00371
00372 }00373
00374 }00375
00376 package provide stereo 0.1