00001 00002
00003 00004 00005 00006
00007 namespace eval vme {
00008
00009 proc estimateMotion {indexFrame1 indexFrame2
00010 { scale 0.5 }
00011 { dataDir "." }
00012 { enableWeight "true" }
00013 { enableOutliers "true" }
00014 { enableUncertainty "true"}
00015 { minDisparity 0.5 }
00016 { maxStereoDeltaV 1.0 }
00017 { nbMin3DPointPairs 3 }
00018 { removeOutliersKmax 5 }
00019 { removeOutliersKmin 3 }
00020 { sigmaPix 0.5 }
00021 { sigmaDisp 0.5 }
00022 { doDisplay true }
00023 { imagesSubDir "images" }
00024 { configSubDir "config" }
00025 } {
00026 00027 00028
00029 00030 set stereoImageReader [::image::new_StereoImageSequenceReader]
00031 $stereoImageReader setup [file join $dataDir $imagesSubDir] "image." ".g" ".d" "" 3
00032
00033 00034 set sb [::image::new_StereoBench]
00035 $sb load [file join $dataDir $configSubDir "stereo.cal"]
00036 $sb applyScale $scale
00037
00038 00039 set vmeParams [vme::new_EngineParams \
00040 $enableWeight $enableOutliers $enableUncertainty \
00041 $minDisparity $maxStereoDeltaV \
00042 $nbMin3DPointPairs \
00043 $removeOutliersKmax $removeOutliersKmin \
00044 $sigmaPix $sigmaDisp]
00045
00046 00047 global vmeEngine
00048 set vmeEngine [::vme::new_Engine $::geom::T3D_EULER $sb]
00049 $vmeEngine setParams $vmeParams
00050
00051 ::image::delete_StereoBench $sb
00052 vme::delete_EngineParams $vmeParams
00053
00054 00055 set imageFrame1Left [$stereoImageReader loadLeft $indexFrame1]
00056 set imageFrame1Right [$stereoImageReader loadRight $indexFrame1]
00057
00058 00059 set imagesFrame1_rect [::stereo::rectification_old $imageFrame1Left $imageFrame1Right [file join $dataDir $configSubDir "vecteurs"] $scale]
00060 set imageFrame1Left_rect [lindex $imagesFrame1_rect 0]
00061 set imageFrame1Right_rect [lindex $imagesFrame1_rect 1]
00062
00063 00064 $imageFrame1Left_rect saveImage "pipo1LeftRect.tiff"
00065 $imageFrame1Right_rect saveImage "pipo1RightRect.tiff"
00066
00067 00068 ::image::delete_JfrImage $imageFrame1Left
00069 ::image::delete_JfrImage $imageFrame1Right
00070
00071 00072 $vmeEngine init $imageFrame1Left_rect $imageFrame1Right_rect
00073
00074 if $doDisplay {
00075 ::display::show $imageFrame1Left_rect "frame $indexFrame1 - left - corrected"
00076 ::display::show $imageFrame1Right_rect "frame $indexFrame1 - right - corrected"
00077 ::gfm::displayHarrisPoints $imageFrame1Left_rect [[$vmeEngine getStereoResult] cget -points_ref]
00078 ::gfm::displayHarrisPoints $imageFrame1Right_rect [[$vmeEngine getStereoResult] cget -points_match]
00079 ::gfm::displayMatch $imageFrame1Left_rect $imageFrame1Right_rect \
00080 [[$vmeEngine getStereoResult] cget -matches] \
00081 false "green"
00082 }
00083
00084 00085 set imageFrame2Left [$stereoImageReader loadLeft $indexFrame2]
00086 set imageFrame2Right [$stereoImageReader loadRight $indexFrame2]
00087
00088 00089 set imagesFrame2_rect [::stereo::rectification_old $imageFrame2Left $imageFrame2Right [file join $dataDir $configSubDir "vecteurs"] $scale]
00090 set imageFrame2Left_rect [lindex $imagesFrame2_rect 0]
00091 set imageFrame2Right_rect [lindex $imagesFrame2_rect 1]
00092
00093 00094 $imageFrame2Left_rect saveImage "pipo2LeftRect.tiff"
00095 $imageFrame2Right_rect saveImage "pipo2RightRect.tiff"
00096
00097 00098 ::image::delete_JfrImage $imageFrame2Left
00099 ::image::delete_JfrImage $imageFrame2Right
00100
00101 00102 $vmeEngine estimateMotion $imageFrame2Left_rect $imageFrame2Right_rect
00103
00104 if $doDisplay {
00105 ::display::show $imageFrame2Left_rect "frame $indexFrame2 - left - corrected"
00106 ::display::show $imageFrame2Right_rect "frame $indexFrame2 - right - corrected"
00107
00108 ::gfm::displayHarrisPoints $imageFrame2Left_rect [[$vmeEngine getStereoResult] cget -points_ref]
00109 ::gfm::displayHarrisPoints $imageFrame2Right_rect [[$vmeEngine getStereoResult] cget -points_match]
00110 ::gfm::displayMatch $imageFrame2Left_rect $imageFrame1Right_rect \
00111 [[$vmeEngine getStereoResult] cget -matches] \
00112 false "green"
00113
00114 ::hpm::displayTrack $imageFrame2Left_rect \
00115 [[$vmeEngine getTrackResult] cget -matches]
00116 }
00117
00118 00119 ::image::delete_JfrImage $imageFrame1Left_rect
00120 ::image::delete_JfrImage $imageFrame1Right_rect
00121 ::image::delete_JfrImage $imageFrame2Left_rect
00122 ::image::delete_JfrImage $imageFrame2Right_rect
00123
00124 ::image::delete_StereoImageSequenceReader $stereoImageReader
00125
00126 puts "** motion estimate: "
00127 puts "[geom::print [$vmeEngine t3d]]"
00128 set T [[$vmeEngine t3d] getX]
00129 set TStdDev [[$vmeEngine t3d] getXStdDev]
00130
00131 puts "t (m): [$T get 0] [$T get 1] [$T get 2]"
00132 puts "sigma: [$TStdDev get 0] [$TStdDev get 1] [$TStdDev get 2]"
00133 puts "r (deg): [jmath::radToDeg [$T get 3]] [jmath::radToDeg [$T get 4]] [jmath::radToDeg [$T get 5]]"
00134 puts "sigma: [jmath::radToDeg [$TStdDev get 3]] [jmath::radToDeg [$TStdDev get 4]] [jmath::radToDeg [$TStdDev get 5]]"
00135
00136 puts "vme duration: [$vmeEngine getElapsedTime] ms"
00137
00138 ::vme::delete_Engine $vmeEngine
00139 }00140
00141 proc batchEstimateMotion {indexFirstFrame indexLastFrame
00142 { indexStep 1}
00143 { scale 1.0 }
00144 { dataDir "." }
00145 { enableWeight "true" }
00146 { enableOutliers "true" }
00147 { enableUncertainty "true"}
00148 { minDisparity 0.5 }
00149 { maxStereoDeltaV 1.0 }
00150 { nbMin3DPointPairs 3 }
00151 { removeOutliersKmax 5 }
00152 { removeOutliersKmin 3 }
00153 { sigmaPix 0.5 }
00154 { sigmaDisp 0.5 }
00155 { doDisplay true }
00156 { imagesSubDir "images" }
00157 { vmeSubDir "vme" }
00158 { configSubDir "config" }
00159 } {
00160 00161 00162
00163 00164 global dataLogger
00165 set dataLogger [::kernel::new_DataLogger "vme.dat"]
00166
00167 00168 set stereoImageReader [::image::new_StereoImageSequenceReader]
00169 $stereoImageReader setup [file join $dataDir $imagesSubDir] "image." ".l" ".r" ".tiff"
00170
00171 00172 set sb [::image::new_StereoBench]
00173 $sb load [file join $dataDir $configSubDir "stereo.cal"]
00174 $sb applyScale $scale
00175
00176 00177 global vmeEngine
00178 set vmeEngine [::vme::new_Engine $::geom::T3D_EULER $sb]
00179 ::image::delete_StereoBench $sb
00180 $vmeEngine setup $enableWeight $enableOutliers $enableUncertainty \
00181 $minDisparity $maxStereoDeltaV \
00182 $nbMin3DPointPairs \
00183 $removeOutliersKmax $removeOutliersKmin
00184 $vmeEngine setupUncertainty $sigmaPix $sigmaDisp
00185
00186 $dataLogger addLoggable $vmeEngine
00187 $dataLogger addLoggable [$vmeEngine getStereoTrackingEngine]
00188
00189 puts ""
00190 puts "** frame $indexFirstFrame **"
00191
00192 00193 set imageFrame1Left [$stereoImageReader loadLeft $indexFirstFrame]
00194 set imageFrame1Right [$stereoImageReader loadRight $indexFirstFrame]
00195
00196 00197 set imagesFrame1_rect [::stereo::rectification_old $imageFrame1Left $imageFrame1Right [file join $dataDir $configSubDir "vecteurs"] $scale]
00198 set imageFrame1Left_rect [lindex $imagesFrame1_rect 0]
00199 set imageFrame1Right_rect [lindex $imagesFrame1_rect 1]
00200
00201 00202 ::image::delete_JfrImage $imageFrame1Left
00203 ::image::delete_JfrImage $imageFrame1Right
00204
00205 00206 $vmeEngine init $imageFrame1Left_rect $imageFrame1Right_rect
00207
00208 if $doDisplay {
00209 }
00210
00211 00212 ::image::delete_JfrImage $imageFrame1Left_rect
00213 ::image::delete_JfrImage $imageFrame1Right_rect
00214
00215 set index $indexFirstFrame
00216 incr index $indexStep
00217
00218 for {} {$index <= $indexLastFrame} {incr index $indexStep} {
00219
00220 puts ""
00221 puts "** frame $index **"
00222
00223 # load images
00224 set imageFrame2Left [$stereoImageReader loadLeft $index]
00225 set imageFrame2Right [$stereoImageReader loadRight $index]
00226
00227 # rectif
00228 set imagesFrame2_rect [::stereo::rectification_old $imageFrame2Left $imageFrame2Right [file join $dataDir $configSubDir "vecteurs"] $scale]
00229 set imageFrame2Left_rect [lindex $imagesFrame2_rect 0]
00230 set imageFrame2Right_rect [lindex $imagesFrame2_rect 1]
00231
00232 # free memory
00233 ::image::delete_JfrImage $imageFrame2Left
00234 ::image::delete_JfrImage $imageFrame2Right
00235
00236 # vme
00237 $vmeEngine estimateMotion $imageFrame2Left_rect $imageFrame2Right_rect $index
00238
00239 $dataLogger log
00240
00241 if $doDisplay {
00242 }
00243
00244 # free memory
00245 ::image::delete_JfrImage $imageFrame2Left_rect
00246 ::image::delete_JfrImage $imageFrame2Right_rect
00247
00248 # save t3d
00249 set from [expr $index - $indexStep]
00250 set to $index
00251 [$vmeEngine t3d] save [file join $dataDir $vmeSubDir "[format "%04d" $from]_to_[format "%04d" $to].t3d"]
00252
00253 puts "** motion estimate: "
00254 puts "[geom::print [$vmeEngine t3d]]"
00255 set T [[$vmeEngine t3d] getX]
00256 set TStdDev [[$vmeEngine t3d] getXStdDev]
00257
00258 puts "t (m): [$T get 0] [$T get 1] [$T get 2]"
00259 puts "sigma: [$TStdDev get 0] [$TStdDev get 1] [$TStdDev get 2]"
00260 puts "r (deg): [jmath::radToDeg [$T get 3]] [jmath::radToDeg [$T get 4]] [jmath::radToDeg [$T get 5]]"
00261 puts "sigma: [jmath::radToDeg [$TStdDev get 3]] [jmath::radToDeg [$TStdDev get 4]] [jmath::radToDeg [$TStdDev get 5]]"
00262
00263 }
00264
00265 00266 ::image::delete_StereoImageSequenceReader $stereoImageReader
00267 ::vme::delete_Engine $vmeEngine
00268 ::kernel::delete_DataLogger $dataLogger
00269 }00270
00271 }00272
00273 package provide vme 0.2