コード例 #1
0
def server():
    socketServer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    socketServerNumber = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #creating end point for connection
    host = (input("please Enter the ip "))
    serverPort = 800
    serverPortNumber = 8000
    socketServer.bind((host, serverPort))
    socketServerNumber.bind((host, serverPortNumber))
    print("hosting at " + str(host) + ":" + str(serverPortNumber))
    #port and address for the client to conect
    socketServer.listen(5)
    socketServerNumber.listen(5)
    #listener for the client to queue upto 5 requests
    (clientsocket, address) = socketServer.accept()
    clientSocketNumber, addr = socketServerNumber.accept()

    makeAndEnterDirectory("image")

    while True:
        p = grabScreen.grab_screen((0, 0, 800, 800))
        p = cv2.cvtColor(p, cv2.COLOR_BGR2RGB)
        name = "roshan.png"
        cv2.imwrite(name, p)
        file = open(name, "rb")
        fi = file.read()
        r = os.path.getsize(name)
        q = str(os.path.getsize(name))

        if int(q) > r * 2 / 3:
            clientSocketNumber.send(str.encode(q))
            clientsocket.send(fi)
        file.close()

    clientsocket.close()
コード例 #2
0
def main():
    last_time = time.time()
    for i in list(range(4))[::-1]:
        print(i + 1)
        time.sleep(1)

    paused = False
    while (True):

        if not paused:
            # 800x600 windowed mode
            screen = grab_screen(region=(0, 40, 800, 640))
            print('loop took {} seconds'.format(time.time() - last_time))
            last_time = time.time()
            screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
            screen = cv2.resize(screen, (160, 120))

            prediction = model.predict([screen.reshape(160, 120, 1)])[0]
            print(prediction)

            if np.argmax(prediction) == np.argmax(w):
                straight()

            elif np.argmax(prediction) == np.argmax(s):
                reverse()
            if np.argmax(prediction) == np.argmax(a):
                left()
            if np.argmax(prediction) == np.argmax(d):
                right()
            if np.argmax(prediction) == np.argmax(wa):
                forward_left()
            if np.argmax(prediction) == np.argmax(wd):
                forward_right()
            if np.argmax(prediction) == np.argmax(sa):
                reverse_left()
            if np.argmax(prediction) == np.argmax(sd):
                reverse_right()
            if np.argmax(prediction) == np.argmax(nk):
                no_keys()

        keys = key_check()

        # p pauses game and can get annoying.
        if 'T' in keys:
            if paused:
                paused = False
                time.sleep(1)
            else:
                paused = True
                ReleaseKey(A)
                ReleaseKey(W)
                ReleaseKey(D)
                time.sleep(1)
コード例 #3
0
def printTaker():
	global value
	while True:
		#ciclos de 10 em 10 segundos
		for i in range(0,5):
			print(i+1)
			time.sleep(1)
		print("Passaram 10 segundos!")
		 # grab fullscreen
		grab_screen()
		image = cv2.imread("print.png",0)
		listValues, imageList = getActiveTables(image)#print
		print (listValues)
		for x in listValues:
			# cv2.imshow("x",imageList[x])
			flag = toPlay(imageList[x])
			print(str(x)+" tem a flag do jogo a : "+str(flag))
			if(flag):
				value += 1
				nameContinuation = "cards/cardSet"+str(value)+".png"
				cv2.imwrite(nameContinuation, imageList[x])
				print("tirado print com o valor " + nameContinuation)
				clika(x)
コード例 #4
0
ファイル: marioPython.py プロジェクト: beerjamin/projects
def main():
    for i in list(range(4))[::-1]:
        print(i+1)
        time.sleep(1)
    last_time = time.time()

    while True:
        screen = grab_screen(region=(0,40,800,640))
        screen = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)
        screen = cv2.resize(screen,(80,60))
        keys = key_check()
        output = keys_to_output(keys)
        training_data.append([screen,output])
        print('Frame took {} seconds'.format(time.time()-last_time))
        last_time = time.time()

        #cv2.imshow('window2',cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB))

        if len(training_data) % 500 == 0:
            print(len(training_data))
            np.save(file_name,training_data)
コード例 #5
0
ファイル: nierBot.py プロジェクト: Tabas32/NierBot
    i = 0
    maxIndex = -1
    for cnt in contoursS:
        cntArea = cv2.contourArea(cnt)
        if cntArea > maxArea:
            maxArea = cntArea
            maxIndex = i
        i += 1

    if maxIndex > -1:
        return contoursS[maxIndex]
    else:
        return None


while (True):
    #screen = np.array(ImageGrab.grab(bbox=(0, 25, 640, 420)))
    screen = grab_screen((0, 25, 640, 420))
    new_screen = process_img(screen)
    cnt = mark_player(screen)
    if cnt is not None:
        x, y, w, h = cv2.boundingRect(cnt)
        cv2.rectangle(screen, (x, y), (x + w, y + h), (255, 0, 0), 3)

    # new_screen = grab_screen((0, 25, 640, 420))
    # cv2.imshow('window2', new_screen)
    cv2.imshow('window1', cv2.cvtColor(screen, cv2.COLOR_BGR2RGB))
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break