This action might not be possible to undo. Are you sure you want to continue?

Chapter 1
OVERVIEW
1.1 Overview of the Project Face recognition system is a software that is a biometric identification system. Having the s/w trained on a system and then a given a new face, the software can identify the face as recognized (Belonging to the Database) face or as a new face (not belonging to the Database).
The motive behind the project was that we could learn about Image processing and also being AI students, Image processing is considered to be one of the main fields of AI. This project also increased our knowledge about the image processing and also gaining knowledge about the Artificial Intelligence.
Regarding the applications point of view, Face Recognition actually belongs to Biometrics Security measures. However, Face Recognition has its immense importance as well particularly after 9/11. American DOD is spending millions of dollars on face recognition for tracking of terrorist particularly at Airports. It is yet not so commercial in the sense that no accurate versions of face recognition systems are in the market as compared to finger print recognition or retina scan but the main advantage of it is that actually its non pervasive security technology i.e. you can easily get a picture through a installed camera of a person and recognize it rather than him to do anything for you.
2Face Recognition Systems could also be applied to:
Airport Surveillance Face Recognition systems could be integrated into CCTV networks of airports and used to scan for known terrorists and drug traffickers.
Private Surveillance In today’s cutthroat corporate environment, companies are becoming more and more focused on protecting trade secrets, preserving customer confidentiality and preventing industrial sabotage. To this end, face recognition systems could be used to detect unauthorized personnel in private premises. Together with a private security firm this would provide companies with an extremely high level of internal security.
Access control for PCs in a Corporate Environment Logging on to PCs could be done by a combination of passwords and/or face recognition. This would allow to work unencumbered by complex security procedures yet still ensure a high degree of confidentiality for clients and protections of trade secrets.
Added Security for ATM transactions Access to Automated Teller Machines and other banking services could be controlled with methods like PIN numbers, Speech verification or IRIS recognition in combination with face recognition. Whilst face recognition alone would not alone yield such a high
3degree of certainty for such a crucial application, it could be used together with other techniques to add an extra level of safety an security.
Mug Shot Matching for Law enforcement Agencies Law enforcement agencies could use face recognition software to match witnesses’ descriptions to known criminals. The ability of face recognition systems to determine identity with only partial information would be particularly useful here.
Improved HumanComputer Interaction After recognizing the identity and mood of their users, computerized equipment could modify their behaviour accordingly.
4
Chapter 2
Background Mathematics
First of all going directly into the details of Principal Component Analysis (PCA), its better to get familiar with some basic concepts of image processing.
2.1 Standard Deviation To understand standard deviation, we need a data set. Statisticians are usually concerned with taking a sample of a population. To use election polls as an example, the population is all the people in the country, whereas a sample is a subset of the population that the statisticians measure. The great thing about statistics is that by only measuring (in this case by doing a phone survey or similar) a sample of the population, you can work out what is most likely to be the measurement if you used the entire population.
In this statistics section, I am going to assume that our data sets are samples of some bigger population. There is a reference later in this section pointing to more information about samples and populations. Here’s an example set:
I will use subscripts on the symbol X to indicate a specific number. we can calculate the mean of the sample. but are obviously quite different: So what is different about these two sets? It is the spread of the data that is different. If I want to refer to an individual number in this data set. For example. The Standard Deviation (SD) of a data set is a measure of how spread out the data is. For example. There are a number of things that we can calculate about a data set. these two data sets have exactly the same mean (10). you may see in some is the first number in the sequence.5I could simply use the symbol X to refer to this entire set of numbers. Eg Note that refers to the 3rd number in X. not like textbooks. and will only give the formula: Notice the symbol (said “X bar”) to indicate the mean of the set X. the symbol n will be used to refer to the number of elements in the set X. namely the number 4. Also. How do we calculate it? The English definition of the SD is: “The average distance . All this formula says is “Add up all the numbers and then divide by how many there are”. the mean doesn’t tell us a lot about the data except for a sort of middle point. Unfortunately. I assume that the reader understands what themean of a sample is.
divide by ‘n1’ . The way to calculate it is to compute the squares of the distance from each data point to the mean of the set. . but in general. than if you’d used ‘n’ . the answer is a bit complicated. If. but for an entire population. you are not calculating the standard deviation for a sample. if your data set is a sample data set. ie. Well. I hear you asking “Why are you using ‘n1’ and not ‘n’ ?”. then you should divide by ‘n’ instead of ‘n1’ . you have taken a subset of the realworld (like surveying 500 people about the election) then you must use ‘n1’ because it turns out that this gives you an answer that is closer to the standard deviation that would result if you had used the entire population. add them all up. and take the positive square root. As a formula: Where s is the usual symbol for standard deviation of a sample.6from the mean of the data set to a point”. however.
Standard deviation is the most common measure. in both the symbol ( ) and the formula (there is no square root in the formula for variance). and the aim of the statistical analysis of these data sets is usually to see if there is any relationship between the dimensions. 2. Standard deviation and variance only operate on 1 dimension. so that you could only calculate the standard deviation for each dimension of the data set independently of the . However many data sets have more than one dimension.72. is the usual symbol for variance of a sample. marks for the last DSP exam etc. covariance. and the mark they received for that paper.3 Covariance The last two measures we have looked at are purely 1dimensional. can launch from. In fact it is almost identical to the standard deviation. The formula is this: You will notice that this is simply the standard deviation squared. For example.2 Variance Variance is another measure of the spread of data in a data set. The reason why I have introduced variance in addition to standard deviation is to provide a solid platform from which the next section. we might have as our data set both the height of all the students in a class. but variance is also used. Both these measurements are measures of the spread of the data. We could then perform statistical analysis to see if the height of a student has any effect on their mark. Data sets like this could be: heights of all the people in the room.
Covariance is always measured between 2 dimensions. and the x and y dimensions.8other dimensions. So. here is the formula for covariance: It is exactly the same except that in the second set of brackets.y. The formula for covariance is very similar to the formula for variance. in English. y and z dimensions respectively. So given that knowledge. it is useful to have a similar measure to find out how much the dimensions vary from the mean with respect to each other. or z and z would give you the variance of the x. However. you get the variance. if you had a 3dimensional data set (x. multiply the difference between the x . The formula for variance could also be written like this: where I have simply expanded the square term to show both parts. the x and z dimensions. or y and y. This says. the X ’s are replaced by Y’s.z) then you could measure the covariance between the x and y dimensions. If you calculate the covariance between one dimension and itself. “For each data item. Measuring the covariance between x and x. Covariance is such a measure.
In the last case.z) and cov(y. and the second is the M dimension. by the the difference between the y value and the mean of y. the hours studied. meaning that.z) you could calculate cov(x. the mark received. the first is the H dimension. If we had ended up with a negative covariance here. there is more than one covariance measurement that can be calculated. Imagine we have gone into the world and collected some 2dimensional data. from a 3 dimensional data set (dimensions x. So we have two dimensions. For example. say. for an ndimensional data set. then that indicates that both dimensions increase together. as it is here.y. then as one dimension increases. If the value is negative. then that would have said the opposite. in general.z). if the covariance is zero.9value and the mean of x.4 The covariance Matrix Recall that covariance is always measured between 2 dimensions. cov(x. and divide by (n1)”. Positive or Negative). so did the final mark. you can calculate n!/((n2)!2) different covariance values. we have asked a bunch of students how many hours in total that they spent studying PP. as the number of hours of study increased. it indicates that the two dimensions are independent of each other. . and the mark that they received. If the value is positive. the other decreases. So what does it tell us? The exact value is not as important as it’s sign (ie. If we have a data set with more than 2 dimensions. that as the number of hours of study increased the the final mark decreased. 2. Add all these up. In fact.y). How does this work? Let’s use some example data.
10 .
is the covariance value calculated between the 2nd dimension and the 3rd dimension. you see that the covariance value is between one of the dimensions and itself. using the usual dimensions x.a). the entry on row 2. An example. then the matrix has n rows and columns (so is square) and each entry in the matrix is the result of calculating the covariance between two separate dimensions. the definition for the covariance matrix for a set of data with n dimensions is: Where is a matrix with n rows and n columns. So. the covariance matrix has 3 rows and 3 columns. These are the variances for that dimension. and how they can be defined. I assume in this tutorial that you are familiar with matrices.b) = cov(b. y and z.g. column 3. Then. and is the xth dimension. and the values are this: Some points to note: Down the main diagonal. . All that this ugly looking formula says is that if you have an ndimensional data set. E. the matrix is symmetrical about the main diagonal. We’ll make up the covariance matrix for an imaginary 3 dimensional data set. The other point is that since cov(a.11A useful way to get all the possible covariance values between all the different dimensions is to calculate them all and put them in a matrix.
Then you can see that if there were a vector that lay on the line y=x. given an n*n matrix that does have eigenvectors. can be thought of as a transformation matrix. And. Why is this? Well.5 Eigenvectors As you know. when multiplied on the left. there are 3 eigenvectors. Consider the two multiplications between a matrix and a vector in Figure1. (0.0) to the point (3. would be an eigenvector of that transformation matrix. the resulting vector is not an integer multiple of the original vector. you can multiply two matrices together. the example is exactly 4 times the vector we began with.122. the square one. there are n of them. whereas in the second example. The vector (from the second example multiplication) represents an arrow pointing from the origin. provided they are compatible sizes. because it wouldn’t matter how long the vector was). it’s reflection it itself. Imagine a transformation matrix that. If you multiply this matrix on the left of a vector. In the first example. What properties do these eigenvectors have? You should first know that eigenvectors can only be found for square matrices. The other matrix. not every square matrix has eigenvectors. This vector (and all multiples of it. reflected vectors in the line y=x. And.2) . the answer is another vector that is transformed from it’s original position. . the vector is a vector in 2 dimensional space. It is the nature of the transformation that the eigenvectors arise from. Given a 3*3 matrix. Eigenvectors are a special case of this.
Notice how. This is important because it means that you can express the data in terms of these perpendicular eigenvectors. as in Figure 2. I still get the same multiple of it as a result. all the eigenvectors of a matrix are perpendicular. By the way.13 Figure 1: Example of one Eigenvector and one nonEigenvector Figure2 : Example of how a scaled Eigenvector is still an Eigenvector Another property of eigenvectors is that even if I scale the vector by some amount before I multiply it. no matter how many dimensions you have. ie. is orthogonal. in fact.6 Eigenvalues Eigenvalues are closely related to eigenvectors. Lastly. not changing it’s direction. instead of expressing them in terms of the and axes. 2. another word for perpendicular. we saw an eigenvalue in Figure 2. in maths talk. all you are doing is making it longer. the amount by which the original vector was . in both those examples. at right angles to each other. This is because if you scale a vector by some amount.
3). Figure 3: formation of the face’s vector from the face’s image 2. 2.14scaled after multiplication by the square matrix was the same? In that example. The basis of the image space is composed of the following vectors: .8 Image Space The face vector described in the previous section belongs to a space. we would always get 4 times the scaled vector as our result (as in Figure 2. which is an image. No matter what multiple of the eigenvector we took before we multiplied it by the square matrix. the space of all images whose dimension is w by h pixels. This space is the image space. as shown on the figure 3. Each pixel is coded by one vector component. 4 is the eigenvalue associated with that eigenvector.the rows of the image are placed each beside one another. the number of components of this vector will be w*h. can be viewed as a vector. The construction of this vector from an image is performed by a simple concatenation . the value was 4. If the image’s width and height are w and h pixels respectively.7 Face viewed as a vector A face.
all the face vectors are located in a very narrow cluster in the image space. . Figure 5: Image Space and face cluster Hence. The basis vectors of this face space are called the principal components. etc. The task presented here aims to build a face space which better describes the faces. a mouth. a nose. the full image space is not an optimal space for face description.15 Figure 4: Image space’s basis All the faces look like each other. They all have two eyes. as shown in the figure 5. located at the same place. Therefore.
and each pixel depends on its neighbours. The goal of the method presented here. Principal Components Analysis aims to catch the total variation in the set of the training faces. Of course. So. And when many observations. or faces. The dimension of the face space cannot be determined. is to reduce the dimension of a set or space so that the new basis better describes the typical ‘models’ of the set. but it is sure that it is to be far less than that of the image space. the dimension of the face space is less than the dimension of the image space.16 The dimension of the image space is w*h. Principal Components Analysis. Components in this face space basis will be uncorrelated and will maximise the variance accounted for in the original variables. and to explain this variation by a few variables. In our case the ‘models’ are a set of training faces. have to be processed the dimensionality reduction is of first importance. an observation described by a few variables is easier to handle and easier to understand than if it was defined by a huge amount of variables. all the pixels of a face are not relevant. The fact that it reduces the dimension is important. In fact. The new basis will be constructed by linear combination. .
Since patterns in data can be hard to find in data of high dimension. and expressing the data in such a way as to highlight their similarities and differences.17 Chapter 3 Principal Components Analysis Finally we come to Principal Components Analysis (PCA). and the reason why I have chosen this is so that I can provide plots of the data to show what the PCA analysis is doing at each step. The data I have used is found in Figure 3. PCA is a powerful tool for analysing data. you have to subtract the mean from each of the data dimensions. without much loss of information. The other main advantage of PCA is that once you have found these patterns in the data. So. where the luxury of graphical representation is not available. What is it? It is a way of identifying patterns in data. all the x . ie. by reducing the number of dimensions. 3. The mean subtracted is the average across each dimension. 3.1 Step 1: Get some data In my simple example.1. It’s only got 2 dimensions. along with a plot of that data. I am going to use my own madeup data set.2 Step 2: Subtract the mean For PCA to work properly. This chapter will take you through the steps you needed to perform a Principal Components Analysis on a set of data. and you compress the data.
values have y values have . and all the = subtracted from them. This produces a data set whose mean is zero.18< (the mean of the x values of all the data points) subtracted.
There are no surprises here. original data on the left.3 Step 3: Calculate the covariance matrix Since the data is 2 dimensional. we should expect that both the x and y variable increase together. . and a plot of the data 3.19 Figure 6: PCA example data. since the nondiagonal elements in this covariance matrix are positive. so I will just give you the result: So. the covariance matrix will be 2*2. data with the means subtracted on the right.
here are the eigenvectors and eigenvalues: It is important to notice that these eigenvectors are both unit eigenvectors ie. most maths packages. Their lengths are both 1. This is very important for PCA. I will show you why soon. On top of the data I have plotted both the eigenvectors as well. they two variables do indeed increase together. more importantly. when asked for eigenvectors. they are perpendicular to each other. As stated in the eigenvector section. So what do they mean? If you look at the plot of the data in Figure 7 then you can see how the data has quite a strong pattern. but luckily. As expected from the covariance matrix. as they tell us useful information about our data.20 3. These are rather important. They appear as diagonal dotted lines on the plot. they .4 Step 4: Calculate the covariance matrix Since the covariance matrix is square. will give you unit eigenvectors. But. In the meantime. we can calculate the eigenvectors and eigenvalues for this matrix.
It is the most significant relationship between the data dimensions.5 Step 5: Choosing components and forming a feature vector Here is where the notion of data compression and reduced dimensionality comes into it. less important. See how one of the eigenvectors goes through the middle of the points. by this process of taking the eigenvectors of the covariance matrix. the eigenvector with the larges eigenvalue was the one that pointed down the middle of the data. we have been able to extract lines that characterize the data. . like drawing a line of best fit? That eigenvector is showing us how these two data sets are related along that line. but are off to the side of the main line by some amount. The second eigenvector gives us the other. 3. The rest of the steps involve transforming the data so that it is expressed in terms of them lines. So. pattern in the data. If you look at the eigenvectors and eigenvalues from the previous section. In our example. In fact. you will notice that the eigenvalues are quite different values.21provide us with information about the patterns in the data. it turns out that the eigenvector with the highest eigenvalue is the principle component of the data set. that all the points follow the main line.
If you leave out some components. This gives you the components in order of significance. and then you choose only the first eigenvectors. if you like. if you originally have n dimensions in your data. To be precise. the next step is to order them by eigenvalue. you can decide to ignore the components of lesser significance. Now. In general. you don’t lose much. and so you calculate n eigenvectors and eigenvalues. but if the eigenvalues are small. You do lose some information. the final data set will have less dimensions than the original. highest to lowest. then the final data set has only dimensions. .22 Figure 7: A plot of the normalised data (mean subtracted) with the eigenvectors of the covariance matrix overlayed on top. once eigenvectors are found from the covariance matrix.
we can choose to leave out the smaller. which is just a fancy name for a matrix of vectors. and is also the easiest. we have two choices. and the fact that we have 2 eigenvectors. and forming a matrix with these eigenvectors in the columns. We can either form a feature vector with both of the eigenvectors: or. less significant component and only have a single column: 3. Once we have chosen the components (eigenvectors) that we wish to keep in our data and formed a feature vector. This is constructed by taking the eigenvectors that you want to keep from the list of eigenvectors.6 Step 6: Deriving the new data set This is the final step in PCA.23What needs to be done now is you need to form a feature vector. Given our example set of data. .
with data items in columns. Our original data set had two axes. transposed. What will this give us? It will give us the original data solely in terms of the vectors we chose. but the equations from here on are easier if we take the transpose of the feature vector and the data first. ie. If these axes are perpendicular. where RowFeatureVector is the matrix with the eigenvectors in the columns transposed so that the eigenvectors are now in the rows. the new data is only in terms of the vectors that we decided to keep. the data items are in each column. and dimensions along rows.24we simply take the transpose of the vector and multiply it on the left of the original data set. ie. In the case of when the new data set has reduced dimensionality. We have left some of the eigenvectors out. FinalData is the final data set. We have changed our data from being in terms of the axes x and y . and RowDataAdjust z is the meanadjusted data transposed. and now they are in terms of our 2 eigenvectors. so our data was in terms of them. rather that having a little T symbol above their names from now on. This was why it was important that eigenvectors are always perpendicular to each other. with each row holding a separate dimension. It is possible to express data in terms of any two axes that you like. then the expression is the most efficient. I’m sorry if this sudden transpose of all our data confuses you. x and y. with the most significant eigenvector at the top. .
So. we get the data and the plot found in Figure 8. rotated so that the eigenvectors are the axes. The other transformation we can make is by taking only the eigenvector with the largest eigenvalue. I have done the final transformation with each of the possible feature vectors. In the case of keeping both eigenvectors for the transformation. you will notice that this data set is exactly the first column of the other. I have also plotted the final points to show how they relate to the components. . it would be 1 dimensional. and would be points on a line in exactly the x positions of the points in the plot in Figure 8. As expected. If you compare this data set with the one resulting from using both eigenvectors. This plot is basically the original data. if you were to plot this data. which is the other eigenvector. This is understandable since we have lost no information in this decomposition. it only has a single dimension. The table of data resulting from that is found in Figure 9. I have taken the transpose of the result in each case to bring the data back to the nice tablelike format. We have effectively thrown away the whole other axis.25To show this on our data.
. and a plot of the new data points.26 Figure 8: The table of data by applying the PCA analysis using both eigenvectors.
27 Figure 9: The data after transforming using only the most significant eigenvector So what have we done here? Basically we have transformed our data so that is expressed in terms of the patterns between them. Now. Initially we had the simple x and y axes. where the patterns are the lines that most closely describe the relationships between the data. In the case of the transformation using both eigenvectors. the values of the data points tell us exactly where (i. But the singleeigenvector decomposition has removed the contribution due to the smaller eigenvector and left us with data that is only in terms of the other. This is fine. This is helpful because we have now classified our data point as a combination of the contributions from each of those lines. but the x and y values of each data point don’t really tell us exactly how that point relates to the rest of the data. above/below) the trend lines the data point sits. .e. we have simply altered the data so that it is in terms of those eigenvectors instead of the usual axes.
E ig e n fa c e s : e a c h c o lu m n i s a 4 0 9 6 com ponent r e p r e s e n tin g a n e ig e n fa c e . P C A S to r e d c o m p o n e n t s o f t h e tr a in in g f a c e s in th e fa c e s p a c e (3 0 c o m p o n e n ts p e r fa c e ) .28 CHAPTER 4 Block Diagram T r a in in g fa c e s : e a c h c o lu m n is a 4 0 9 6 c o m p o n e n ts v e c to r r e p r e s e n tin g a fa c e . T ra n s p o s e W h ic h s t o r e d fa c e is t h e n e a r e s t ? R e s u lt T e s t fa c e ( 4 0 9 6 p ix e ls ) T e s t f a c e 's c o m p o n e n ts in t h e fa c e s p a c e (3 0 c o m p o n e n ts ) Block Diagram of the Project .
Where I is the array in which image is stored.g. tif.29 CHAPTER 5 Implementation in MATLAB We have implemented the system in MATLAB as it provides the wide range of operations through its Image Processing Toolbox. gif etc. pgm.jpg’).1 Application of PCA on MATLAB Now. faces are obtained in MATLAB.1. 5. Imread command is used to read an image from the file and stores it in an array. 5. .1. E. Using imread command. The other file formats can also be used like bmp.1.1 Training Set 5. I = imread(‘face. Here JPEG is the file format.1 Reading of an Image The first step is to obtain a set of faces used for recognition. Also. let us discuss how PCA is applied on MATLAB. coding is easy in MATLAB because of many builtin functions and we need only a single line command.
305. each column represents one image and that’s how we calculate mean of each image. first we take mean and standard deviation of each image.2 Normalization of Images After obtaining a set of faces.1. Here mean is calculated as mean(matrix. dim) dim=2 i. Normalization is necessary to reduce errors due to lightening conditions. we normalize each image.e. In our coding.1. For normalization.1. normalization is a process that changes the range of pixel intensity values. Then by using these mean and standard deviation values. we need to normalize all images i. Normalization is a linear process.e. Std(matrix) calculates standard deviation of each image. we find a mean image. taking mean row wise in order to take mean of every pixel of all images. so we need only single command mean(matrix) calculates mean columnwise. In image processing. For mean and standard deviation. faces. Mean image is constructed by taking mean of all corresponding pixels of all images. builtin functions are already in MATLAB.3 Mean Image After normalizing faces. 5.1. .
The covariance of a variable with itself is the variable’s variance. the covariance matrix is a matrix of covariance between elements of a vector. μk = E(Xk). Obtaining eigen values is the basically the PCA (Principal Components Analysis). After normalization of images.1..j) element is the covariance between Xi and Xj. It is the natural generalization to higher dimensions.e.315.1.4 Covariance and Eigen Vectors The covariance between two variables equals the correlation times the product of the variables’ standard deviations. then the covariance matrix is defined as: The (i. If X is a column vector with n scalar random variable components. We say that is an eigen value of A if there exists a nonzero vector x such that . and μk is the expected value of the kth element of X. In statistics and probability theory. we calculate covariance of images and then determine its eigen vectors. i. of the concept of the variance of a scalarvalued random variable.
i.1.32where x is called an eigenvector. we calculate the weight of each image in the training set.5 Eigen Faces After determining eigen vectors and sorting them. indices] = sort(eigen values) Then by applying normalization formula to sorted eigen vectors. The wait is calculated by dot product of eigen faces and normalized images.1. This is our achievement of obtaining training set.1. In MATLAB. 5. value] = eig(matrix) where vector represents eigen vector and value represents eigen value.e. We can determine eigen vectors and eigen values by single command in MATLAB. images) . will be more distinguishing. [S. sorting is done in ascending order. [vector. we determine eigen faces. dot product is taken by dot(eigen faces. we get eigen faces. We sort the eigen values and also store their previous indices.6 Weight of an Image When we obtain the training set. 5. The sorting is done in ascending order because eigen faces with bigger eigen values will explain more of the variation in the set of faces.1. By default.
. we find the weight of the input image in the same manner as discussed above. Next.1 Euclidean Distance Euclidean distance is the “ordinary” distance between the two points. The image is user input for which we use command input (‘ ’) to take input from user. After that. Here the dot product is taken between eigen faces and difference calculated above. We apply the same procedure of normalizing image as applied on given set of images. We set a threshold value that identifies that the face is known or unknown or it really the face or not.335. we calculate the dot product between eigen faces and the input image. Then. This is actually the Face Space Representation of the input image. The Euclidean distance between two points and is In MATLAB. mean and eigen faces. we calculate the difference between input image and the mean image obtained from set of given images. norm(image) then we find maximum and minimum values of the distance between input image and each image the training set. we calculate Euclidean distance by using the command norm.1. Using this dot product. we reconstruct the input image. 5.2 Recognition Procedure First we read an image which is to be recognized.2.1.
we determine that the face is known or unknown and whether it is face or not.2 Results of Face Recognition We set a threshold of maximum and minimum values of Euclidean distance and with the help of these maximum and minimum values.345. Lets take some test cases: If the face is known then result will be Maximum Value = 14827 Minimum Value = 11960 .
we consider the case where face is unknown Maximum Value = 14506 Minimum Value = 13321 .35 Next.
36 In last. If the maximum distance is within 15000 and minimum distance is within 12000 then it is a known face. it is observed that if the distance(min) exceeds 15000 then it is not a face and if the maximum distance is within 15000 and minimum distance exceeds 12000 then it is face but unknown. . we consider the case when recognized object is not a face Maximum Value = 17072 Minimum Value = 15260 From the above discussion.
It’ll remove flexibility in algorithm. userfriendly and interactive. ActionScript is designed keeping in mind that it’ll be used to grab data from other sources and present that. Code the algorithm directly in Macromedia Flash’s ActionScript 3. . Use some library for communication between MATLAB and Java and then write code normally as done in normal Java programs. Hardcoding the algorithm in any language isn’t a good idea. etc. Coding it using ActionScript is worst because ActionScript is not so powerful. To provide even better GUI we have to connect it to Macromedia Flash. Write the modified Java instructions right into the MATLAB IDE because MATLAB itself runs on a JVM (Java Virtual Machine). Code the algorithm in some other convenient language and then connect it to Macromedia Flash using appropriate channels like XML sockets.37 Chapter 6 Final Implementation In this phase we have to implement the algorithm in some language and compile a binary file in order to make the algorithm more useable. We can adopt two approaches: 1. Code the algorithm in MATLAB and interface it with Macromedia Flash 2. streams. We’ve decided to use Java if we’ll use any programming language for convenience. 2. It is interpreted language hence it’s slow. To connect MATLAB to Java we have two approaches: 1.
you use 'single quotes' where you use "double quotes" in java. but you must make some changes in syntax. The following is a list of those that come to mind: • • • In MATLAB. you do not need to type "new"objects are created as needed. you could type: import javax. To use a java class. This is unnecessary in MATLAB. . For example. Keep the algorithm in MATLAB because it’ll provide us more flexibility if we need to change it. Use Java to communicate with MATLAB and then provide data to Macromedia Flash.38The options we’ve opted are: 1. In this context Java will be acting as a proxy. We’re not yet sure whether will we write Java code right into the MATLAB IDE or connect it using any library. You can then use any of these classes. Pick the data using XML sockets. In MATLAB. you must first import it. Use Macromedia Flash at presentation layer.swing. 2. 3.1 Connecting Java and MATLAB The MATLAB desktop runs a java virtual machine.*. Following is the procedure to write inline Java code in MATLAB: 6. In java you call a routine with no inputs by putting () after its name.
39• In MATLAB you're not required to put semicolon in the end of every statement (when only one statement is written on one line).0.swing.hidden.layout=java.alignmentX=null.* MATLAB Response: [nothing] User command: J = JFrame('Hi there') MATLAB Response: J= javax. try this: User command: import javax.invalid.preferredSize=].alignmentY=null.invalid.BorderLayout.maximumSize=.swing.normal.minimumSize=. title=Hithere!.JRootPane[.swing.JRootPane$RootLayout.swing. rootPane=javax.awt. rootPaneCheckingEnabled=true] . border=.JFrame[frame0.defaultCloseOperation=HIDE_ON_CLOSE.flags=385.0.0.0.0x0. For example.0x0.resizable. layout=javax.
0.horizontalAlignment=LEADING.0x0.swing. border=.swing. MATLAB Response: L = javax.flags=9.maximumSize=.0.swing.preferredSize=] . verticalAlignment=CENTER.JPanel[null.40User command: L = JLabel('A Label').invalid. layout=javax.flags=0.alignmentY=null.labelFor=.defaultIcon=. text=Hi there!.alignmentY=null.0.iconTextGap=4.0x0.preferredSize=.minimumSize=.JRootPane$1.verticalTextPosition=CENTER] User command: P = J.JLabel[.invalid.maximumSize=.0. border=.minimumSize=.contentPane. horizontalTextPosition=TRAILING.0.getContentPane MATLAB Response: P = javax.alignmentX=0. disabledIcon=.alignmentX=null.
minimumSize=.200).alignmentY=null.iconTextGap=4.0x0.setVisible(1) MATLAB Response: [A window frame appears captioned: "Hi there" appears with a label Label"] in it saying: "A .disabledIcon=.JLabel[.verticalTextPosition=CENTER] User command: J.maximumSize=.add(L) MATLAB Response: ans = javax.41User command: P. text=Hi there!.labelFor=.alignmentX=0.0.flags=0.verticalAlignment=CENTER.0.horizontalAlignment=LEADING . defaultIcon=. MATLAB Response: [nothing] User command: J.invalid.0.setSize(200.horizontalTextPosition=TRAILING. border=.swing.preferredSize=.
There are two things that you must get working in order to do this.3. For example. For information on how to locate "classpath.1 VectorChooser.3.txt" contains the directories in which you class files reside.1" to my call to javac. . you must make sure that the file "classpath.". so changing to the correct directory should work. you can compile a class VectorChooser.java Note: Code of VectorChooser. It might be necessary to add the flag "target 1. • You must tell MATLAB where to look for classes.txt which does contain ".java is given on the following four pages. To do this.txt" and create your own (you probably put it in your home directory or a directory called~/MATLAB) In my current installation.java (whose code is given below) and typing: javac target 1. then only way I can get MATLAB to read java classes is by starting MATLAB in the directory in which they reside • MATLAB does not necessarily accept code from the latest compilers.42You can also import your own classes. There is a default classpath.
0).event. BoxLayout. i++) { sliders[i] = new JSlider(JSlider.swing.1.VERTICAL. contentPane.java: import java. sliders[i].1 Code of VectorChooser.X_AXIS)).setMajorTickSpacing(10). . i < dimension.*.setMinorTickSpacing(1).*. import javax. 10.awt. sliders = new JSlider[dimension].swing. JPanel contentPane = new JPanel(). public class VectorChooser extends JFrame { JSlider sliders[]. import javax.setLayout(new BoxLayout(contentPane. for (i = 0.*. this.436.awt. int dimension. int i. public VectorChooser(int dimension) { super("Vector Chooser"). import java.dimension = dimension. 0.*. sliders[i].event.
} contentPane.setPaintLabels(true).setBorder( BorderFactory. sliders[i]. 10)). Integer converter. i < dimension.10.add(sliders[i]). setContentPane(contentPane).0)).doubleValue().setBorder(BorderFactory.10. contentPane. i++) { converter = new Integer(getOne(i)). } .createEmptyBorder(10. ret = new double[dimension]. ret[i] = converter. for (i = 0.10. } public double[] getAll() { double ret[]. sliders[i].createEmptyBorder(0.0. int i. } return ret.44sliders[i].setPaintTicks(true).
} else { for (i = 0. int i.intValue())."). } } } public int getOne(int i) { int ret.println("i must be between 0 and dimension1"). System. i < dimension.getValue().err. if (values.println("wrong number of values.45public void setAll(double values[]) { Double converter.converter.length != dimension) { System. } else { ret = 1. if ((i >= 0) && (i < dimension)) { ret = sliders[i]. i++) { converter = new Double(values[i]). setOne(i. } . } return ret.err.
46 public void setOne(int i.setVisible(true). vc. int value) { if ((i >= 0) && (i <= dimension)) { sliders[i].setValue(value).err.println("i must be between 0 and dimension1"). vc. } } Let's now give VectorChooser a spin: User command: . } } public static void main(String[] args) { VectorChooser vc = new VectorChooser(4). } else { System.pack().
0x0.defaultCloseOperation=HIDE_ON_CLOSE.rootPaneCheckingEnabled=true] User command: v.0.invalid.alignmentX=null.0. layout=javax.swing.title=Vector Chooser. rootPane=javax.invalid.0x0.swing.0. preferredSize=]. alignmentY=null.maximumSize=. normal.flags=385.hidden. layout=java.JRootPane[.0.JRootPane$RootLayout.setVisible(1) .BorderLayout.border=.47 import VectorChooser MATLAB Response: [nothing] User command: v = VectorChooser(4) MATLAB Response: v = VectorChooser[frame1.resizable.awt.minimumSize=.
getAll MATLAB Response: ans = 0 0 0 0 User command: v.setSize(250. 200) MATLAB Response: [The window’s size is changed to 250x200] User command: v.48MATLAB Response: [A window appears with nothing in it has its main panel’s size is 0x0] User command: v.4)) .setAll(10*rand(1.
getOne(0) .setOne(1.0) MATLAB Response: [nothing] User command: v.getAll MATLAB Response: ans = 9 2 6 4 User command: v.49MATLAB Response: [nothing] User command: v.
50MATLAB Response: ans = 9 Try moving the sliders. but that is a story for another day. . You'll see that MATLAB can read them! You can also have a java process running within MATLAB call MATLAB.
and then access it through the class loader. 6. and Matlab seems to provide this.51 6. Exiting and restarting MATLAB terminates and restarts the Java VM. This restriction exists because the Java VM does not provide a way to unload a Java class once it has been loaded. There is interest in having an interactive environment for selectively creating instances and invoking methods of Java classes.1 Explanation: 6. you kill the class loader and then create a new instance of it.2. you must exit and restart MATLAB in order to use the updated class definition. The rough idea is that you create a class loader for your class. However. quoting from the Mathworks web site regarding restrictions on unloading Java classes “If you load a Java class into MATLAB and.1. which then allows you to load the updated class. After you recompile. MATLAB will not know about it until you quit and restart MATLAB. which then reads the recompiled class.1 Loading and Reloading a Java Class from Matlab Matlab has a facility for creating instances of Java classes and for invoking methods on those instances. if you recompile your java class.2 Recompiling Classes Unfortunately. modify and recompile the class. Unfortunately. sometime later. there’s a cure for this.2.” .
52No combination of import or clear commands from the Matlab environment works because this restriction is a characteristic of the Java VM, that creating the first object instance of a class loads that class and once a class is loaded it stays loaded. The reasons why Java has to be that way are discussed on the SUN web site. Java has a facility called a class loader which may allow reloading a compiled class according to a pattern. The Java runtime has a default class loader employed when creating an object instance with the new operator. Any object created in that fashion along with the class loaded to create that object go in the namespace of that default class loader, and that namespace is immutable – you can add classes to that namespace but you cannot take them away or reload them. Any new class loader that you create with a ClassLoader object establishes a new name space into which you can load classes and create objects. That new name space is also immutable, but every time you create a new ClassLoader object instance, you create a fresh namespace that allows loading a recompiled class and seeing the changes. You can simply overwrite or set to null references to old ClassLoader object instances to let them be garbage collected, but you don't need to force garbage collection because each new ClassLoader object starts from fresh. Objects created with classes loaded by the new class loader can only be accessed using the Java reflection API – you can't get at them in the manner of objects created by the new operator because they are in a namespace not accessible by the regular means. The reflection API is the way of inspecting objects and invoking methods on those objects at runtime. This shouldn't be a problem because Matlab invokes methods on Java objects using reflection anyway. But it turns out that for whatever reason, Matlab will not recognize instances of type Object created in a new class loader namespace as valid Java
53objects. Such an object can be accessed in Java without reflection by having an interface or base class in the default namespace and by casting the class loadercreated object to that interface or base class. With Matlab, that doesn't work either. What does work is to create a proxy object in the default namespace to return to Matlab, and to have the proxy object call the corresponding methods of the target object that lives in the class loader namespace. Class Proxy allows creating and configuring a proxy object at runtime. The ingredients are a class called ClassLoad to create an object instance inside the namespace of a new class loader instance as well as create the proxy object to allow Matlab to see that object, a public interface class called InPlace defining the methods Matlab is able to invoke on that object, and a class called SineFilter that implements that interface. ClassLoad does all this at runtime so it does not need to be changed if you substitute a new interface and a new target class for InPlace and SineFilter – InPlace and SineFilter may be given different names. InPlace defines an interface which is not reloadable without exiting and restarting Matlab, but once the interface is defined, class SineFilter can be recompiled and the changes will be visible from a Matlab session. If this system is used in a classroom setting, ClassLoad is supplied by the instructor and does not change, InPlace can be supplied by the instructor or by the student to specify an interface, and it can only change between Matlab session, and SineFilter can be supplied by the student as part of completing an assignment. There are also some restrictions on directories where files can go. My setup puts each student account on a virtual network drive F: with F:\matlab the default work directory for student Matlab projects. The files ClassLoad.java and InPlace.java can go in that directory, but the file SineFilter.java cannot go there if I want to be able to reload that
54class. F:\matlab is on the default Java classpath, and any classes found there will be loaded with the default class loader, defeating what we are trying to accomplish. I put SineFilter.java in F:\matlab\myjava. When compiling it, I need to tell it where class InPlace is found, so from F:\matlab\myjava I invoke javac classpath .. SineFilter.java which tells the Java compiler to look for the next directory up (.. same as F:\matlab) to find InPlace.class. From the Matlab command window, one may invoke >> cl = ClassLoad('F:\\matlab\\myjava/') to create a reloadable object from a class found in F:\matlab\myjava. Note the peculiar syntax (required by Java) for specifying this directory. Creating an object instance is as simple as >>sinegen = cl.NewInstance('SineFilter') I can create the first 4 samples of a cosine wave of the default frequency of 100 Hz, peak value 1, and phase 0 for a sampling frequency of 22.05 kHz by >>sinegen.Init(1.0/22.05) >>sinegen.Apply([0.0, 0.0, 0.0, 0.0]) The Apply() method takes an input array and adds the sine wave to that array – that is why I supply a 4element 0valued input array to see 4 samples of the cosine function.
55I can edit SineFilter.java (say, to change the default magnitude from 1.0 to 2.0), recompile it, repeat >> sinegen = cl.NewInstance('SineFilter) >>sinegen.Init(1.0/22.05) >>sinegen.Apply([0.0, 0.0, 0.0, 0.0]) to see the output at twice the amplitude. By the way, to produce a 2000 Hz sine wave with default amplitude and phase I can invoke >>sinegen.SetParams([2000.0]); >>sinegen.Init(1.0/22.05) >>sinegen.Apply([0.0, 0.0, 0.0, 0.0]) (SetParams() needs to precede Init()), or to produce a 440 Hz sine wave of amplitude 1.5 >>sinegen.SetParams([440.0,1.5]); >>sinegen.Init(1.0/22.05) >>sinegen.Apply([0.0, 0.0, 0.0, 0.0])
following is the procedure: There’s an Java archive named JLab for this purpose. JMatLink has some memory leak issues. This Java library was developed so that Java developers may have the power of Matlab available to them.56If we had decided to use any library to connect MATLAB to regular Java classes. is not compatible with the latest Matlab header files and the Java code is not packaged (meaning all calling code has to reside in the default package. author = "Toft. JLab has been developed and tested in a Windows environment with the Suns JDK 1. it must be referenced as: @misc{Toft2005. This tool requires machine native codes to run. most notably JMatLink developed by Stefan M? JMatLink was inspiration for developing this tool. E. If this software library is used. Matlab was a fantastic prototyping environment but any results would still have to be implemented in Java. I had to agree.4 and Matlab 7 R14. however. title = "{JLab Connecting Java to Matlab}. The software I write for research lends itself to Java. To overcome this barrier I've created this Java library which allows you to execute commands from Java as if you were at the Matlab prompt and send and receive matrices to and from Matlab. . I. new as of JDK 1.4). Other similar tools exist. Colleagues and advocates of Matlab encouraged me to take it up.". there are many occasions when prototyping Java code with complex algorithms depending on other peoples code can be time consuming and a thankless task. as such the binary distributions made available on this page are for MS Windows platforms only. I have made the method names similar to those used in JMatLink as I expect JMatLink users are the most likely users of this library.
html}". int evalString(java. 6. int[][] getIntMatrix(java. . 2.lang.lang.com/abdullah/index.”. howpublished = "NED University of Engineering and Technology. void closeEngine() Closes the Matlab engine for the MatLabEngine instance.abcxyz123. 4. 3.57\url{http://www. 5. static MatlabEngine getEngineInstance() Provides access to the single instance of MatLabEngine. double[][] getDoubleMatrix(java.String varName) Retrieve a named matrix as a 2D array of doubles. year = "2006" } The method summary of the MatlabEngine class is: 1.String varName) Retrieve a named matrix as a 2D array of ints.lang.String cmd) Evaluates a command in the Matlab engine. void openEngine() Opens the Matlab engine for the instance of MatLabEngine. Computers & Information Systems Department.
int[][] matrix) Put a integer precision matrix into the Matlab workspace. double[][] matrix.String varName. void putDoubleMatrix(java.String varName.lang. 8.String varName. double[][] matrix) Put a double precision matrix into the Matlab workspace. 10.String varName.lang.lang. boolean check) Put a integer precision matrix into the Matlab workspace. . void putDoubleMatrix(java. void putIntMatrix(java. 9. boolean check) Put a double precision matrix into the Matlab workspace.lang. int[][] matrix. The next step is to connect the Java classes to Macromedia Flash.587. void putIntMatrix(java.
By default. beans. Flash MX 2004. however. or published web services. and to start. Flash offers a scripting EMCAbased language called ActionScript and a palette of components. here's a bit about Flash. and more are offered in the newest version. cross platform solutions. video integration improvements. Flash can be a great option. Both Flash versions can call Java code contained in JSPs. Connecting the two is often up to the Java developer. Both Flash and Java promote themselves as a crossdevice. you need to know your options on how to get across to Flash. Some Flash components are dataaware. you need Java. the Java code must be in the same subdomain as the Flash .3 Connecting Java to Macromedia Flash For an interface. For application developers. Developers can write functions and attach them to component events. it's not an option to replace business logic. Flash Professional also offers a new metaphor for designers in addition to its animation framebased timeline: form or screen based design.59 6. Flash Professional provides extras such as data and web service binding. For robust performance and enterprise capabilities. The components aren't as robust as Swing. In Flash MX 2004. and security. First. The newest Flash 7 player runs Flash movies developed with either tool. Macromedia offers two versions of their Flash development tool: Flash and Flash Professional. much like the listener model in Java. but they cover the basics for common interfaces. so they are natural partners. for the backend. for the first time. which will be helpful to application designers. servlets. query management. and device emulators.
.60movie. Here are some methods to send and receive Flash data from Java: from simplest to complex modes. On the java side. Getting information out of a formlike interface is easy with Flash. However. you can supply an xml policy file to allow other locations. or in another specified window.server. and then commit them at the end with a call to a JSP. and it attempts to load it in the same window. you could save the user's work. On the Flash side. "_blank".3. you can send a URL with parameters encoded in strings. but with the new version of Flash. in a frame. you call the URL: getURL("http://www."POST"). A drawback is that URL requests need somewhere to load a response page.com/thequiz. Of course. 6. You may not want this behavior in your design. URL encoding is the simplest model of calling a JSP or servlet. and sending information in that interface is often as simple as printing to an ‘out’ object. the backend Java code can contact other domains.jsp?question1=Yes&question2=No". For example. for a series of Flash frames. It could be ideal to popup a window or to be the final step in an application. On an event in Flash.1 URL Encoding Outbound. if the Flash session must reload. you simply parse the request parameters and process them. it loses the user's work. Java developers using Flash need to know how to do a few common tasks: receiving and sending Flash data and dealing with data type issues.
Here's what the ActionScript would look like in a situation where a JSP is called with a LoadVars object. you still have to follow URL encoding. but it doesn't unload your Flash movie.2 LoadVars Object As an improvement over straight URL encoding.61 6. showcase_desc = new LoadVars(). Session can be maintained if you use session objects in Java. . you can use a LoadVars object in the ActionScripting model to call Java code. and it's an asynchronous HTTP transmission. showcase_desc.getParameter("showcase_id"). All you have to do is have Java code waiting to collect the data. showcase_desc. On the java side.sendAndLoad("fillShowcasedesc.3. The JSP will make a query based on a showcase id number and return the results to an ActionScript called capture_desc. With a LoadVars object. Then you can write data back out to Flash: out.jsp". Here's the line for the JSP called above: String showcase_id = request. the code simply pulls off the parameters on the request object. It's a real exchange with a Java backend. You can use a GET or POST. allowing sending and receiving. "POST"). showcase_desc.showcase_id = showcase_id.onLoad = capture_desc. showcase_desc.println("&description" "=" showcase_desc).
it's helpful to change the Flash interface to indicate "loading" before requesting making the LoadVars request. it is. which is a real exchange with Java backend. If you are loading the Flash interface with data.62 Is it that simple? Yes. which can cause apparent hesitation. On the Flash side. The returned data to Flash can be loaded into the interface. the Flash interface waits for the HTTP response. you can get a response back on the LoadVars object on the success of the transaction and handle it. function capture_desc(success) { if (success == true) { showcase_description = "".description. showcase_description = showcase_desc. } . However.
but it can be quite handy. i<=dataList. basically.firstChild. Flash doesn't have a sophisticated parser or verifier. mainTag = this. for (i=0.childNodes.childNodes.length. if (mainTag.63 6. Flash can read XML as. dataList = new Array(). a long string set on the response object or XML files. function capture_showcase(success) { if (success == true) { mainTag = new XML(). and you have to write ActionScript to load the XML information. you can format the rows returned on a query as XML to load components.3. elementList = new Array().nodeName == "dataSet") { dataList = mainTag. . elementTag = new XML(). In the case of list components.3 XML Objects In the same vein as LoadVars.nodeName == "data") { elementList = dataList[i]. i ) { if (dataList[i]. you can send or request XML and manage it through an ActionScript object. For example. they can be easier to load with an XML object than a LoadVars object.
print( "" title "" ). the Java code writes out string data. out. if (elementType == "showcase_id") { ID = elementTag.nodeValue. In Flash Professional.setChangeHandler("showcase_change"). if you send and receive XML. .nodeValue.print( "" ).firstChild.print( "" showcase_id ""). elementType = elementTag. j<=elementList. out. }}}}} lstShowcase. out.length. out. the Java code takes on the larger role to correct the format and verify it. } Again.firstChild. and in the case of my example. there's more code that is not shown that handled a query and a resultset. No header on the XML is used. j ) { elementTag = elementList[j].64for (j=0.print( "").} if (elementType == "showcase_title") { Show_Title = elementTag. the request is an HTTP request. When you use XML objects.addItem(ID.} }lstShowcase. Of course. Show_Title).nodeName. you can use an XML connector object to bind XML sources with components.
onXML = processXML. On the Flash side. myConn = new XMLSocket. The XML transfer is faster this way.com".3. and the end of file marker is a single byte zero. 1025).65 6. you create an XMLSocket object.close(). myConn.myflashserver.connect("http://www. through port 1024 or higher. myConn. but it's the least secure method of communication. you'd write an ActiveScript function called processXML that would interpret the incoming XML document. The code is the same as any simple socket application: create a socket. The Flash XML documents are like a long string: it skips the XML header. myConn. The XML documents don't use a DTD. This connection is ideal for chat or gaming applications. and an inputstream and read your data into a stringbuffer: send data out on an outputstream through that socket. it's easy to communicate through XML Sockets. the onXML event is triggered. XML Sockets do have a couple of drawbacks. you can use a XMLsocket persistent connection. and when it receives XML. On the java side. In the above case. Not only that.4 XML Sockets Instead of using an XML object through HTTP. some firewalls will not .
Flash offers a protocol called Remoting. you can directly call methods on Java objects and transfer a variety of data types. AMF or Action Media Format. but you can install Remoting with any Java server. the Flash developer must install additional ActionScript libraries. (Don't forget to configure a web. 6. but since it is serialized. you can't have objects inside objects that you include. but Flash uses a proprietary. . you should consider Remoting. If you want to transfer more sophisticated data with faster responses.5 Remoting All of the previous methods basically transfer string information. To use Remoting.) Macromedia's JRun servers have Remoting installed. The gateway servlet acts as a factory for connections to Java objects. With Remoting. You can include Java objects on the ASObjects. Remoting uses HTTP or HTTPS. If you want security with more speed than LoadVars. You can use these mappings or you can create an ASObject and handle getting and setting data yourself.xml file. The gateway maps incoming data to target Java data types or to an ASObject. the task of designing how you want to handle data casting would be where you'd spend the most time.66allow this sort of connection .) On the server side. and maps outgoing data to target ActionScript data types or to an ASObject. optimized. (The new version of Flash Professional comes with these libraries. which are available for free from Macromedia. Connecting to Flash through Remoting is simple. binary format.3. a "gateway" servlet must be installed.
service. and create a connection. this).67 Object Mapping Chart ActionScript data type Number (primitive data type) Boolean (primitive data type) String ActionScript (AS) null undefined Ordered array Named array Date object XML object RecordSet Java data type Double Boolean String object Map null null ArrayList Map Date org. var gatewayConn = Netservices. and call the java method.createGatewayConnection().w3c. . get a service object. # include "NetServices. netServices.myJava".getService("com. in this case called handleCustomers(). var service = gatewayConn.dom Document RowSet On the Flash side. Results are sent to an ActionScript function. that you would write on the Flash side.setDefaultGatewayUrl("http://myhost/gateway").as". you have to include Remoting.getCustomers(new handleCustomers()).mycompany.
because you can use an ActionScript extension called DataGlue to simply the task of binding and formatting data for the interface. since it allows direct calls. you can use HTTPS for security purposes. With DataGlue. return cust.io. ASObject must be imported or Serializable be implemented on the class. public class service { public ASObject getCustomers(){ ASObject cust = new ASObject("custList"). To avoid problems.ASObject. "Anderson"). import flashgateway.68The Java code is simple. set up security policies on your Java classes to prevent wholesale access to your libraries. cust. } With Remoting.put("99".put("101". for example. but Remoting can expose some security concerns. Remoting makes development on the Flash side easier. cust. you can bind recordset objects and its formatting to Flash interface components with a couple of lines of code. With the . "Smith").
the Flash developer can use the Component Inspector and basically click through some tabbed dialog boxes and data bind interface components to published java web services or XML sources. instead of writing lines of ActionScript. They can use it tune the formatting too. by adding a feature that makes binding components to web services and XML sources as easy as filling out property sheets. . This feature is available with or without Remoting. it's a bit more work to create published web services. For the Java developer. In the Component Inspector. but it makes Java methods available to Flash development almost like a tag. Macromedia extends this idea into the authoring interface.69new Flash Professional 2004.
There's been a lot of talk about using Coldfusion or PHP to do the job. and together will make a successful partnership in a growing number of application architectures.70 6. it's worth it.3. The server is an additional product to purchase. which allows you to grow into new markets.6 Remoting with Communication Server If you use Remoting. you can enhance its performance by using Macromedia's Communication Server with it. The Java coding required is the same as Remoting without the Server. As you can see getting across to Flash with Java is so very easy. but if you employ a lot of video and audio. . but you may want to revisit your security plans. The first step is making a decision on how to connect. which is a TCP/IP protocol. but Java is a more robust language to architect a backend than PHP or Coldfusion tags. so you'll see good performance improvements in reporting interfaces. Also the Java APIs are cross platform. so you can't use HTTPS. as Flash's market continues to grow into the device area. and I hope this article's been a good survey for you. For example. Java and Flash are natural partners. it caches and polls data for changes. The Communication Server uses a proprietary protocol: RTMP. and using this combination a great example of MVC architecture. Java's library support would be key to making crossdevice Flash applications for handhelds. On the data side. The server offers the most efficient streaming of video and audio to Flash interfaces.
we can put our Java code directly into Matlab and connect it directly to Macromedia Flash. how to connect Java and Macromedia Flash including (but not limited to): • • • • • • URL Encoding LoadVars Object XML Objects XML Sockets Remoting Remoting with Communication Server The above options progress from most simple to complex and powerful. We’ve plenty of options. Macromedia JRun or RedHat JBoss. But since we know from previous data that Matlab is built on top of JRE (Java Runtime Environment) and has many builtin JIT Compilers. Since we’ll be using Matlab as our Java compiler and interpreter we can’t use “Remoting” as well as “Remoting with Communitaion Server” because they need Java classes running in a server environment like Apache Tomcat. XML Sockets is the fastest.4 Final Option we’ve opted So plenty of options and mechanisms are described above. etc.71 6. and we said we were going to do it using Matlab. . Interpreter. We’ll be running the Java commands in Matlab IDE so XML Sockets is the best option we can implement. Java and Macromedia Flash. Also among all of the above methods.
This description will be very simple and fast because all the necessary details are given in this chapter above.5 An illustration of the opted method A small and simple example of connecting Matlab to Macromedia Flash MX 2004 using Java is shown below. Step 2 Run (in Matlab): import java.io. To create a server socket who’d be listing on the port number 1026 of the local computer. To import all builtin Java Input/Output classes. Step 3 Run (in Matlab): import java. To import all builtin Java Network classes.*. Step 1 Start a new Matlab instance.*.net.72 6. Step 4 Run (in Matlab): ssock = ServerSocket(1026). .
Step 6 Now run Macromedia Flash MX 2004. Step 7 Create a new project. Step 9 Select this button and change its instance name to objBut.accept. .73Step 5 Run (in Matlab): sock = ssock. Step 8 Draw a Button components (bring it from the components pane). This command is used to listen to client request of connection. The cursor will be halted here until a client makes a connection and then will return a Socket object in variable sock.
} function processData(src) { trace (src).onData = processData.close().onXML(new XML(src)). 1026).74Step 10 Now click the blank scene area and extend the Actions panel shown in the above picture and write the following code: objBut. function receiveData() { myConn. // myConn.connect("localhost". this. } . myConn. receiveData). myConn = new XMLSocket.addEventListener("click".
0. Step 13 Now the function (accept) call in Matlab should be released with the output: sock = Socket[addr=/127.0.75 Step 11 Run the movie by pressing Ctrl+Enter.1. Step 12 Click the button labeled “Button”.port=4484.localport=1026] .
i. In response to this command Matlab says: os = java. my name is John!" /> .io.net.SocketOutputStream@170f98 So os is an object of java. The stream will be saved in variable os but it can only write one byte of data at a time. PrintWriter class. To have it. my name is John!"/>' Matlab says: str = <MESSAGE USER="John" TEXT="Hello.PrintWriter@1c221b2 Step 16 Define a string to send by a command like: str='<MESSAGE USER="John" TEXT="Hello. run the following command: out = PrintWriter(os) Matlab says: out = java.76Step 14 Now create a output stream from Matlab to send data to Flash by running the following command: os = sock.getOutputStream.net.SocketOutputStream class Step 15 To pass entire Strings we need a buffered output stream.e.
print(str) Step 18 Since the stream is buffered flush the stream using: out.77Step 17 Now send data to Flash using the socket using: out. you’ve got the output: Following is the snapshot of the Matlab’s workspace window at this time: .write(0) Step 20 Now look at the Flash window.flush Step 19 End the output by sending byte zero (0) using: os.
This research is going on for finding better techniques and there have been many good results. Face Recogntion is a new concept and everyday it gains more popularity and importance.78 CHAPTER 7 CONCLUSION Finally this discussion can be concluded as the project bears a good relation to various real world applications. Nowadays. in the field of recognition. The technique PCA which has been used in this project is also the most common technique and easy to implement. . Also. In future. Security is the major concern in everyday life such as human machine interfaces and image retrieval. this project can be enhanced for better performance.
Department of Computer Science.com . Gonzalez. www. USA. Pearson Education Press 7. 3. www. Pearson Education Press 6. Eddins. 2002 5.79 BIBLIOGRAPHY 1. Digital Image Processing. Gonzalez.google. Richard E. Maryland University. Woods.Mathswork. College Park. Steven L. Second Edition by Rafael C. Digital Image Processing by Rafael C.Wikipedia. A tutorial on Principal Component Analysis by Lindsay I Smith. Woods.com 8. Richard E. MD 20742.org 2. Face Recognition using Principle Component Analysis by Kyungnam Kim . www. Face Recognition Handbook by Jim and Dickens 4. February 26.
80 .