Example #1
0
def getPrediction(q):
    # Open saved SVM model
    loaded_model = pickle.load(open("bin/src/model.sav", "rb"))

    while True:
        if not q.empty():
            # Pasamos la foto de la mano por el SVM
            item = q.get()
            # print("Se ha sacado 1 item, quedan {}".format(q.qsize()))
            item = np.float32(item) / 255.0
            item = cv.cvtColor(item, cv.COLOR_BGR2GRAY)
            data = hog(item)
            data = np.array([data])
            print(loaded_model.predict(data))
        img = cv.imread(dpath)
        if (len(img) != None):
            print(dpath + '   has been succesfully loaded!')

            img = img[8:199 - 8, 8:199 - 8]
            dim = (160, 160)
            img = cv.resize(img, dim, interpolation=cv.INTER_AREA)
            img = np.float32(img) / 255.0
            img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

            # cv.imshow('Imagen', img)
            # cv.waitKey(0)

            # The function hog will only accept 1 dimension images (Gray)
            X[(num - 1) * samp + i - 1] = hog(img)
            Y.append(l)
        else:
            print("Error! no image found")
            i = samp

# Now that we already have the variables well fit the VSM
X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2)

svclassifier = SVC(kernel='linear')
svclassifier.fit(X_train, Y_train)

Y_pred = svclassifier.predict(X_test)

print("\n\nCLASSIFIER 1: Linear\n\n")
print(confusion_matrix(Y_test, Y_pred))
Example #3
0
        'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z')

dim = (160, 160)
data = np.zeros(shape=(len(opts),2916))
num = 0

for o in opts:
    path = '../../../../asl_alphabet_test/asl_alphabet_test/{}_test.jpg'.format(o)

    img = cv.imread(path)
    img = img[8:199-8,8:199-8]
    img = cv.resize(img, dim, interpolation = cv.INTER_AREA)
    img = np.float32(img)/255.0
    img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    data[num] = hog(img)
    num=num+1


# # Now that we have our model we'll import some images to test the model outside the dataset
# img = cv.imread('../../../../fotoc.png')
# img = img[8:199-8,8:199-8]
# dim = (160, 160)
# img = cv.resize(img, dim, interpolation = cv.INTER_AREA)
# img = np.float32(img)/255.0
# img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
#
# # img2 = cv.imread('../../../../fotoj.png')
# # img2 = img2[8:199-8,8:199-8]
# # img2 = cv.resize(img2, dim, interpolation = cv.INTER_AREA)
# # img2 = np.float32(img2)/255.0
Example #4
0
    #Quitamos el fondo
    BackGround = backgroundRemoval(noFace,bg)
    #Binarizamos la imagen
    imbin = binarization(BackGround, H_LowThreshold, H_HighThreshold, S_LowThreshold, S_HighThreshold, V_LowThreshold, V_HighThreshold)
    #Situamos el Bounding box
    bnd, origbnd = Bounding(imbin,frame)


    # cv.imshow('Foreground',BackGround)
    # cv.imshow('User hand', bnd)
    cv.imshow('Bounding box', origbnd)

    # Pasamos la foto de la mano por el SVM
    bnd = np.float32(bnd)/255.0
    bnd = cv.cvtColor(bnd, cv.COLOR_BGR2GRAY)
    data = hog(bnd)
    data = np.array([data])
    print(loaded_model.predict(data))

    #teclas
    k = cv.waitKey(1) & 0xFF
    if k == ord('q'):#quit
        break
    elif k == ord('b'):#remove background
        print('Obtenemos nuevo background')
        bg = frame
    elif k == ord('s'):#capture skin
        print('Capturamos la piel del usuario')
        th = captureSkin(BackGround)
        # Asign calculated thresholds to used ones
        H_LowThreshold = th[0]
Example #5
0
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import classification_report, confusion_matrix
import pickle
import math
from _hog import hog

# Open saved SVM model
loaded_model = pickle.load(open("bin/src/model.sav", "rb"))

# Now that we have our model we'll import some images to test the model outside the dataset
img = cv.imread('../../../../fotoc.png')
img = img[8:199 - 8, 8:199 - 8]
dim = (160, 160)
img = cv.resize(img, dim, interpolation=cv.INTER_AREA)
img = np.float32(img) / 255.0
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

img2 = cv.imread('../../../../fotoj.png')
img2 = img2[8:199 - 8, 8:199 - 8]
img2 = cv.resize(img2, dim, interpolation=cv.INTER_AREA)
img2 = np.float32(img2) / 255.0
img2 = cv.cvtColor(img2, cv.COLOR_BGR2GRAY)

data = hog(img)
data2 = hog(img2)
data = np.array([data])
data2 = np.array([data2])
print(loaded_model.predict(data))
print(loaded_model.predict(data2))