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
/
View
/
view-analysis.lisp
Wrap
Lisp/Scheme
|
1995-08-14
|
6KB
|
179 lines
;;; VIEW-ANALYSIS.LISP
;;;
;;; Support Routines for Viewpoint Selection/Verification for
;;; three Dimensional Perceptual Organization.
;;;
;;;
;;; Author: Christopher O. Jaynes
;;; Date: June 10, 1995
;;;
;;
;------------------------------------------------------------
; (c) Copyright 1995 by The University of Massachusetts
;------------------------------------------------------------
(in-package 'grouping)
;;********************************************************
;; Generic Projection Routines.
;;
;;(defun project-point (projection x y z)
"Projects 3D world point x y z into image plane u v."
;; (projmat-3d-to-2d (projection-projmat projection) x y z))
;;
;;(defun backproject-point (projection u v zval)
;; "Backproject image point u v and return the 3d point where
;; the backprojection ray intersects the plane z = zval."
;; (when (null (projection-inverse-projmat projection))
;; (setf (projection-inverse-projmat projection)
;; (inverse-projmat (projection-projmat projection))))
;; (let ((invproj (projection-inverse-projmat projection)))
;; (multiple-value-bind (a b)
;; (projmat-2d-to-3d nil u v invproj)
;; (let ((k (/ (- zval (third b)) (third a))))
;; (la:v+ b (la:vs k a))))))
;;*********************************************************
;; Given a line in a single image, create a 3d rectangle where
;; the length is the backprojected endpoint length and the
;; height is the grouping depth.
;;
;; First, a rectangle within the image is created with
;; vertecies r1,r2,r3,r4;
;;
;; The 2d rectangle is backprojected to create a rectangle in
;; the world.
(defun grouping-box (2dw pt1 pt2)
" Generates a 3d grouping region from the backprojected image
points."
(let* ((proj (3d-to-2d-projection 2dw))
(avgHeight (/ (+ (third pt1) (third pt2)) 2.0))
(u1 (car pt1))
(v1 (cadr pt1))
(u2 (car pt2))
(v2 (cadr pt2)))
(multiple-value-bind (r1x r1y r2x r2y)
(fex::perpendicular-from-point-on-line
u1 v1 u2 v2 u1 v1 (- *group-column-image-width*))
(multiple-value-bind (r3x r3y r4x r4y)
(fex::perpendicular-from-point-on-line
u1 v1 u2 v2 u2 v2 (- *group-column-image-width*))
(setf vertexlist (list
(multiple-value-list (inverse-project-point proj r1x r1y
(- avgHeight *grouping-column-depth*)))
(multiple-value-list (inverse-project-point proj r3x r3y
(- avgHeight *grouping-column-depth*)))
(multiple-value-list (inverse-project-point proj r4x r4y
(- avgHeight *grouping-column-depth*)))
(multiple-value-list (inverse-project-point proj r2x r2y
(- avgHeight *grouping-column-depth*)))
(multiple-value-list (inverse-project-point proj r1x r1y
(+ avgHeight *grouping-column-depth*)))
(multiple-value-list (inverse-project-point proj r3x r3y
(+ *grouping-column-depth* )))
(multiple-value-list (inverse-project-point proj r4x r4y
(+ avgHeight *grouping-column-depth* )))
(multiple-value-list (inverse-project-point proj r2x r2y
(+ avgHeight *grouping-column-depth* ))))))))
(make-vertex-array-from-vertex-list vertexlist))
(defun make-grouping-box (2dw pt1 pt2)
(let* ((cube (make-cube-object :world (3d-world 2dw)))
(verts (grouping-box-vertices 2dw pt1 pt2)))
(setf (vertices cube) verts)
cube))
;;
;; Compute the image area covered by projecting the 3d group-box into
;; the image plane using 'proj'
;;
;;
;; 2.5d Box to image.
;;
;;
;; In order to verify a possible 2.5d grouping, a particular image
;; region must be chosen from the set of possible viewpoints.
;; A quadralateral is formed in the world between the the two corner
;; features with a depth defined by the allowed error. This region is
;; projected into each image and its area is computed. The projection
;; that yields the maximum area is chosen as the "best" viewpoint
;; for verification.
;;
;;
;;
;; best-verify-viewpoint
;;
;; Determine the best viewpoint for image verification of the proposed
;; grouping. If the proposed grouping takes place in 2d then a 3d
;; 'grouping-object' should have been created using the 'grouping-box'
;; routine.
;;
;; For each 2d-world, project the grouping-box and compute the area
;; subtracting out occlusions that can be detected from the model,
;; the "best" viewpoint is the one that has the maximum projected
;; visible image region between the two features that are being
;; grouped.
;;
(defmethod image-bounding-box ((self cached-bounding-box-mixin) image)
"Returns multiple values (imin imax jmin jmax) giving the image coordinates
of the bounding box of the 3d object"
(with-slots (object-to-world-transform) self
(multiple-value-bind (oxmin oxmax oymin oymax ozmin ozmax)
(compute-bounding-box self)
(when oxmin
(multiple-value-bind (wxmin wymin wzmin)
(transform-point object-to-world-transform oxmin oymin ozmin)
(multiple-value-bind (wxmax wymax wzmax)
(transform-point object-to-world-transform oxmax oymax ozmax)
(multiple-value-bind (i000 j000)
(transform-world-to-image wxmin wymin wzmin image)
(multiple-value-bind (i001 j001)
(transform-world-to-image wxmin wymin wzmax image)
(multiple-value-bind (i010 j010)
(transform-world-to-image wxmin wymax wzmin image)
(multiple-value-bind (i011 j011)
(transform-world-to-image wxmin wymax wzmax image)
(multiple-value-bind (i100 j100)
(transform-world-to-image wxmax wymin wzmin image)
(multiple-value-bind (i101 j101)
(transform-world-to-image wxmax wymin wzmax image)
(multiple-value-bind (i110 j110)
(transform-world-to-image wxmax wymax wzmin image)
(multiple-value-bind (i111 j111)
(transform-world-to-image wxmax wymax wzmax imag
e)
(values (min i000 i001 i010 i011 i100 i101 i110 i1
11)
(max i000 i001 i010 i011 i100 i101 i110 i1
11)
(min j000 j001 j010 j011 j100 j101 j110 j1
11)
(max j000 j001 j010 j011 j100 j101 j110 j1
11))))))))))))))))