# loop over the image and mask paths for imagen_entrenamiento in imagenes_entrenamiento: # load the image and mask image = cv2.imread(imagen_entrenamiento) target.append(imagen_entrenamiento.split("_")[-2]) #print imagen_entrenamiento.split("_")[-2] #print "." le = LabelEncoder() target = le.fit_transform(target) ################################################################################# # initialize the HOG descriptor hog = HOG(orientations=18, pixelsPerCell=(10, 10), cellsPerBlock=(1, 1), normalize=True) """ # load the image and convert it to grayscale image = cv2.imread(args["image"]) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # blur the image, find edges, and then find contours along # the edged regions blurred = cv2.GaussianBlur(gray, (3, 3), 0) # extract features from the image and classify it hist = hog.describe(blurred) direccion = le.inverse_transform(model.predict(hist))[0] #le.inverse_transform(model.predict(features))[0] print " Por favor: %s" % (direccion)
import mahotas import cv2 # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-m", "--model", required = True, help = "path to where the model will be stored") ap.add_argument("-i", "--image", required = True, help = "path to the image file") args = vars(ap.parse_args()) # load the model model = joblib.load(args["model"]) # initialize the HOG descriptor hog = HOG(orientations = 18, pixelsPerCell = (10, 10), cellsPerBlock = (1, 1), transform = True, block_norm="L2-Hys") # load the image and convert it to grayscale image = cv2.imread(args["image"]) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # blur the image, find edges, and then find contours along # the edged regions blurred = cv2.GaussianBlur(gray, (5, 5), 0) edged = cv2.Canny(blurred, 30, 150) cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = imutils.grab_contours(cnts) # sort the contours by their x-axis position, ensuring # that we read the numbers from left to right cnts = sorted([(c, cv2.boundingRect(c)[0]) for c in cnts], key = lambda x: x[1])
import mahotas import cv2 ap = argparse.ArgumentParser() ap.add_argument('-m', '--model', required=True, help='path to where the model will be stored') ap.add_argument('-i', '--image', required=True, help='path to the image file') args = vars(ap.parse_args()) model = joblib.load(args['model']) hog = HOG(orientation=18, pixelsPerCell=(10, 10), cellsPerBlock=(1, 1), transform=True) image = cv2.imread(args['image']) # image=imutils.resize(image,width=28,height=28) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (5, 5), 0) edged = cv2.Canny(blurred, 30, 150) (_, cnts, _) = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cnts = sorted([(c, cv2.boundingRect(c)[0]) for c in cnts], key=lambda x: x[1]) for (c, _) in cnts: (x, y, w, h) = cv2.boundingRect(c) if w >= 7 and h >= 20: roi = gray[y:y + h, x:x + w]