home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
Acquire
/
acquire-model.lisp
< prev
Wrap
Lisp/Scheme
|
1996-03-08
|
14KB
|
330 lines
;;Acquire-model.lisp - acquire a full site model in as automatic
;;a manner as possible. Once you set the system parameters, this
;;runs pretty much as a batch job.
(in-package 'cme)
(defun display-work-area-rectangle (view u1 v1 u2 v2 color thickness transform)
(display-line view u1 v1 u1 v2
:color color :thickness thickness :transform transform)
(display-line view u1 v2 u2 v2
:color color :thickness thickness :transform transform)
(display-line view u2 v2 u2 v1
:color color :thickness thickness :transform transform)
(display-line view u2 v1 u1 v1
:color color :thickness thickness :transform transform)
)
(defvar *max-acquire-blocksize* 256)
(defvar *acquire-blocksize* 256)
(defvar *site-save-filename* "site-model.fs")
(defvar *boldt-sens* :medium)
(defvar *boldt-minlength* 5.0)
(defun set-acquire-parameters-via-menu ()
(ic::with-cvv-items
(((blocksize "Acquire Site Model: Block Size: "
:integer :initial-value *max-acquire-blocksize*
:documentation "Width (in pixels) of subwindow for building detection")
(savefilename "Save Site Filename: "
:string :initial-value *site-save-filename*
:documentation "Filename for saving site model feature set")
(ignore1 nil :separator)
(sens "Boldt Line Extraction: Sensitivity: " :assoc :alist
(("Low" :low "Low sensitivity")
("Medium" :medium "Medium sensitivity")
("High" :high "High sensitivity"))
:documentation "Choose a sensitivity setting"
:initial-value :medium)
(minlength "Min Length: " :float :initial-value 5.0
:documentation "Minimum desired line length")
(ignore2 nil :separator)
(sensitivity "2D Building Detection: Sensitivity: "
:double-float-slider
:value *bf-sensitivity*
:format "%3g"
:min 0.0
:max 1.0
:documentation "Adjust sensitivity of the building detector")
(constrain "Shape Refinement: "
:yes-or-no
:value *bf-constrain-p*
:documentation
"Use Least Squares Constraints to modify final polygon shape")
(manual "Manually adjust parameters: "
:yes-or-no :value *bf-param-adjust*
:documentation
"Ignore the sensitivity slider, set each parameter individually")
(topcycles "Output Best K cycles: "
:yes-or-no :value *bf-best-k*
:documentation "Ignore hypothesis conflicts, output k best cycles")
(k-cycles "K: "
:integer :value *bf-k-cycles*
:documentation "Number of best cycles to display")
(2.5dlines "Use 2.5d line data: "
:yes-or-no :value *bf-2.5d-lines*
:documentation
"Match image lines to compute height before building detection")
(ignore3 nil :separator)
(zmin "Match/Triangulate: Min Z value: " :float :value *last-epi-minz*
:documentation "Minimum Z coordinate of a building rooftop")
(zmax "Max Z value: " :float :value *last-epi-maxz*
:documentation "Maximum Z coordinate of a building rooftop")
(support "Line support:" :float :value *last-epi-support-percentage*
:documentation "Minimum line support percentage allowed")
(slop "Pixel error: " :float :value *last-epi-slop*
:documentation "Amount of perpendicular slop in line endpoints")
(dtheta "Radian error: " :float :value *last-epi-dtheta*
:documentation "Amount of slop in line orientation (radians)")
(arb "Arbitration: " :float :value *arbitration-threshold*
:documentation "Amount of overlap defining alternate hypotheses")
)
:label "Acquire Site Model")
(declare (ignore ignore1 ignore2 ignore3))
(when (> blocksize *max-acquire-blocksize*)
(warn "Setting blocksize to ~d" *max-acquire-blocksize*)
(setf blocksize *max-acquire-blocksize*))
(setf blocksize (* 2 (floor blocksize 2))) ;;make sure it's an even number
(setf *acquire-blocksize* blocksize)
(setf *site-save-filename* savefilename)
(setf *boldt-sens* sens)
(setf *boldt-minlength* minlength)
(when manual (popup-building-parameters-menu))
(setf *bf-sensitivity* sensitivity)
(setf *bf-constrain-p* constrain)
(setf *bf-2.5d-lines* 2.5dlines)
(setf *bf-param-adjust* manual)
(setf *bf-best-k* topcycles)
(when (null topcycles) (setf k-cycles 0))
(setf *bf-k-cycles* k-cycles)
(setf *last-epi-slop* slop)
(setf *last-epi-dtheta* dtheta)
(setf *last-epi-minz* zmin)
(setf *last-epi-maxz* zmax)
(setf *last-epi-support-percentage* support)
(setf *arbitration-threshold* arb)
(rcde-init-height-histograms zmin zmax)))
(defun active-image-view (image)
(let ((viewlist (view-list (2d-world image))))
(or (find nil viewlist
:test #'(lambda (x y) (declare (ignore x)) (active-p y)))
(car viewlist))))
(defun acquire-model-in-block (image ustart vstart uend vend &key (pane nil)
(clear-lines-before nil)(clear-lines-after t)
(use-previous-lines nil))
(let* ((topview (if pane (cme::top-view pane) (active-image-view image)))
(panechoice (or pane (view-window topview)))
(2d-world (2d-world image))
(view1 (find-epi-view-for-world 2d-world))
(otherviews (find-the-other-epi-views 2d-world))
(boldt-fs (get-or-make-2d-feature-set 2d-world *2d-line-fsname*))
(2droof-fs (find-fs-named 2d-world *2d-building-fsname*))
(imto2d-trans (image-to-2d-transform image))
(2dtoim-trans (inverse-transform (image-to-2d-transform image)))
(winto2d-trans (inverse-transform (2d-to-window-transform topview)))
(wintoim-trans (make-composite-coordinate-transform
(list winto2d-trans 2dtoim-trans)))
(imtowin-trans (inverse-transform wintoim-trans))
(world-bbox (multiple-value-list
(transform-2d-bounding-box imto2d-trans
ustart vstart uend vend)))
(pane-bbox (multiple-value-list
(transform-2d-bounding-box imtowin-trans
ustart vstart uend vend))))
(when clear-lines-before (clear-fs boldt-fs) (process-object-updates))
(display-work-area-rectangle topview ustart vstart uend vend
"GREEN" 1 imtowin-trans)
(epi::synch-epipolar-screen topview)
(unless use-previous-lines
(boldt::canny-boldt-uv image ustart vstart uend vend boldt-fs
:sensitivity *boldt-sens* :minlength *boldt-minlength*))
(process-object-updates)
(if *bf-2.5d-lines*
(compute-2.5dlines-for-building-detect panechoice pane-bbox)
(write-2dlines-for-building-detect panechoice pane-bbox))
(setf *topdown-edgels-for-bdetect*
(apply #'compute-2dworld-canny-edges image world-bbox))
(find-polygons *bf-sensitivity* *bf-constrain-p*
*bf-param-adjust* *bf-2.5d-lines*
(floor (car pane-bbox)) (floor (cadr pane-bbox))
(ceiling (third pane-bbox)) (ceiling (fourth pane-bbox))
*bf-k-cycles* (lci::create-c-handle panechoice))
(free-edgeimg *topdown-edgels-for-bdetect*)
(when clear-lines-after (clear-fs boldt-fs))
(process-object-updates)
(let* ((curves (mapcan #'(lambda (x)
(when (eq (type-of x) 'cme::2d-curve) (list x)))
(inferiors 2droof-fs)))
(count 0)
(numcurves (length curves))
(linelist (mapcan #'linelist-from-2dcurve curves)))
(when curves
(dolist (view2 otherviews)
(let ((boundingbox (epi::epipolar-search-area-bbox
view1 view2 linelist)))
(setf (epi::view-topdown-edgels view2)
(apply #'compute-2dworld-canny-edges
(epi::view-image view2)
boundingbox)))))
(dolist (curve curves)
(format t "Running matcher on 2d roof curve: ~d of ~d~%"
(incf count) numcurves)
(let ((match (rcde-run-epipolar-matcher 2d-world curve
:filename *triang-infile*
:endpoint-slop *last-epi-slop*
:delta-theta *last-epi-dtheta*
:run-canny? nil)))
(shell (format nil "~a ~a ~a"
(translated-unix-path *triang-c-filename*)
*triang-infile* *triang-outfile*))
(remove-object curve 2droof-fs) ;;remove 2d roof hypothesis
(install-triangulated-building ;;and install 3D wireframe
*triang-outfile*
(epi::epimatch-peak-confidence match))))
(when curves
(dolist (view2 otherviews)
(free-edgeimg (epi::view-topdown-edgels view2)))))
(epi::synch-epipolar-screen topview)
(process-object-updates)))
;;could probably figure out a formula for this, but I'm too lazy right now.
(defun determine-numblocks (size block &optional (overlap (floor block 2)))
(do ((count 1 (+ count 1))
(bstart 0 (+ bstart overlap))
(bend block (+ bend overlap)))
((> bend size) count)))
(defun image-numblocks (im block &optional (overlap (floor block 2)))
(* (determine-numblocks (ic::image-x-dim im) block overlap)
(determine-numblocks (ic::image-y-dim im) block overlap)))
(defun bbox-numblocks (image panechoice bbox &optional
(blocksize *acquire-blocksize*)
(overlap (floor blocksize 2)))
(let* ((topview (cme::top-view panechoice))
(xdim (ic::image-x-dim image))
(ydim (ic::image-y-dim image))
(2dtoim-trans (inverse-transform (image-to-2d-transform image)))
(winto2d-trans (inverse-transform
(2d-to-window-transform topview)))
(wintoim-trans (make-composite-coordinate-transform
(list winto2d-trans 2dtoim-trans))))
(multiple-value-bind (u1 v1 u2 v2)
(apply #'transform-2d-bounding-box wintoim-trans bbox)
(setf u1 (min (max u1 0) xdim) v1 (min (max v1 0) ydim)
u2 (max 0 (min u2 xdim)) v2 (max 0 (min v2 ydim)))
(let* ((du (- u2 u1))
(dv (- v2 v1))
(Ublocks (determine-numblocks du blocksize overlap))
(Vblocks (determine-numblocks dv blocksize overlap)))
(* Ublocks Vblocks)))))
(defun image-resolution-list (image panechoice bbox &optional
(blocksize *acquire-blocksize*)
(overlap (floor blocksize 2)))
(let* ((list (list image))
(nblks (bbox-numblocks image panechoice bbox blocksize overlap))
(count nblks))
(do ()
((= nblks 1) (values (reverse list) count))
(setf image (ic::image-zoom-out image))
(push image list)
(setf nblks (bbox-numblocks image panechoice bbox blocksize overlap))
(incf count nblks))))
(defun acquire-site-model ()
(set-acquire-parameters-via-menu)
(multiple-value-bind (bbox panechoice) (pick-bounding-box-and-pane)
(let* ((topview (cme::top-view panechoice))
(2d-world (2d-world (view-image topview)))
(3d-world (3d-world 2d-world))
(blocksize *acquire-blocksize*)
(halfblocksize (floor blocksize 2))
(blocksofar 0)
imagelist numblocks)
(unless (ic::get-prop 3d-world :umass-site-model)
(error "No UMass site model has been initialized for this 3D world"))
(multiple-value-setq (imagelist numblocks)
(image-resolution-list
(ic::top-of-image-hierarchy (view-image topview))
panechoice bbox blocksize halfblocksize))
(ic::noting-progress ("Acquire Model" numblocks :progress-var acqvar)
(dolist (image imagelist)
(let* ((boldt-fs (get-or-make-2d-feature-set 2d-world *2d-line-fsname*))
(3dhyp-fs (find-fs-named 3d-world *3d-hypotheses-fsname*))
(3dsite-fs (find-fs-named 3d-world *3d-building-fsname*))
(xdim (ic::image-x-dim image))
(ydim (ic::image-y-dim image))
(2dtoim-trans (inverse-transform (image-to-2d-transform image)))
(winto2d-trans (inverse-transform
(2d-to-window-transform topview)))
(wintoim-trans (make-composite-coordinate-transform
(list winto2d-trans 2dtoim-trans)))
u1 v1 u2 v2)
(clear-fs boldt-fs)
(process-object-updates)
(multiple-value-setq (u1 v1 u2 v2)
(apply #'transform-2d-bounding-box wintoim-trans bbox))
(setf u1 (min (max u1 0) xdim) v1 (min (max v1 0) ydim)
u2 (max 0 (min u2 xdim)) v2 (max 0 (min v2 ydim)))
(let* ((du (- u2 u1))
(dv (- v2 v1))
(Ublocks (determine-numblocks du blocksize halfblocksize))
(Vblocks (determine-numblocks dv blocksize halfblocksize)))
(do ((Vcnt 1 (1+ vcnt))
(vstart v1 (+ vstart halfblocksize))
(vend (min v2 (+ v1 blocksize))
(min v2 (+ vend halfblocksize))))
((> Vcnt Vblocks) nil)
(do ((ucnt 1 (1+ ucnt))
(ustart u1 (+ ustart halfblocksize))
(uend (min u2 (+ u1 blocksize))
(min u2 (+ uend halfblocksize))))
((> ucnt ublocks) nil)
(acquire-model-in-block image ustart vstart uend vend
:pane panechoice)
(dump-feature-sets *site-save-filename* (list 3dhyp-fs 3dsite-fs))
(ic::note-progress (incf blocksofar) acqvar))))))))))
#|
(defun cl ()
(load (compile-file "$RADIUSCODE/UMass/Acquire/acquire-model.lisp")))
(defun foo () (acquire-site-model))
|#
#|
(defun just-draw-box (image ustart vstart uend vend &key (pane nil)
(clear-lines-before nil)(clear-lines-after t)
(use-previous-lines nil))
(let* ((topview (if pane (cme::top-view pane) (active-image-view image)))
(panechoice (or pane (view-window topview)))
(2d-world (2d-world image))
(view1 (find-epi-view-for-world 2d-world))
(otherviews (find-the-other-epi-views 2d-world))
(boldt-fs (get-or-make-2d-feature-set 2d-world *2d-line-fsname*))
(2droof-fs (find-fs-named 2d-world *2d-building-fsname*))
(imto2d-trans (image-to-2d-transform image))
(2dtoim-trans (inverse-transform (image-to-2d-transform image)))
(winto2d-trans (inverse-transform (2d-to-window-transform topview)))
(wintoim-trans (make-composite-coordinate-transform
(list winto2d-trans 2dtoim-trans)))
(imtowin-trans (inverse-transform wintoim-trans))
(world-bbox (multiple-value-list
(transform-2d-bounding-box imto2d-trans
ustart vstart uend vend)))
(pane-bbox (multiple-value-list
(transform-2d-bounding-box imtowin-trans
ustart vstart uend vend))))
(when clear-lines-before (clear-fs boldt-fs) (process-object-updates))
(display-work-area-rectangle topview ustart vstart uend vend
"GREEN" 1 imtowin-trans)
))
|#