1. A method of recognizing an object in an image, comprising steps of: providing the image having the object, and encoding principal traits of the object in order to generate a first trait code; comparing the first trait code with data stored in a database so as to obtain a plurality of differences; wherein the database is constructed by steps of: collecting K images, wherein each object in each of the K images has M traits; classifying each of the M traits so that the each trait of the K objects is classified into ki trait patterns, wherein i=1, 2,. .. , M, and ki≦K; extracting N principal traits from the M traits, wherein each principal trait includes classified kj trait patterns, and wherein j=1, 2,. .. , N, and kj≦K; constructing a code book based on the N principal traits and the kj trait patterns; and finding a minimum of the plurality of differences.