Exemplo n.º 1
0
def getTemplatesInDirectory(dirMoves, dirName):
    Templates = []
    for i in range(len(dirMoves)):
        fileMoves = dirMoves[i]
        for move in fileMoves:
            x, y, z = get_xyz_of_move(move)
            magnitude = getMagnitude(x, y)
            shapeArray = createArray(magnitude, z)
            template = Template(dirName, shapeArray)
            Templates.append(template)
    return Templates
def getRecognizer(arrayOfzigzagMove, arrayOfPasses, arrayOfv):
    Templates = []

    # Templates.append(Template(shapeName, shapeArray))
    for allMoves in arrayOfzigzagMove:
        for k in range(len(allMoves)):
            x, y, z = [], [], []
            move = allMoves[k]
            for i in range(len(move)):
                x.append(move[i][0])
                y.append(move[i][1])
                z.append(move[i][2])
        magnitude = getMagnitude(x, y)
        shapeArray = createArray(magnitude, z)
        Templates.append(Template("zigzagMove", shapeArray))

    for allMoves in arrayOfPasses:
        for k in range(len(allMoves)):
            x, y, z = [], [], []
            move = allMoves[k]
            for i in range(len(move)):
                x.append(move[i][0])
                y.append(move[i][1])
                z.append(move[i][2])
        magnitude = getMagnitude(x, y)
        shapeArray = createArray(magnitude, z)
        Templates.append(Template("pass", shapeArray))

    for allMoves in arrayOfv:
        for k in range(len(allMoves)):
            x, y, z = [], [], []
            move = allMoves[k]
            for i in range(len(move)):
                x.append(move[i][0])
                y.append(move[i][1])
                z.append(move[i][2])
        magnitude = getMagnitude(x, y)
        shapeArray = createArray(magnitude, z)
        Templates.append(Template("v", shapeArray))

    return Recognizer(Templates)
Exemplo n.º 3
0
def test_recognition_failed():
    tmpl = Template('X', [
        Point(0, 0, 1),
        Point(1, 1, 1),
        Point(0, 1, 2),
        Point(1, 0, 2)
    ])
    recognizer = Recognizer([tmpl])
    result = recognizer.recognize([
        Point(30, 146, 1),
        Point(306, 222, 1),
    ])
    assert result[0] is None
Exemplo n.º 4
0
def read(eventstream):
    # Train the recognizer on the list of template files,
    # then execute the recognizer on the eventstream file.
    # -------------------------------------------------------------------------
    tf = open("templates.dat", 'r')
    templates = []
    for raw_lines in tf:
        line = raw_lines.strip()
        touch_num = 0
        gf = open(line, 'r')
        gname = gf.readline().strip()
        gpoints = []
        for lines in gf:
            gfline = lines.strip()
            if gfline == "BEGIN":
                touch_num += 1
            elif gfline == "END":
                continue
            else:
                x, y = int(gfline.split(',')[0]), int(gfline.split(',')[1])
                gpoints.append(Point(x, y, touch_num))
        t = Template(gname, gpoints)
        templates.append(t)
        gname = ""
        gpoints = []
    recog = Recognizer(templates)
    # -------------------------------------------------------------------------
    # Extract the necessary points from the event stream.
    gestures = []  # list of lists of points
    gesture = []  # list of points
    touch_num = 0
    es = open(eventstream, 'r')
    for raw_line in es:
        line = raw_line.strip()
        if line == "MOUSEDOWN":
            touch_num += 1
        elif line == "MOUSEUP":
            continue
        elif line == "RECOGNIZE":
            # It's assumed recognize clears after recognition.
            gestures.append(gesture)
            gesture = []
            touch_num = 0
        else:
            x, y = int(line.split(',')[0]), int(line.split(',')[1])
            gesture.append(Point(x, y, touch_num))
    es.close()
    for gesture in gestures:
        gname, accuracy = recog.recognize(gesture)
        print(gname)
    def recognize_shape(self):
        for k in self.templates:
            for p in k[0]:
                self.cloud.append(Point(p[0], p[1], p[2]))
                #print(points)
            self.temp.append(Template(k[1], self.cloud))
        #print(temp)

        for k in self.listFigurePoints:
            self.drawnFigure.append(Point(k[0], k[1], k[2]))

        recognizer = Recognizer(self.temp)
        self.recognitionResult = recognizer.recognize(self.drawnFigure,
                                                      n=self.sampleNumber)
Exemplo n.º 6
0
def test_recognition_successful():
    tmpl = Template('X', [
        Point(0, 0, 1),
        Point(1, 1, 1),
        Point(0, 1, 2),
        Point(1, 0, 2)
    ])
    recognizer = Recognizer([tmpl])
    result = recognizer.recognize([
        Point(30, 146, 1),
        Point(106, 222, 1),
        Point(30, 225, 2),
        Point(106, 146, 2)
    ])
    assert result[0] == 'X'
Exemplo n.º 7
0
def find_template(event_file_path):
    templates_list = os.listdir('./templates')
    number_of_templates = len(templates_list)
    all_templates_points = []
    templates_dir_path = os.path.dirname(
        os.path.realpath(__file__)) + "/templates/"
    for i in range(len(templates_list)):
        with open(templates_dir_path + templates_list[i], 'r') as f:
            all_points = f.readlines()
        all_templates_points.append(add_points_in_list(all_points))
    eventfile_points = get_eventfile_points(event_file_path)
    event_file_points_list = get_points_from_class(eventfile_points)
    for i in range(len(templates_list)):
        present_template_points = get_points_from_class(
            all_templates_points[i])
        present_template = Template(templates_list[i], present_template_points)
        recognizer = Recognizer([present_template])
        result = recognizer.recognize(event_file_points_list)
        print result
Exemplo n.º 8
0
def read_template_points(event_points):

    all_templates = []

    path = os.path.join('Templates')
    if (os.listdir(path) == []):
        print "No Templates."
    else:
        for filename in os.listdir(path):
            new_path = path + "/" + filename
            TemplateObject = open(new_path, "r")

            line = TemplateObject.readline()
            filename = line.strip()

            stroke_count = 0
            template_points = []

            for line in TemplateObject:

                line = line.strip()
                row = line.split(',')

                if (line == 'BEGIN'):
                    stroke_count = stroke_count + 1
                elif (line == 'END'):
                    continue
                else:
                    row = line.split(',')
                    x = int(row[0])
                    y = int(row[1])
                    template_points.append(Point(x, y, stroke_count))

            new_template = Template(filename, template_points)
            all_templates.append(new_template)

        recognizer = Recognizer(all_templates)
        result = recognizer.recognize(event_points)
        print(result)  # Output: ('X', 0.733770116545184)
def getRecognizer():
    mypath = "dataset/"
    dribling = [
        f for f in listdir(mypath + "dribling")
        if isfile(join(mypath + "dribling", f))
    ]
    walking = [
        f for f in listdir(mypath + "walking")
        if isfile(join(mypath + "walking", f))
    ]
    mypass = [
        f for f in listdir(mypath + "pass") if isfile(join(mypath + "pass", f))
    ]
    zigzagMove = [
        f for f in listdir(mypath + "zigzagMove")
        if isfile(join(mypath + "zigzagMove", f))
    ]
    v = [f for f in listdir(mypath + "v") if isfile(join(mypath + "v", f))]

    shapes = [dribling, walking, mypass, v, zigzagMove]
    # print(shapes)
    Templates = []
    for files in shapes:
        for fileName in files:
            # print(fileName)
            shapeName = fileName[:fileName.index("_")]
            fileDir = "dataset/" + shapeName + "/"
            # print("fileDir + fileName", fileDir + fileName)
            x, y, z = split_arrays_without_timeStamps(fileDir + fileName)
            magnitude = getMagnitude(x, y)
            shapeArray = createArray(magnitude, z)
            # shapeArray=segment()

            # print("shapeArray ",shapeArray)
            Templates.append(Template(shapeName, shapeArray))
            x, y, z = [], [], []

    return Recognizer(Templates)
Exemplo n.º 10
0
from dollarpy import Recognizer, Template, Point

# Define 'Template' gestures, each consisting of a name and a list of 'Point' elements.
# These 'Point' elements have 'x' and 'y' coordinates and optionally the stroke index a point belongs to.
tmpl_1 = Template('X', [Point(0, 0), Point(1, 1), Point(0, 1), Point(1, 0)])
tmpl_2 = Template('line', [Point(0, 0), Point(1, 0)])
tmpl_3 = Template('line', [Point(0, 0), Point(1, 1)])
tmpl_4 = Template('line', [Point(0, 0), Point(0, 1)])
tmpl_5 = Template(
    'square', [Point(0, 0), Point(0, 1),
               Point(1, 1), Point(1, 0)])

# Create a 'Recognizer' object and pass the created 'Template' objects as a list.
recognizer = Recognizer([tmpl_1, tmpl_2])

# Call 'recognize(...)' to match a list of 'Point' elements to the previously defined templates.
result = recognizer.recognize([
    Point(31, 141, 1),
    Point(109, 222, 1),
    Point(22, 219, 2),
    Point(113, 146, 2)
])
print(result)  # Output: ('X', 0.733770116545184)
Exemplo n.º 11
0
import cv2
import time
from dollarpy import Recognizer, Template, Point
tmpl_1 = Template('X', [
    Point(0, 0, 1),
    Point(1, 1, 1),
    Point(0, 1, 2),
    Point(1, 0, 2)])
tmpl_2 = Template('line', [
    Point(0, 0),
    Point(1, 0)])
recognizer = Recognizer([tmpl_1, tmpl_2])
cap = cv2.VideoCapture(0)####### 0 indicates primary camera as for me i use my secondary
circle=True
prevx=0
prevy=0
framect=0
result=list()
laserpoints=list()
while(True):
    ret, frame = cap.read()
    blur = cv2.GaussianBlur(frame,(5,5),0)
    height, width, channels = frame.shape
    gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)##############han3ml Gray Scaling n3rf aktar no2ta bright we deh hatob2a red dot######
    (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
    x , y = maxLoc
    intensity= gray[y,x]
    if intensity<254:
        circle=False
    for i in range(-1,1):
        for k in range(-1,1):