Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
rectification_old.tcl
00001 
00002 package require image
00003 package require stereo
00004 package require model3d
00005 
00006 namespace eval stereo {
00007 
00008     proc rectification_old { imageLeft
00009            imageRight
00010            vecteursDir
00011            {scale 1.0}
00012            {type_rectification 1}
00013            {debayer false}
00014        } {
00015   # This macro applies rectification to imageLeft and
00016   # imageRight. Input images must be full resolution, a scale
00017   # factor can be applied on the rectification result. The
00018   # rectified images are returned as a list {imageLeft_rect
00019   # imageRight_rect}
00020   #
00021   # Paramtres :
00022   #
00023   #        imageDir: le nom du repertoire dans lequel sont les images.
00024   #                   Quelques infos sur:
00025   #                   il DOIT y avoir un lien ou un sous-rpertoire 
00026   #                   'vecteurs' dans lequel se trouvent les matrices
00027   #                   de calibrage
00028   #
00029   #        nom_image: l'entte du nom des fichiers image, sans
00030   #                   l'extension
00031   #                   (voir commentaires ci dessus)
00032   #
00033   #
00034   #
00035   # Tous les paramtres qui suivent sont optionnels, il est conseill de
00036   # prendre leur valeur par dfaut ( moins de bien connatre les algos)
00037   #
00038   #
00039   #        type_rectification: 0 = pas de rectification
00040   #                            1 = rectification  partir des matrices
00041   #                            2 = rectification  partir des tables
00042   #                            3 = rectification "inverse"  
00043   #
00044   
00045   # Lecture des fichiers de calibrage
00046   set param_stereo_file "$vecteursDir/"  
00047   set calibrageMatrices  [::stereo::new_CalibrageMatrices]
00048   ::stereo::CalibrageMatrices_readFromOldFile $calibrageMatrices \
00049       $param_stereo_file
00050   
00051   set source_image_gauche  $imageLeft
00052   set source_image_droite  $imageRight
00053   if { $debayer } {
00054       set interm [image::new_Image [$source_image_gauche width] [$source_image_gauche height] [$source_image_gauche depth] 3]
00055       image::Image_convertColorMode $source_image_gauche $interm $::image::Image_bayerRG2bgr
00056       image::Image_convertColorMode $interm $source_image_gauche $::image::Image_rgb2grey
00057       image::Image_convertColorMode $source_image_droite $interm $::image::Image_bayerRG2bgr
00058       image::Image_convertColorMode $interm $source_image_droite $::image::Image_rgb2grey
00059       image::delete_Image $interm
00060   }
00061   
00062   set images_rectif [_rectification_old $source_image_gauche $source_image_droite $calibrageMatrices \
00063                          $type_rectification]
00064 
00065   ::stereo::delete_CalibrageMatrices $calibrageMatrices
00066 
00067   if "$scale != 1.0" {
00068       set imageLeftRect  [[lindex $images_rectif 0] resize $scale]
00069       set imageRightRect [[lindex $images_rectif 1] resize $scale]
00070       ::image::delete_Image [lindex $images_rectif 0]
00071       ::image::delete_Image [lindex $images_rectif 1]
00072       set images_rectif "$imageLeftRect $imageRightRect"
00073   }
00074 
00075   return $images_rectif
00076     }
00077     
00078     
00079     proc _rectification_old { { source_image_gauche }
00080             { source_image_droite }
00081             { calibrageMatrices }
00082             {type_rectification 1}
00083             {i_min 0.0}
00084             {i_max 1.0}
00085             {j_min 0.0}
00086             {j_max 1.0}
00087         } {
00088   
00089   # suivent les diffrents paramtres sur le choix des algorithmes,
00090   # que l'on peut modifier si on veut ( tous ces paramtres 
00091   # correspondent des enumrations dfinies dans 
00092   # "enum_StereoCorrelation.h") pour les pr-traitements
00093 
00094   set LEFT_IMAGE_ID  0
00095   set RIGHT_IMAGE_ID 1
00096 
00097   # Interpolation flag pendant la rectification : 
00098   #       0 : non
00099   #       1 : oui
00100   set interpolation 1;
00101   
00102   # Correction de la distorsion pendant la rectification :
00103   #           0: non
00104   #           1: vieux modle en R 
00105   #           2 nouveau modle en R
00106   #           3 modle en R3
00107   # REMARK: by Ayman put 2 or 3
00108   ##########  set distorsion 3;
00109   set distorsion 2;
00110 
00111   # nblig :  nombre de lignes dans l'image (hieght)
00112   # nbcol :  nombre de colonnes dans l'image (width)
00113   set nbcol [::image::CvImage_width $source_image_gauche]
00114   set nblig [::image::CvImage_height $source_image_gauche]
00115   
00116 
00117   # Les tailles des images
00118   set images_sizes [::stereo::new_ImagesSizes]
00119   ::stereo::ImagesSizes_initialize $images_sizes    \
00120       $nblig $nbcol 1 1 \
00121       $i_min $i_max $j_min $j_max
00122 
00123   set rectif_params_droite [::stereo::new_RectificationParams]
00124   ::stereo::RectificationParams_initialize $rectif_params_droite \
00125       $images_sizes $calibrageMatrices $RIGHT_IMAGE_ID
00126 
00127   set rectif_params_gauche [::stereo::new_RectificationParams]
00128   ::stereo::RectificationParams_initialize $rectif_params_gauche \
00129       $images_sizes $calibrageMatrices $LEFT_IMAGE_ID
00130   
00131   # On initialise les tables s'il le faut
00132   if {$type_rectification == 2} {
00133       ::stereo::RectificationParams_initializeTables_michel \
00134     $rectif_params_gauche $distorsion
00135       ::stereo::RectificationParams_initializeTables_michel \
00136     $rectif_params_droite $distorsion
00137   }
00138 
00139   # Reconstruction Params
00140   set reconstruction_params [::stereo::new_ReconstructionParams]
00141   ::stereo::ReconstructionParams_initialize $reconstruction_params $calibrageMatrices
00142   #  ::stereo::ReconstructionParams_info $reconstruction_params 
00143 
00144   ######################################################################
00145   # Rectification 
00146   # first we must create the rectified image buffer 
00147   # then call the rectification function
00148   set nRectifiedImageWidth [::stereo::ImagesSizes_getRectifiedImageWidth $images_sizes]
00149   set nRectifiedImageHeight [::stereo::ImagesSizes_getRectifiedImageHeight $images_sizes]
00150   set img_depth $::image::IPL_DEPTH_8U
00151   set color_space  $::image::JfrImage_CS_GRAY
00152 
00153   set im_rectif_gauche [::image::new_Image \
00154           $nbcol \
00155           $nblig\
00156           $img_depth \
00157           $color_space]
00158   
00159 
00160   set im_rectif_droite [::image::new_Image \
00161           $nbcol \
00162           $nblig\
00163           $img_depth \
00164           $color_space]
00165   
00166   
00167   ::stereo::jfrRectification_old $source_image_gauche $im_rectif_gauche \
00168       $images_sizes $rectif_params_gauche \
00169       0 $type_rectification\
00170       $distorsion $interpolation
00171 
00172 
00173   ::stereo::jfrRectification_old $source_image_droite $im_rectif_droite \
00174       $images_sizes $rectif_params_droite \
00175       0 $type_rectification\
00176       $distorsion $interpolation
00177 
00178 #     ::display::show $im_rectif_gauche "image rect gauche"
00179 #   ::display::show $im_rectif_droite "image rect droite"
00180 
00181   # clean intermediaire variables
00182   ::stereo::delete_ImagesSizes $images_sizes
00183   ::stereo::delete_RectificationParams $rectif_params_droite
00184   ::stereo::delete_RectificationParams $rectif_params_gauche
00185   ::stereo::delete_ReconstructionParams $reconstruction_params
00186 
00187   return "$im_rectif_gauche $im_rectif_droite"
00188     }
00189     
00190 }
00191 
00192 package provide stereo 0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:28 for Jafar by doxygen 1.7.6.1
LAAS-CNRS