00001
00002 package require image
00003 package require model3d
00004
00005 namespace eval stereo {
00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020
00021
00022 proc stereo_correlation_old {
00023 imageDir
00024 nom_image
00025 {taux_reduction 2}
00026 {type_rectification 1}
00027 {filtrage 0}
00028 {type_correlation 2}
00029 {window_size 13}
00030 {i_min 0.0}
00031 {i_max 1.0}
00032 {j_min 0.0}
00033 {j_max 1.0}
00034 {dodisplay true}
00035 {delcorrelimages true}
00036 {debayer false}
00037 } {
00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081
00082 set oldPath [pwd]
00083 cd $imageDir
00084
00085
00086 00087 set param_stereo_file "$imageDir/vecteurs/"
00088 set calibrageMatrices [::stereo::new_CalibrageMatrices]
00089 ::stereo::CalibrageMatrices_readFromOldFile $calibrageMatrices \
00090 $param_stereo_file
00091
00092 00093 00094 00095 00096 if { [file exists $imageDir/$nom_image.d] } then {
00097 set separateur "."
00098 set extension ""
00099 } elseif { [file exists $imageDir/$nom_image.d.gz] } then {
00100 set separateur "."
00101 set extension ".gz"
00102 } elseif { [file exists $imageDir/$nom_image.d.Z] } then {
00103 set separateur "."
00104 set extension ""
00105 } elseif { [file exists $imageDir/$nom_image.d.tif] } then {
00106 set separateur "."
00107 set extension ".tif"
00108 } elseif { [file exists $imageDir/$nom_image.d.tif.gz] } then {
00109 set separateur "."
00110 set extension ".tif.gz"
00111 } elseif { [file exists $imageDir/$nom_image.d.tiff] } then {
00112 set separateur "."
00113 set extension ".tiff"
00114 } elseif { [file exists $imageDir/$nom_image.d.tiff.gz] } then {
00115 set separateur "."
00116 set extension ".tiff.gz"
00117 } elseif { [file exists $imageDir/$nom_image.d.ras] } then {
00118 set separateur "."
00119 set extension ".ras"
00120 } elseif { [file exists $imageDir/$nom_image.d.ras.gz] } then {
00121 set separateur "."
00122 set extension ".ras.gz"
00123 } elseif { [file exists $imageDir/$nom_image-d] } then {
00124 set separateur "-"
00125 set extension ""
00126 } elseif { [file exists $imageDir/$nom_image-d.gz] } then {
00127 set separateur "-"
00128 set extension ".gz"
00129 } elseif { [file exists $imageDir/$nom_image.d.Z] } then {
00130 set separateur "."
00131 set extension ".Z"
00132 } elseif { [file exists $imageDir/$nom_image.d.jpeg] } then {
00133 set separateur "."
00134 set extension ".jpeg"
00135 } elseif { [file exists $imageDir/$nom_image-d.tif] } then {
00136 set separateur "-"
00137 set extension ".tif"
00138 } elseif { [file exists $imageDir/$nom_image-d.tif.gz] } then {
00139 set separateur "-"
00140 set extension ".tif.gz"
00141 } elseif { [file exists $imageDir/$nom_image-d.ras] } then {
00142 set separateur "-"
00143 set extension ".ras"
00144 } elseif { [file exists $imageDir/$nom_image-d.ras.gz] } then {
00145 set separateur "-"
00146 set extension ".ras.gz"
00147 } elseif { [file exists $imageDir/${nom_image}_d] } then {
00148 set separateur "_"
00149 set extension ""
00150 } elseif { [file exists $imageDir/${nom_image}_d.gz] } then {
00151 set separateur "_"
00152 set extension ".gz"
00153 } elseif { [file exists $imageDir/$nom_image.d.Z] } then {
00154 set separateur "."
00155 set extension ".Z"
00156 } elseif { [file exists $imageDir/${nom_image}_d.tif] } then {
00157 set separateur "_"
00158 set extension ".tif"
00159 } elseif { [file exists $imageDir/${nom_image}_d.tif.gz] } then {
00160 set separateur "_"
00161 set extension ".tif.gz"
00162 } elseif { [file exists $imageDir/${nom_image}_d.ras] } then {
00163 set separateur "_"
00164 set extension ".ras"
00165 } elseif { [file exists $imageDir/${nom_image}_d.ras.gz] } then {
00166 set separateur "_"
00167 set extension ".ras.gz"
00168 } elseif { [file exists $imageDir/${nom_image}.d.ppm] } then {
00169 set separateur "."
00170 set extension ".ppm"
00171 } else {
00172 puts "Fichiers image non trouvs!!"
00173 return
00174 }
00175
00176 set source_image_gauche [image::Image_loadImage \
00177 ${imageDir}${nom_image}${separateur}g$extension]
00178 set source_image_droite [image::Image_loadImage \
00179 ${imageDir}${nom_image}${separateur}d$extension]
00180 if { $debayer } {
00181 set interm [image::new_Image [$source_image_gauche width] [$source_image_gauche height] [$source_image_gauche depth] 3]
00182 image::Image_convertColorMode $source_image_gauche $interm $::image::Image_bayerRG2bgr
00183 image::Image_convertColorMode $interm $source_image_gauche $::image::Image_rgb2grey
00184 image::Image_convertColorMode $source_image_droite $interm $::image::Image_bayerRG2bgr
00185 image::Image_convertColorMode $interm $source_image_droite $::image::Image_rgb2grey
00186 image::delete_Image $interm
00187
00188 }
00189 00190 00191
00192 set im3d [_stereo_correlation_old $source_image_gauche $source_image_droite $calibrageMatrices \
00193 $taux_reduction $type_rectification $filtrage $type_correlation $window_size \
00194 $i_min $i_max $j_min $j_max $dodisplay $delcorrelimages ]
00195
00196 ::stereo::delete_CalibrageMatrices $calibrageMatrices
00197 ::image::delete_Image $source_image_gauche
00198 ::image::delete_Image $source_image_droite
00199 cd $oldPath
00200 return $im3d
00201 }00202
00203
00204 proc _stereo_correlation_old {
00205 { source_image_gauche }
00206 { source_image_droite }
00207 { calibrageMatrices }
00208 {taux_reduction 1}
00209 {type_rectification 1}
00210 {filtrage 0}
00211 {type_correlation 2}
00212 {window_size 13}
00213 {i_min 0.0}
00214 {i_max 1.0}
00215 {j_min 0.0}
00216 {j_max 1.0}
00217 {dodisplay true}
00218 {delcorrelimages true}
00219 } {
00220
00221 00222 00223 00224
00225 00226 00227
00228 00229 00230 00231 00232
00233 set LEFT_IMAGE_ID 0
00234 set RIGHT_IMAGE_ID 1
00235
00236 00237 00238 00239 set reduction 1;
00240
00241 00242 00243 00244 set type_reduction 1;
00245
00246
00247 00248 00249 00250 set interpolation 1;
00251
00252 00253 00254 00255 00256 00257 00258 00259 set distorsion 2;
00260
00261 00262
00263 set disp_min -340;
00264
00265 set type_census 4; 00266
00267 00268 00269 00270 set blob_filtre 1;
00271
00272
00273 00274 00275 00276 set type_repere 0;
00277
00278
00279 00280 if {$filtrage == 1} {
00281 set size_low 3;
00282 set size_high 7;
00283 set coefficient 2;
00284 }
00285
00286 set th_sigma 1.0; 00287 set th_score 0.; 00288 set th_delta 0.0; 00289 set th_voisins 0.0; 00290 set espilon_inverse 1; 00291 00292
00293
00294 00295 00296 global im_reduite_gauche
00297 00298 00299 global im_reduite_droite
00300 00301 00302 00303 00304 global correlation_results
00305
00306
00307
00308 00309 if { $dodisplay } {
00310 ::display::show $source_image_gauche "image source gauche"
00311 # ::display::show $source_image_droite "image source droite"
00312 }
00313
00314
00315 00316 00317 set nbcol [::image::CvImage_width $source_image_gauche]
00318 set nblig [::image::CvImage_height $source_image_gauche]
00319
00320
00321 00322 set images_sizes [::stereo::new_ImagesSizes]
00323 ::stereo::ImagesSizes_initialize $images_sizes \
00324 $nblig $nbcol $taux_reduction $taux_reduction \
00325 $i_min $i_max $j_min $j_max
00326
00327
00328 00329 set correlation_params [::stereo::new_CorrelationParams]
00330 ::stereo::CorrelationParams_initialize $correlation_params \
00331 $type_correlation 1 $window_size $window_size \
00332 $disp_min 0 \
00333 $th_sigma $th_score $th_delta $th_voisins \
00334 $espilon_inverse
00335
00336 00337
00338 00339 set correlation_results [::stereo::new_CorrelationResults]
00340 ::stereo::CorrelationResults_initialize $correlation_results \
00341 $images_sizes $correlation_params
00342
00343 00344
00345
00346 00347 set images_tmp_g [::stereo::new_ImagesTemporary]
00348 ::stereo::ImagesTemporary_initialize $images_tmp_g $images_sizes
00349
00350 00351
00352 set images_tmp_d [::stereo::new_ImagesTemporary]
00353 ::stereo::ImagesTemporary_initialize $images_tmp_d $images_sizes
00354
00355 00356
00357
00358
00359 set rectif_params_droite [::stereo::new_RectificationParams]
00360 ::stereo::RectificationParams_initialize $rectif_params_droite \
00361 $images_sizes $calibrageMatrices $RIGHT_IMAGE_ID
00362
00363
00364
00365 set rectif_params_gauche [::stereo::new_RectificationParams]
00366 ::stereo::RectificationParams_initialize $rectif_params_gauche \
00367 $images_sizes $calibrageMatrices $LEFT_IMAGE_ID
00368
00369
00370
00371
00372 00373 if {$type_rectification == 2} {
00374 ::stereo::RectificationParams_initializeTables_michel \
00375 $rectif_params_gauche $distorsion
00376 ::stereo::RectificationParams_initializeTables_michel \
00377 $rectif_params_droite $distorsion
00378 }
00379
00380
00381 00382 set reconstruction_params [::stereo::new_ReconstructionParams]
00383 ::stereo::ReconstructionParams_initialize $reconstruction_params $calibrageMatrices
00384 00385
00386
00387
00388 00389 00390 00391 00392 set nRectifiedImageWidth [::stereo::ImagesSizes_getRectifiedImageWidth $images_sizes]
00393 set nRectifiedImageHeight [::stereo::ImagesSizes_getRectifiedImageHeight $images_sizes]
00394 set img_depth $::image::IPL_DEPTH_8U
00395 set color_space $::image::JfrImage_CS_GRAY
00396
00397 set im_rectif_gauche [::image::new_Image \
00398 $nbcol \
00399 $nblig\
00400 $img_depth \
00401 $color_space]
00402
00403
00404 set im_rectif_droite [::image::new_Image \
00405 $nbcol \
00406 $nblig\
00407 $img_depth \
00408 $color_space]
00409
00410
00411 ::stereo::jfrRectification_old $source_image_gauche $im_rectif_gauche \
00412 $images_sizes $rectif_params_gauche \
00413 0 $type_rectification\
00414 $distorsion $interpolation
00415
00416
00417 ::stereo::jfrRectification_old $source_image_droite $im_rectif_droite \
00418 $images_sizes $rectif_params_droite \
00419 0 $type_rectification\
00420 $distorsion $interpolation
00421 00422 00423
00424 set im_reduite_gauche [::image::new_Image \
00425 $nRectifiedImageWidth \
00426 $nRectifiedImageHeight\
00427 $img_depth \
00428 $color_space]
00429 ::image::Image_resize $im_rectif_gauche $im_reduite_gauche
00430 00431 00432
00433 set im_reduite_droite [::image::new_Image \
00434 $nRectifiedImageWidth \
00435 $nRectifiedImageHeight\
00436 $img_depth \
00437 $color_space]
00438 ::image::Image_resize $im_rectif_droite $im_reduite_droite
00439 00440 00441
00442
00443 00444 if { $dodisplay } {
00445 ::display::show $im_reduite_gauche "image reduite gauche"
00446 # ::display::show $im_reduite_droite "image reduite droite"
00447 }
00448
00449
00450 00451 00452 if {$filtrage == 1} {
00453 ::stereo::laplacien_ima1 $im_reduite_gauche $images_tmp_g \
00454 $size_low $size_low $size_high $size_high $coefficient
00455 ::stereo::laplacien_ima1 $im_reduite_droite $images_tmp_d \
00456 $size_low $size_low $size_high $size_high $coefficient
00457 }
00458
00459
00460
00461 00462 00463 if { [expr {$type_correlation == 0} || {$type_correlation == 1}] } {
00464 # ZNCC: calcul des moyennes et sigmas
00465 ::stereo::jfrMoyennesSigmas $im_reduite_gauche \
00466 $images_tmp_g $correlation_params
00467 ::stereo::jfrMoyennesSigmas $im_reduite_droite \
00468 $images_tmp_d $correlation_params
00469 # set imagesigma_g [::stereo::getImageForSigmas $images_tmp_g ]
00470 # ::display::show $imagesigma_g
00471 # ::image::Image_saveImage $imagesigma_g "/home/cberger/im_sigmas_g.png"
00472 # set imagesigma_d [::stereo::getImageForSigmas $images_tmp_d ]
00473 # ::display::show $imagesigma_d
00474 # ::image::Image_saveImage $imagesigma_d "/home/cberger/im_sigmas_d.png"
00475 # set imagemoyennes_g [::stereo::getImageForMoyennes $images_tmp_g ]
00476 # ::display::show $imagemoyennes_g
00477 # ::image::Image_saveImage $imagemoyennes_g "/home/cberger/im_moyennes_g.png"
00478 # set imagemoyennes_d [::stereo::getImageForMoyennes $images_tmp_d ]
00479 # ::display::show $imagemoyennes_d
00480 # ::image::Image_saveImage $imagemoyennes_d "/home/cberger/im_moyennes_d.png"
00481 } else { # Census
00482 if {[expr {$type_census == 3} || \
00483 {$type_census == 4} || \
00484 {$type_census == 5} || \
00485 {$type_census == 6}]} {
00486 # Il faut calculer l'images des moyennes
00487 ::stereo::jfrMoyennes $im_reduite_gauche 3 3 $images_tmp_g
00488 ::stereo::jfrMoyennes $im_reduite_droite 3 3 $images_tmp_d
00489 }
00490
00491 # Creation des images de Census
00492 set im_census_gauche [::image::Image im_census_gauche \
00493 $nRectifiedImageWidth \
00494 $nRectifiedImageHeight\
00495 $img_depth \
00496 $color_space]
00497
00498 set im_census_droite [::image::Image im_census_droite \
00499 $nRectifiedImageWidth \
00500 $nRectifiedImageHeight\
00501 $img_depth \
00502 $color_space]
00503
00504 ::stereo::jfrTransform_census_8bits \
00505 $im_reduite_gauche $images_tmp_g \
00506 $type_census $im_census_gauche
00507
00508 ::stereo::jfrTransform_census_8bits \
00509 $im_reduite_droite $images_tmp_d \
00510 $type_census $im_census_droite
00511 }
00512
00513
00514
00515
00516 00517 00518
00519 if {[expr {$type_correlation == 0} || {$type_correlation == 1}]} {
00520 # ZNCC
00521 ::stereo::jfrCorrelationZncc \
00522 $im_reduite_gauche $im_reduite_droite \
00523 $images_tmp_g $images_tmp_d \
00524 $correlation_params $correlation_results
00525 } else {
00526 # Census
00527 ::stereo::jfrCorrelationCensus \
00528 $im_census_gauche $im_census_droite \
00529 $images_sizes $correlation_params $correlation_results
00530 }
00531
00532
00533 00534 00535
00536
00537 00538 00539 if {$blob_filtre != 0} {
00540 ::stereo::jfrBlobFilterDisparites $correlation_results 500 1.0
00541 }
00542
00543
00544 00545 00546 00547
00548 set imDisp [::stereo::getImageForDisparity $correlation_results]
00549 display::show $imDisp "Disparites"
00550
00551 00552 00553 00554 00555 00556 00557
00558 00559 00560 00561 00562 00563
00564
00565 00566 00567 00568
00569 if {[expr {$type_correlation == 1} || {$type_correlation == 3}]} {
00570 set type_reconstruction 1
00571 } else { set type_reconstruction 0 }
00572
00573
00574 00575 00576 00577
00578 00579 00580
00581 set im3d [::model3d::Image3D]
00582 ::model3d::Image3D_initialize $im3d \
00583 $nRectifiedImageWidth $nRectifiedImageHeight
00584
00585
00586 ::stereo::jfrReconstruction3D $correlation_results \
00587 $images_sizes $type_repere \
00588 $type_reconstruction $reconstruction_params \
00589 $rectif_params_gauche $im3d
00590
00591
00592 ::model3d::Image3D_minMax $im3d
00593 00594 00595 00596
00597 00598
00599 00600 00601 00602 00603
00604 00605 ::stereo::delete_ImagesSizes $images_sizes
00606 00607 ::stereo::delete_CorrelationParams $correlation_params
00608 ::stereo::delete_CorrelationResults $correlation_results
00609 ::stereo::delete_ImagesTemporary $images_tmp_g
00610 ::stereo::delete_ImagesTemporary $images_tmp_d
00611 ::stereo::delete_RectificationParams $rectif_params_droite
00612 ::stereo::delete_RectificationParams $rectif_params_gauche
00613 ::stereo::delete_ReconstructionParams $reconstruction_params
00614 if { $delcorrelimages} {
00615 ::image::delete_Image $im_reduite_gauche
00616 ::image::delete_Image $im_reduite_droite
00617 }
00618
00619 00620
00621 return $im3d
00622 }00623
00624 }00625
00626 package provide stereo 0.1