Esempio n. 1
0
def get_cube(debug_flag=False,
             directory='/home/jan/rubiks-cube-NxNxN-solver'):  #PRODUCTION
    #def get_cube(debug_flag=False, directory='/home/jan/rubiks-cube-tracker/test-data/3x3x3-random-01'): #TEST
    data = {}

    if not os.path.isdir(directory):
        sys.stderr.write("ERROR: directory %s does not exist\n", directory)
        sys.exit(1)
    cube_size = None

    for (side_index, side_name) in enumerate(('U', 'L', 'F', 'R', 'B', 'D')):
        filename = os.path.join(directory, "rubiks-side-%s.png" % side_name)

        if os.path.exists(filename):
            #log.info("filename %s, side_index %s, side_name %s" % (filename, side_index, side_name))

            #log.info("filename %s, side_index %s, side_name %s" % (filename, side_index, side_name))
            rimg = RubiksImage(side_index, side_name, debug=debug_flag)
            rimg.analyze_file(filename, cube_size)

            if cube_size is None:
                side_square_count = len(rimg.data.keys())
                cube_size = int(sqrt(side_square_count))

            data = merge_two_dicts(data, rimg.data)
            # log.info("cube_size %d" % cube_size)

        else:
            sys.stderr.write("ERROR: %s does not exist\n" % filename)
            sys.exit(1)

    return json.dumps(data, sort_keys=True)
def tracker(directory):
    def convert_keys_to_int(dict_to_convert):
        result = {}

        for (key, value) in dict_to_convert.items():
            result[int(key)] = value

        return result

    data = {}

    cube_size = None
    cube_size = None

    for (side_index, side_name) in enumerate(('U', 'L', 'F', 'R', 'B', 'D')):
        filename = os.path.join(directory, "rubiks-side-%s.png" % side_name)

        if os.path.exists(filename):
            #log.info("filename %s, side_index %s, side_name %s" % (filename, side_index, side_name))

            #log.info("filename %s, side_index %s, side_name %s" % (filename, side_index, side_name))
            rimg = RubiksImage(side_index, side_name)
            rimg.analyze_file(filename, cube_size)

            if cube_size is None:
                side_square_count = len(rimg.data.keys())
                cube_size = int(sqrt(side_square_count))

            data = merge_two_dicts(data, rimg.data)
            # log.info("cube_size %d" % cube_size)

        else:
            print "ERROR: %s does not exist" % filename
            sys.exit(1)

    print(json.dumps(data, sort_keys=True))
    with open('out.txt', 'w') as f:
        print >> f, json.dumps(data, sort_keys=True)
Esempio n. 3
0
def recognition():
    get_pictures_of_sides()
    data = {}
    cube_size = None
    if not os.path.isdir(args.directory):
        print "ERROR: directory %s does not exist" % args.directory
        sys.exit(1)
    for (side_index, side_name) in enumerate(('U', 'L', 'F', 'R', 'B', 'D')):
        filename = os.path.join(args.directory,
                                "rubiks-side-%s.png" % side_name)
        rimg = RubiksImage(side_index, side_name, debug=False)
        rimg.analyze_file(filename, cube_size)
        print side_name
        if cube_size is None:
            side_square_count = len(rimg.data.keys())
            cube_size = int(sqrt(side_square_count))
        data = merge_two_dicts(data, rimg.data)
    #print "rubiks-color-resolver.py --json --rgb " + str(data)
    #print(json.dumps(data, sort_keys=True))
    command = "rubiks-color-resolver.py  --rgb '" + str(
        json.dumps(data, sort_keys=True)) + "'"  #+"|grep kociemba"
    #proc=subprocess.check_call(str(command), shell=True, stdout=subprocess.PIPE)
    #kubic = "DRLUUBFBRBLURRLRUBLRDDFDLFUFUFFDBRDUBRUFLLFDDBFLUBLRBD"
    kubic = run_command(command)
    print "Cubic recognized!"
    print kubic
    kubic_fix = raw_input(
        "Please insert the right kubic configuration if it did not recognized it correctly!"
    )
    if len(kubic_fix) < len(
            "DRLUUBFBRBLURRLRUBLRDDFDLFUFUFFDBRDUBRUFLLFDDBFLUBLRBD"):
        print("There was no fix...")
        return kubic
    else:
        print("The cube is fixed a bit: ")
        print(kubic_fix)
        return kubic_fix
Esempio n. 4
0
def CubeScan():

    #return 'DRLUUBFBRBLURRLRUBLRDDFDLFUFUFFDBRDUBRUFLLFDDBFLUBLRBD'
    #return 'UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB'
    #return 'UUUUUUUUULLLLLLLLLFFFFFFFFFRRRRRRRRRBBBBBBBBBDDDDDDDDD'

    #data = json.loads(str)
    data = {}
    # F,R,B,L,U,D
    #  (letters stand for Up, Left, Front, Right, Back, and Down)
    #for (side_index, side_name) in enumerate(('U', 'R', 'F', 'D', 'L', 'B')):
    for (side_index, side_name) in enumerate(('U', 'R', 'F', 'D', 'L', 'B')):
        index = 0
        if side_name == 'U':
            index = 4
        elif side_name == 'L':
            index = 1
        elif side_name == 'F':
            index = 0
        elif side_name == 'R':
            index = 2
        elif side_name == 'B':
            index = 3
        elif side_name == 'D':
            index = 5

        filename = os.path.join(os.getcwd(), "images", "%s.png" % index)
        print('file = ', filename)
        rimg = RubiksImage(index, side_name)
        rimg.analyze_file(filename)
        data = merge_two_dicts(data, rimg.data)

    cube = RubiksColorSolverGeneric(3)
    cube.enter_scan_data(data)
    cube.crunch_colors()
    return ''.join(cube.cube_for_kociemba_strict())
Esempio n. 5
0
    if not os.path.isdir(args.directory):
        sys.stderr.write("ERROR: directory %s does not exist\n" %
                         args.directory)
        sys.exit(1)
    cube_size = None
    cube_size = None

    for (side_index, side_name) in enumerate(("U", "L", "F", "R", "B", "D")):
        filename = os.path.join(args.directory,
                                "rubiks-side-%s.png" % side_name)

        if os.path.exists(filename):
            # log.info("filename %s, side_index %s, side_name %s" % (filename, side_index, side_name))

            # log.info("filename %s, side_index %s, side_name %s" % (filename, side_index, side_name))
            rimg = RubiksImage(side_index, side_name, debug=args.debug)
            rimg.analyze_file(filename, cube_size)

            if cube_size is None:
                side_square_count = len(rimg.data.keys())
                cube_size = int(sqrt(side_square_count))

            data = merge_two_dicts(data, rimg.data)
            # log.info("cube_size %d" % cube_size)

        else:
            sys.stderr.write("ERROR: %s does not exist\n" % filename)
            sys.exit(1)

    print(json.dumps(data, sort_keys=True))