def apply_filter(self, image, grayscale=False): """ Apply the DFT filter to given image. :param image: PhloxAR.Image :param grayscale: if True, perform the operation on the gray version of the image, if False, perform the operation on each channel and the recombine then to create the result. :return: filtered image. """ if self.width == 0 or self.height == 0: warnings.warn("Empty filter. Returning the image.") return image w, h = image.size() if grayscale: image = image.to_gray() img = self._image if img.size() != image.size(): img = img.resize(w, h) filtered = image.apply_DFT_filter(img) return filtered
def __add__(self, other): if not isinstance(other, type(self)): warnings.warn("Provide PhloxAR.DFT object.") return None if self.size() != other.size(): warnings.warn("Both PhloxAR.DFT object mush have the same size.") return None numpy_array = self._narray + other._narray image = PhloxAR.core.image.Image(numpy_array) ret = DFT(array=numpy_array, image=image, size=image.size()) return ret
def predict(self, image): """ **SUMMARY** Predict the class of the image using trained face recognizer. **PARAMETERS** * *image* - Image.The images must be of the same size as provided in training. **RETURNS** * *label* - Class of the image which it belongs to. **EXAMPLES** >>> f = FaceRecognizer() >>> imgs1 = ImageSet(path/to/images_of_type1) >>> labels1 = ["type1"]*len(imgs1) >>> imgs2 = ImageSet(path/to/images_of_type2) >>> labels2 = ["type2"]*len(imgs2) >>> imgs3 = ImageSet(path/to/images_of_type3) >>> labels3 = ["type3"]*len(imgs3) >>> imgs = imgs1 + imgs2 + imgs3 >>> labels = labels1 + labels2 + labels3 >>> f.train(imgs, labels) >>> img = Image("some_image_of_any_of_the_above_type") >>> print f.predict(img) Save Fisher Training Data >>> f.save("trainingdata.xml") Load Fisher Training Data and directly use without trainging >>> f1 = FaceRecognizer() >>> f1.load("trainingdata.xml") >>> img = Image("some_image_of_any_of_the_above_type") >>> print f1.predict(img) Use CSV files for training >>> f = FaceRecognizer() >>> f.train(csvfile="CSV_file_name", delimiter=";") >>> img = Image("some_image_of_any_of_the_type_in_csv_file") >>> print f.predict(img) """ if not self.supported: warnings.warn("Fisher Recognizer is supported by OpenCV >= 2.4.4") return None if image.size() != self.imageSize: w, h = self.imageSize image = image.resize(w, h) cv2img = image.getGrayNumpyCv2() label, confidence = self.model.predict(cv2img) retLabel = self.labels_dict_rev.get(label) if not retLabel: retLabel = label return retLabel, confidence