示例#1
0
文件: room.py 项目: neon-vu/Polyhack
    def output_move_options(self):
        for curr_dir in self.available_passageways:
            print("There is a passage leading " +
                  str(direction(curr_dir).name))

        if (self.stairway):
            print("There is a stairway going up...")
示例#2
0
文件: maxseq.py 项目: gnoynait/its
def gen_path (start, end, TRANS):
    prob = [0] * 8000
    prev = [0] * 8000
    prob[start] = 1.0
    prev[start] = 0
    change = True
    while change:
        change = False
        for tran, p in TRANS.items ():
            d, a, b = tran
            if direction (center[a], center[end]) != d:
                #print direction (center[a], center[end]), d
                continue
            if prob[b] < prob[a] * p:
                prob[b] = prob[a] * p
                prev[b] = a
                change = True
    pr = prev[end]
    path = [end]

    while pr != start and pr != 0:
        path.append (pr)
        pr = prev[pr]
    path.append (start)
    path.append (prob[end])
    path.reverse ()
    return path
示例#3
0
def gen_path(start, end, TRANS):
    prob = [0] * 8000
    prev = [0] * 8000
    markov = {}
    prob[start] = 1.0
    prev[start] = 0
    change = True
    for tran, p in TRANS.items():
        d, a, b = tran
        if direction(center[a], center[end]) == d:
            markov[a, b] = p
    while change:
        change = False
        for tran, p in markov.items():
            a, b = tran
            if prob[b] < prob[a] * p:
                prob[b] = prob[a] * p
                prev[b] = a
                change = True
    pr = prev[end]
    path = [end]

    while pr != start and pr != 0:
        path.append(pr)
        pr = prev[pr]
    path.append(start)
    path.append(prob[end])
    path.reverse()
    return path
示例#4
0
def cut_number(img):

    r, g, b = img.split()
    gray = img.convert('L')
    plt.figure('cut')
    plt.subplot(1, 2, 1), plt.title('origin')
    plt.imshow(gray)
    R = np.asarray(r)
    G = np.asarray(g)
    B = np.asarray(b)

    # print R[27][1562]
    # print G[27][1562]
    # print B[27][1562]

    # box =(1020,0,1030,50) # 门
    # box = (800,830,1230,1066) # 地板
    # box1 = (1348,121,1369,160) # 第一方向
    # box2 = (1198,80,1216,110) # 第二方向

    if direction(img) == 1:
        box = (1348, 121, 1369, 160)
    else:
        box = (1198, 80, 1216, 110)

    roi = gray.crop(box)
    # print '2'
    roi.save("./roi.jpg")
    plt.subplot(1, 2, 2), plt.title('roi')
    plt.imshow(roi), plt.axis('off')
    plt.show()
示例#5
0
文件: markov.py 项目: gnoynait/its
def static_markov ():
    reader = csv.reader (sys.stdin)
    markov = [{}] * 8
    for row in reader:
        end = (int (row[4][:3]), int (row[4][3:]))
        row = [int (p) for p in row]
        for i in range (5, len (row) - 1):
            d = direction (center[row[i]], end)
            if row[i] not in markov[d]:
                markov[d][row[i]] = Counter ()
            markov[d][row[i]][row[i+1]] += 1
    return markov
	def randomize(self):
		while True:
			self.opt_annotations = opt_annotations()
			self.opt_annotations.randomize()
			self.direction = direction()
			self.direction.randomize()
			self.type_ref = type_ref()
			self.type_ref.randomize()
			self.name = name()
			self.name.randomize()
			if not self.filter():
				break
示例#7
0
def static_markov():
    reader = csv.reader(sys.stdin)
    markov = [{}] * 8
    for row in reader:
        end = (int(row[4][:3]), int(row[4][3:]))
        row = [int(p) for p in row]
        for i in range(5, len(row) - 1):
            d = direction(center[row[i]], end)
            if row[i] not in markov[d]:
                markov[d][row[i]] = Counter()
            markov[d][row[i]][row[i + 1]] += 1
    return markov
示例#8
0
def gen_path(start, end, TRANS):
    N = 5000
    prob = [0] * N
    prev = [0] * N
    Q = set()
    adj = [[]] * N
    prob[start] = 1.0
    prev[start] = 0
    for tran, p in TRANS.items():
        d, a, b = tran
        if direction(center[a], center[end]) == d:
            Q.add(a)
            Q.add(b)
            adj[a].append((b, p))
    #change = True

    while len(Q) > 0:
        #change = False
        maxv = 0
        maxp = 0
        for v in Q:
            if prob[v] >= maxp:
                maxv = v
                maxp = p
        Q.remove(maxv)
        for n, p in adj[maxv]:
            if prob[maxv] * p >= prob[n]:
                prob[n] = prob[maxv] * p
                prev[n] = maxv
                #change = True

    path = [end]
    pr = prev[end]
    print pr
    while pr != start:
        print pr
        if pr == 0:
            print >> sys.stderr, 'zero'
            break
        path.append(pr)
        pr = prev[n]
    path.append(start)
    path.append(prob[end])
    path.reverse()
    return path
示例#9
0
    def findExogenous(self, exclude=[]):
        rvList = self.rvList
        rvList.sort()
        accum = {}
        for v in rvList:
            if v not in exclude:
                accum[v] = 0.0
        numVars = len(rvList)
        for i in range(numVars):
            x = rvList[i]
            if x in exclude:
                continue
            for j in range(i + 1, numVars):
                y = rvList[j]
                if x == y or y in exclude:
                    continue
                R = direction.direction(self.data[x], self.data[y])

                if R > 0:
                    leastCausal = y
                else:
                    leastCausal = x
                accum[leastCausal] += abs(R)
        scores = [(accum[key], key) for key in accum.keys()]
        scores.sort()
        exos = []
        for tup in scores:
            var = tup[1]
            if not exos:
                exos.append(var)
            else:
                isExo = True
                for exo in exos:
                    pval = independence.test(self.iProb, [var], [exo])
                    #print('ind ', var, '-', exo, ' = ', pval)
                    if pval < .5:
                        isExo = False
                        break

                if isExo:
                    exos.append(var)
                else:
                    break
        return exos
示例#10
0
def judge(path, TRANS):
    prob = 1.0
    for i in range(len(path) - 1):
        d = direction(center[path[i]], center[path[-1]])
        prob = prob * TRANS[d, path[i], path[i + 1]]
    return [prob] + path
示例#11
0
import direction
import csv
import sys
""" seperate path data by direction"""
reader = csv.reader(sys.stdin)
writer = [None] * 8
for i in range(1, 9):
    f = open('path' + str(i) + '.dat', 'w')
    writer[i - 1] = csv.writer(f)

for row in reader:
    if len(row) < 10:
        continue
    start = (int(row[2][:3]), int(row[2][3:]))
    end = (int(row[4][:3]), int(row[4][3:]))
    d = direction.direction(start, end)
    writer[d - 1].writerow(row)
示例#12
0
def D(img1,img2):

    gray_different = 100
    num_different = 500
    # img1=Image.open(img1)
    # img2=Image.open(img2)

    gray1=img1.convert('L')
    gray2=img2.convert('L')
    if direction(img2) == direction(img1):
        if direction(img2) == 1:
            box = (828, 821, 1248, 1041)
        else:
            box = (740, 827, 1260, 1053)
    else:
        print('摄像头位置改变')
        box = (0,0,1,1)
    roi1=gray1.crop(box)
    roi2=gray2.crop(box)

    roi1.save("./F.jpg")
    roi2.save("./S.jpg")

    plt.figure("-")
    plt.subplot(1,2,1), plt.title('F')
    plt.imshow(roi1),plt.axis('off')

    plt.subplot(1,2,2), plt.title('S')
    plt.imshow(roi2),plt.axis('off')

    plt.show()

    m1 = np.asarray(roi1)
    m2 = np.asarray(roi2)

    emptyimg = np.zeros(m1.shape,np.uint8)
    def pic_sub(dest,s1,s2):
        for x in range(dest.shape[0]):
            for y in range(dest.shape[1]):
                if(s2[x,y] > s1[x,y]):
                    dest[x,y] = s2[x,y] - s1[x,y]
                else:
                    dest[x,y] = s1[x,y] - s2[x,y]


    # print 'm1:',m1
    # print 'm2:',m2
    pic_sub(emptyimg,m1,m2)
    m = emptyimg
   #  m = m1
   #  for i in range(len(m1)):
   # # 迭代输出列
   #      for j in range(len(m1[0])):
   #          m[i][j] = m1[i][j] - m2[i][j]
   # print 'm',m

    a = m.shape[0]
    b = m.shape[1]

    a = int(a)
    b = int(b)
    c = 0
    for i in range(a):
        for j in range(b):
            if abs(m[i][lj]) > gray_different:
                c=c+1
    print('people_different:',c)
    if c > num_different:
        diff = 1
    else:
        diff =0
    print(diff)
    return diff
示例#13
0
def D(img1, img2):
    gray_different = 100
    num_different = 500
    # img1=Image.open(img1)
    # img2=Image.open(img2)

    gray1 = img1.convert('L')  # 转化为灰度图
    gray2 = img2.convert('L')
    if direction(img2) == direction(img1):
        if direction(img2) == 1:
            box = (775, 0, 1113, 30)
        else:
            box = (628, 5, 940, 30)
    else:
        print('摄像头位置改变')  # 输出
        box = (0, 0, 1, 1)

    roi1 = gray1.crop(box)
    roi2 = gray2.crop(box)

    roi1.save("./D_F.jpg")
    roi2.save("./D_S.jpg")

    plt.figure("-")
    plt.subplot(1, 2, 1), plt.title('F')
    plt.imshow(roi1), plt.axis('off')

    plt.subplot(1, 2, 2), plt.title('S')
    plt.imshow(roi2), plt.axis('off')

    plt.show()

    m1 = np.asarray(roi1)
    m2 = np.asarray(roi2)

    # print 'm1:',m1
    # print 'm2:',m2
    emptyimg = np.zeros(m1.shape, np.uint8)

    def pic_sub(dest, s1, s2):
        for x in range(dest.shape[0]):
            for y in range(dest.shape[1]):
                if (s2[x, y] > s1[x, y]):
                    dest[x, y] = s2[x, y] - s1[x, y]
                else:
                    dest[x, y] = s1[x, y] - s2[x, y]

    pic_sub(emptyimg, m1, m2)
    m = emptyimg

    a = m.shape[0]
    b = m.shape[1]

    a = int(a)
    b = int(b)
    c = 0
    for i in range(a):
        for j in range(b):
            if abs(m[i][j]) > gray_different:
                c = c + 1
    print('door_different:', c)
    if c > num_different:
        diff = 1
    else:
        diff = 0
    print(diff)
    return diff
示例#14
0
 def testDirection(self, x, y):
     rho = direction.direction(self.data[x], self.data[y])
     return rho
示例#15
0
文件: judge.py 项目: gnoynait/its
def judge (path, TRANS):
    prob = 1.0
    for i in range (len(path) - 1):
        d = direction (center[path[i]], center[path[-1]])
        prob = prob * TRANS[d, path[i], path[i+1]]
    return [prob] + path
示例#16
0
    if mode in ['crohns', 'multi']:
        cnt = count(zip(*data))
        if any(cnt, lambda(x):x==0):
            continue
        if chi2_contingency(count(zip(data[0],data[2])))[1]>.01:
            continue
        if mode=='multi' and chi2_contingency(count(zip(data[0],data[1])))[1]<.1:
            continue
    elif mode=='multiplat':
        cnt = count(zip(*data))
        if any(cnt, lambda(x):x==0):
            continue
        if chi2_contingency(count(zip(data[0],data[1])))[1] < chi2_contingency(count(zip(data[0],data[2])))[1]:
            continue

    dir=direction(data[0], data[2], data[1], n)
    record(dir, True)
    i += 1

print '%d fwd (took %d tries)' % (i, tries)

### Chain

i=0
tries=0
while i < runs:
    net=struct()
    tries += 1

    if mode in ['platonic', 'multiplat', 'against-v']:
        net.a = random()
示例#17
0
# #
# left_ = Median(th1)

#

# th1 = cv.bitwise_not(th1,None)

# xiahua = Thin.Thin(th1)
# xiahua = cv.bitwise_not(xiahua,None)
# #
# gray_method_left = gray.Cvpointgray(th1)
# gray_method_right = gray.Cvpointgray(th2)

# s1 = gaosi_steger.steger(th1)
# s2 = gaosi_steger.steger(th2)
dir_method_left, left_points = direction.direction(th1)
dir_method_right, right_points = direction.direction(th2)

left_img = dir_method_left.copy()
right_img = dir_method_right.copy()
# cv.imshow("th1",left_img)
# cv.imshow("th2",right_img)
# cv.waitKey(0)

# #获取角点
# left_corners = cv.goodFeaturesToTrack(left_img, 3, 0.01, 10)
# right_corners = cv.goodFeaturesToTrack(right_img, 3, 0.01, 10)
# #亚像素角点
# criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER, 100, 0.001)
# left_sub_corners = cv.cornerSubPix(left_img,left_corners,(5,5),(-1,-1),criteria)
# right_sub_corners = cv.cornerSubPix(right_img,right_corners,(5,5),(-1,-1),criteria)
示例#18
0
def gridfeatures(d):
    # strokes_list = []
    # l = []

    # for coordinate in d:
    #     if coordinate[2] == 0.0:
    #         l.append(coordinate)
    #     else:
    #         strokes_list.append(l)
    #         l = []

    zones = []
    stroke_wise_zones = []
    zone_features = []

    # fr stroke in strokes_list:
    zone1 = []
    zone2 = []
    zone3 = []
    zone4 = []
    zone5 = []
    zone6 = []
    zone7 = []
    zone8 = []
    zone9 = []
    zone_list = []
    sz = len(d)  # no. of rows in d, i.e, no. of coordinates
    x_coor = []
    y_coor = []
    for j in range(sz):  # this loop makes a list of all x coordinates
        x_coor.append((d[j][0]))
    max_x = max(x_coor)  # max and min values of x coordinate
    min_x = min(x_coor)
    for j in range(sz):  # this loop makes a list of all y coordinates
        y_coor.append((d[j][1]))
    max_y = max(y_coor)  # max and min values of y coordinate
    min_y = min(y_coor)
    #print(min_x, max_x, min_y, max_y)
    dx = max_x - min_x  # Width of the grid
    dy = max_y - min_y  # Height of the grid
    l = dx / 3
    m = 2 * (dx / 3)
    a = dy / 3
    s = l * a
    b = 2 * (dy / 3)
    #print(min_x, l + min_x, m + min_x, min_y, a + min_y, b + min_y)
    for point in d:
        if point[0] <= min_x + l:
            if point[1] <= min_y + a:
                zone1.append(point)
            if min_y + a < point[1] <= min_y + b:
                zone4.append(point)
            if point[1] > min_y + b:
                zone7.append(point)
        if min_x + l < point[0] <= min_x + m:
            if point[1] <= min_y + a:
                zone2.append(point)
            if min_y + a < point[1] <= min_y + b:
                zone5.append(point)
            if point[1] > min_y + b:
                zone8.append(point)
        if point[0] > min_x + m:
            if point[1] <= min_y + a:
                zone3.append(point)
            if min_y + a < point[1] <= min_y + b:
                zone6.append(point)
            if point[1] > min_y + b:
                zone9.append(point)
    zone_list.append(zone1)
    zone_list.append(zone2)
    zone_list.append(zone3)
    zone_list.append(zone4)
    zone_list.append(zone5)
    zone_list.append(zone6)
    zone_list.append(zone7)
    zone_list.append(zone8)
    zone_list.append(zone9)
    # print([zone1, zone2, zone3, zone4, zone5, zone6, zone7, zone8, zone9])
    zones = []
    px_density = 0
    for zone in zone_list:
        vicinity = []
        bin_curl = [0 for x in range(8)]
        bin_lin = [0 for x in range(8)]
        bin_sl = [0 for x in range(8)]
        bin_dir = [0 for x in range(8)]
        bin_curv = [0 for x in range(8)]
        if len(zone) != 0:
            count = len(zone)
            px_density = s / count
            for i in range(0, len(zone), 11):
                j = i
                while j < (i + 11) and j < len(zone):
                    vicinity.append(zone[j])
                    j = j + 1
                bin = quantizer(math.acos(curliness(vicinity)))
                bin_curl[bin] = bin_curl[bin] + 1
                bin = quantizer(math.atan(linearity(vicinity)))
                bin_lin[bin] += 1
                bin = quantizer(pixel_angle(vicinity))
                bin_sl[bin] += 1
                vicinity = []
            vicinity = []
            for i in range(0, len(zone), 3):
                j = i
                while j < (i + 3) and j < len(zone):
                    vicinity.append(zone[j])
                    j = j + 1
                bin = quantizer(direction(vicinity))
                bin_dir[bin] += 1
                vicinity = []
            vicinity = []
            for i in range(0, len(zone), 5):
                j = i
                while j < (i + 5) and j < len(zone):
                    vicinity.append(zone[j])
                    j = j + 1
                bin = quantizer(curvature(vicinity))
                bin_curv[bin] += 1
                vicinity = []
            for i in range(8):
                bin_curv[i] /= len(zone)
                bin_dir[i] /= len(zone)
                bin_sl[i] /= len(zone)
                bin_lin[i] /= len(zone)
                bin_curl[i] /= len(zone)
        zone_features.append(sum(bin_dir))
        zone_features.append(sum(bin_curv))
        zone_features.append(sum(bin_sl))
        zone_features.append(sum(bin_lin))
        zone_features.append(sum(bin_curl))
        zone_features.append(px_density)
    return zone_features