Ejemplo n.º 1
0
def recognition_image(image):
    desc = LocalBinaryPatterns(24, 8)

    model = pickle.load(open("models/model.save", 'rb'))

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    hist = desc.describe(gray)
    prediction = model.predict([hist])[0]

    return prediction
Ejemplo n.º 2
0
def get_dataset(image_path):
    dataset = []
    labels = []
    desc = LocalBinaryPatterns(24, 8)
    for img in image_path:
        image = cv.imread(img)
        gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
        hist = desc.describe(gray)
        dataset.append(hist)
        label = img.split(os.path.sep)[-2]
        labels.append(label)

    dataset = np.array(dataset, dtype="float")
    dataset = normalize(dataset)
    labels = np.array(labels)
    return dataset, labels
Ejemplo n.º 3
0
def recognition_images():
    # initialize the local binary patterns descriptor along with
    # the data and label lists
    desc = LocalBinaryPatterns(24, 8)

    model = pickle.load(open("models/model.save", 'rb'))

    # loop over the testing images
    for imagePath in paths.list_images("faces/testing"):
        # load the image, convert it to grayscale, describe it,
        # and classify it
        image = cv2.imread(imagePath)
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        hist = desc.describe(gray)
        prediction = model.predict([hist])[0]

        # display the image and the prediction
        cv2.putText(image, prediction, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1.0,
                    (0, 0, 255), 3)
        cv2.imshow("Image", image)
        cv2.waitKey(0)
Ejemplo n.º 4
0
from local_binary_patterns import LocalBinaryPatterns
from sklearn.svm import LinearSVC
from imutils import paths
import pickle
#opencv
import cv2

# initialize the local binary patterns descriptor along with
# the data and label lists
desc = LocalBinaryPatterns(24, 8)
data = []
labels = []

# loop over the training images
for imagePath in paths.list_images("faces/training"):
    # load the image, convert it to grayscale, and describe it
    image = cv2.imread(imagePath)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    hist = desc.describe(gray)

    # extract the label from the image path, then update the
    # label and data lists
    labels.append(imagePath.split("/")[-2])
    data.append(hist)

# train a Linear SVM on the data
model = LinearSVC(C=100.0, random_state=42)
model.fit(data, labels)

pickle.dump(model, open("model.save", 'wb'))