00001 package require image
00002 package require model3d
00003 00004
00005
00006 00007 00008 00009 00010 00011 00012 00013 00014 00015
00016 namespace eval stereo {
00017 proc do_correlation_only { {image_dir "/home/ayman/images/dala/indoor/serie05/"}
00018 {image_name_left "image.037.g_rec.jpg"}
00019 {image_name_right "image.037.d_rec.jpg"}
00020 {type_correlation 1}
00021 {type_interpolation 1}
00022 {window_size 11}
00023 {i_min 0.0}
00024 {i_max 1.0}
00025 {j_min 0.0}
00026 {j_max 1.0}
00027 {do_display true}
00028 } {
00029
00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041
00042
00043 00044 set oldPath [pwd]
00045 cd $image_dir
00046
00047 set file_name_left "${image_dir}/${image_name_left}"
00048 set file_name_right "${image_dir}/${image_name_right}"
00049
00050 if { [file exists $file_name_left] } then {
00051 puts "opening file $file_name_left"
00052 } else {
00053 puts "file ${file_name_left} not found"
00054 return
00055 }
00056 if { [file exists $file_name_right]} then {
00057 puts "opening file $file_name_right"
00058 } else {
00059 puts "file ${file_name_right} not found"
00060 return
00061 }
00062
00063 set source_image_left [image::Image_loadImage \
00064 ${file_name_left}]
00065
00066 set source_image_right [image::Image_loadImage \
00067 ${file_name_right}]
00068
00069
00070 set disp_min -100;
00071 set disp_max 0;
00072
00073 00074 00075 00076 00077 00078 00079 00080 set type_census 4;
00081
00082 00083 00084 00085 set do_blob_filtre 1;
00086
00087 set th_filter_disparity1 500
00088 set th_filter_disparity2 1.0
00089
00090 set th_sigma 1.0; 00091 set th_score 0.5; 00092 set th_delta 0.05; 00093 set th_voisins 0.0; 00094 set espilon_inverse 1; 00095 00096
00097 00098 if { $do_display } {
00099 ::display::show $source_image_left "image source gauche"
00100 #::display::show $source_image_right "image source droite"
00101 }
00102
00103
00104 00105 00106 set nbcol [::image::CvImage_width $source_image_left]
00107 set nblig [::image::CvImage_height $source_image_left]
00108
00109
00110
00111 00112 set images_sizes [::stereo::new_ImagesSizes]
00113 ::stereo::ImagesSizes_initialize $images_sizes \
00114 $nblig $nbcol 1 1 \
00115 $i_min $i_max $j_min $j_max
00116
00117 ::stereo::ImagesSizes_info $images_sizes
00118
00119
00120 set nRectifiedImageWidth \
00121 [::stereo::ImagesSizes_getRectifiedImageWidth $images_sizes]
00122 set nRectifiedImageHeight \
00123 [::stereo::ImagesSizes_getRectifiedImageHeight $images_sizes]
00124 00125 00126
00127 set img_depth $::image::IPL_DEPTH_8U
00128 set color_space $::image::JfrImage_CS_GRAY
00129 set img_depth_2 [image::CvImage_depth $source_image_left]
00130 puts "img_depth == $img_depth img_depth_2 $img_depth_2"
00131 puts "====================================="
00132 puts "width = $nRectifiedImageWidth height= $nRectifiedImageHeight"
00133 puts "====================================="
00134 puts "====================================="
00135 puts "====================================="
00136
00137
00138 00139 set correlation_params [::stereo::new_CorrelationParams]
00140 ::stereo::CorrelationParams_initialize $correlation_params \
00141 $type_correlation $type_interpolation \
00142 $window_size $window_size $disp_min $disp_max \
00143 $th_sigma $th_score $th_delta $th_voisins \
00144 $espilon_inverse
00145
00146
00147 ::stereo::CorrelationParams_info $correlation_params
00148
00149 puts " "
00150 puts "nblig = $nblig"
00151 set ddd [stereo::ImagesSizes_nb_lig_final_get $images_sizes]
00152 puts "nblig ImagesSizes.nblig_rect $ddd"
00153
00154
00155
00156 00157 set correlation_results [::stereo::new_CorrelationResults]
00158 ::stereo::CorrelationResults_initialize $correlation_results \
00159 $images_sizes $correlation_params
00160
00161 ::stereo::CorrelationResults_info $correlation_results
00162
00163
00164 00165 set images_tmp_g [::stereo::new_ImagesTemporary]
00166 ::stereo::ImagesTemporary_initialize $images_tmp_g $images_sizes
00167
00168 set images_tmp_d [::stereo::new_ImagesTemporary]
00169 ::stereo::ImagesTemporary_initialize $images_tmp_d $images_sizes
00170
00171
00172
00173
00174 00175 00176 if { [expr {$type_correlation == 0} || {$type_correlation == 1}] } {
00177 # ZNCC: calcul des moyennes et sigmas
00178 ::stereo::jfrMoyennesSigmas $source_image_left \
00179 $images_tmp_g $correlation_params
00180 ::stereo::jfrMoyennesSigmas $source_image_right \
00181 $images_tmp_d $correlation_params
00182
00183 puts "ImagesTemporary information "
00184 puts "=============================================== "
00185 ::stereo::ImagesTemporary_info $images_tmp_g
00186 ::stereo::ImagesTemporary_info $images_tmp_d
00187 puts "=============================================== "
00188
00189 } else { # Census
00190 if {[expr {$type_census == 3} || \
00191 {$type_census == 4} || \
00192 {$type_census == 5} || \
00193 {$type_census == 6}]} {
00194 # Il faut calculer l'images des moyennes
00195 ::stereo::jfrMoyennes $source_image_left 3 3 $images_tmp_g
00196 ::stereo::jfrMoyennes $source_image_right 3 3 $images_tmp_d
00197 }
00198
00199
00200
00201 # Creation des images de Census
00202 set im_census_gauche [::image::new_Image \
00203 $nRectifiedImageWidth \
00204 $nRectifiedImageHeight\
00205 $img_depth \
00206 $color_space]
00207
00208 set im_census_droite [::image::new_Image \
00209 $nRectifiedImageWidth \
00210 $nRectifiedImageHeight\
00211 $img_depth \
00212 $color_space]
00213
00214 ::stereo::jfrTransform_census_8bits \
00215 $source_image_left $images_tmp_g \
00216 $type_census $im_census_gauche
00217
00218 ::stereo::jfrTransform_census_8bits \
00219 $source_image_right $images_tmp_d \
00220 $type_census $im_census_droite
00221
00222 display::show $im_census_gauche "census gauche"
00223
00224 }
00225
00226
00227
00228
00229 00230 00231
00232 if {[expr {$type_correlation == 0} || {$type_correlation == 1}]} {
00233 # ZNCC
00234 ::stereo::jfrCorrelationZncc \
00235 $source_image_left $source_image_right \
00236 $images_tmp_g $images_tmp_d \
00237 $correlation_params $correlation_results
00238 } else {
00239 # Census
00240 ::stereo::jfrCorrelationCensus \
00241 $im_census_gauche $im_census_droite \
00242 $images_sizes $correlation_params $correlation_results
00243 }
00244
00245
00246 00247 set im_disparity \
00248 [::stereo::CorrelationResults_getImageForDisparity \
00249 $correlation_results]
00250
00251 if { $do_display } {
00252 ::display::show $im_disparity "image of non filtered disparity "
00253 }
00254
00255 00256 00257 if {$do_blob_filtre != 0} {
00258 ::stereo::jfrBlobFilterDisparites $correlation_results \
00259 $th_filter_disparity1 $th_filter_disparity2
00260 }
00261
00262 00263 00264 set im_disparity_fltr \
00265 [::stereo::CorrelationResults_getImageForDisparity \
00266 $correlation_results]
00267
00268 if { $do_display } {
00269 ::display::show $im_disparity_fltr "image of filtered disparity "
00270 }
00271
00272 00273 set im_correlated_pixels \
00274 [::stereo::CorrelationResults_getImageOfCorrelatedPixels \
00275 $correlation_results $source_image_left]
00276 if { $do_display } {
00277 ::display::show $im_correlated_pixels "image of correlated pixels"
00278 }
00279
00280 00281 set im_regions \
00282 [::stereo::CorrelationResults_getImageForRegions \
00283 $correlation_results]
00284 if { $do_display } {
00285 # ::display::show $im_regions "image of regions"
00286 }
00287
00288
00289 00290 ::stereo::delete_ImagesSizes $images_sizes
00291 ::stereo::delete_CorrelationParams $correlation_params
00292 ::stereo::delete_CorrelationResults $correlation_results
00293 ::stereo::delete_ImagesTemporary $images_tmp_g
00294 ::stereo::delete_ImagesTemporary $images_tmp_d
00295
00296 ::image::delete_Image $im_correlated_pixels
00297 ::image::delete_Image $im_disparity
00298
00299 ::image::delete_Image $source_image_left
00300 ::image::delete_Image $source_image_right
00301
00302 00303 cd $oldPath
00304
00305 }00306 }00307
00308 package provide stereo 0.1