Computer Vision (CSE 490CV/EE 400B), Winter 2002

Project 3:  Single View Modeling

Skeleton Code 

Click here to download.

The interface allows you to load an image and add points, lines, and polygons. After you compute the 3D position of those points, you can save the model and reload it for further editing. When you are done, you can dump the model in VRML 2.0 format and view it in VRML viewer. 

The file IO related functions are under "File" submenu as usual. 

The "Edit" submenu, you have the following choices:

Point: add or delete points. To add a point, left click. To delete a point, move to the point till it is high lighted as white, then press "Backspace". The point can be deleted if it is not used by any other lines or polygons. 

X Line, Y Line, Z Line, Other Line: to add or delete lines. To add a line, the first left click defines the start point, and the second left click defines the end point. If you want to reuse one of the existing points as start/end point, just press "Ctrl" when you left click. To delete a line, move the mouse onto it till it becomes white and press "Backspace". In "X Line" edit mode, the lines you add are supposed to be parallel to the X axis in 3D. Similar meaning for the "Y Line" and "Z Line" mode. Lines added in "Other Line" mode may have any orientation. 

Polygon: add or delete polygons. Each polygon consists of a list of points. To add a polygon, you sequentially left click on desired positions and then press "Enter". A closed a polygon will be drawn. ( You don't have to click on the first point to make the polygon closed, the system automatically does it for you. ) To delete a polygon, move the mouse to the center of the polygon, shown as a white square, and press "Backspace". Every time you create a new polygon, you will give a name for it, e.g, "ceiling", "floor", which will be used as the texture file names when you save the model in VRML. The texture file name for a particular polygon will be the polygon name with ".gif" extension.

The "Draw" submenu, you can toggle the following options:

Points: draw points or not.

Lines: draw lines or not.

Polygons: draw polygons or not.

Draw 3D: draw it in 2D or 3D mode. 

When "Draw 3D" is not checked, all the image and points, lines, and polygons are drawn in image plane. You can edit them and

zoom in/out: Ctrl+/-;

move image: drag with right button;

When "Draw 3D" is checked, all the points, lines, and polygons are drawn in 3D (based on your computation of X,Y,Z for each point). The image is texture mapped onto the polygon (based on your estimation of homograph H, invH). You can not edit in this mode, but you can

scale up/down: Ctrl+/-;

move model parallel to the viewing plane: drag with left button;

move model further/closer: drag with left button upwards/downwards, with Alt down;

rotate around X: drag with left button vertically, with Ctrl down;

rotate around Y: drag with left button horizontally, with Ctrl down;

rotate clockwise/counterclockwise: drag with left button to the right/left, with Shift down;

Currently, there are 30 C++ files in skeleton codes: HelpPageUI.cpp/h, svmUI.cpp/h, ImgView.cpp/h, smvMain.cpp, svm.h, svmAux.h, PriorityQueue.h. 

HelpPageUI.cpp/h, svmUI.cpp/h: defines a help window and a main window respectively. 

svmAux.h, PriorityQueue.h: defines some auxiliary data structures and functions.

svmMain: defines the "main" function, which is simply a loop;

svm.h: includes several head files and defines the following important data structures:

struct SVMPoint {

double u,v,w;

double X,Y,Z,W;

};

typedef CTypedPtrDblList<SVMPoint> PointList;

where (u,v,w) is 2D Homogeneous Coordinates in image plane, and X, Y, Z, W are 3D Homogeneous Coordinates in 3D world. If w = 1, (u, v) is image coordinates, ranging from 0 to image width and 0 to image height respectively. If w=0 means the point is at infinity. Otherwise, (u/w, v/w) is  image coordinates. Similar means for X, Y, Z, W. 

struct SVMLine

int orientation;

SVMPoint *pnt1, *pnt2;

};

typedef CTypedPtrDblList<SVMLine> LineList;

where orientation indicates whether the line is supposed to be parallel to X, Y, Z axis or just any possible orientation in 3D. 

struct SVMPolygon {

CTypedPtrDblList <SVMPoint> pntList;

double cntx, cnty;

double H[3][3],invH[3][3];

char name[256];
};

typedef CTypedPtrDblList<SVMPolygon> PolygonList;

where each polygon consist of a list of SVMPoint and the pointers to the SVMPoints are saved in pntList. 
(cntx, cnty) is the mean of all points in the list, used for polygon selection in UI. H is the homography from normalized texture image of this polygon to the original image; that is, if the INVERSE of H is applied to the image coordinates (u,v,w) in the pntList, the result is the texture coordinates, ranging between [0,1]. invH is the inverse matrix of H. H is used when generating texture images from original image. invH is used to convert image coordinates in pntList to texture coordinates. Whenever you change H, please update invH using Matrix3by3Inv function in svmAux.h. 

name is the name of the polygon. name.gif will be used as texture file name for VRML file, which will be explained later. 

ImgView.cpp/h: defines and implements imgView class, which handles most of the UI messages and drawing routines. You will work with the follow member data:

PointList pntList;

LineList lineList;

PolygonList plyList;

which save all the points, lines, and polygons you create. 

This project is not the same as previous one in a sense that you are not given several TODOs, each of which you just fill in several sentences. Instead, you are given a goal to generate 3D textured models. To achieve the goal, we recommend you to follow the 5 steps mentioned above. It is up to you how to organize your code based our skeleton code. As of the 5 steps, they can be divided into two stages: 

A. Estimate the geometry of the model. 

The goal of this stage is to compute the X,Y,Z,W fields for each SVMPoint. It involves calculate vanishing points, and choose reference points. This has been covered in Steve's lectures;

B. Compute the texture image for each polygon. 

Based on the 3D point positions, you need to compute the homography from the polygon plane to the image plane and then resample the original image to generate texture image. You need to fill in code in the skeleton code to do this ! As for the naming convention for texture images, if the polygon has a name "wall", the texture image name should be "wall.tga". "wall.tga" maybe contain something more than a wall, you want to use your scissor programming to cut the wall out of its background. Based on the mask from your scissor and wall.tga, you want to generate a wall.gif with Photoshop, in which background are transparent and the foreground are opaque. If you do this for all the polygons, and save the model as VRML. The skeleton code will generate a VRML file, using polygon's name with ".gif" extension as texture image filename. That's the reason use want to follow my naming convention: wall-->wall.tga-->wall.gif ! If you put the VRML file and all *.gif texture image files under the same directory, you can view it with a VRML viewer. Here is a detailed document about computing homography

The "Tool" submenu is empty. You can put what ever tools you invented to achieve the single view modeling goal.