コード例 #1
0
ファイル: Test_NN.py プロジェクト: tarqmamdouh/SLAVC
def straight():
    ##    if random.randrange(4) == 2:
    ##        ReleaseKey(W)
    ##    else:
    PressKey(W)
    ReleaseKey(A)
    ReleaseKey(D)
    print("Driver is Moving Stright")
コード例 #2
0
ファイル: Test_NN.py プロジェクト: tarqmamdouh/SLAVC
def right():
    PressKey(W)
    PressKey(D)
    ReleaseKey(A)
    # ReleaseKey(W)
    # ReleaseKey(D)
    time.sleep(t_time)
    ReleaseKey(D)
    print("Driver is Moving right")
コード例 #3
0
ファイル: Test_NN.py プロジェクト: tarqmamdouh/SLAVC
def left():
    PressKey(W)
    PressKey(A)
    # ReleaseKey(W)
    ReleaseKey(D)
    # ReleaseKey(A)
    time.sleep(t_time)
    ReleaseKey(A)
    print("Driver is Moving left")
コード例 #4
0
def FrontFrameCapture():
    # --------------------------------------- Front Frame ----------------------------------------------------------
    # get The Screen window
    Fhwnd = win32gui.GetDesktopWindow()
    FwDC = win32gui.GetWindowDC(Fhwnd)

    # create DC object for
    FdcObj = win32ui.CreateDCFromHandle(FwDC)
    FcDC = FdcObj.CreateCompatibleDC()

    # bitmapping The captured Frame
    FdataBitMap = win32ui.CreateBitmap()
    FdataBitMap.CreateCompatibleBitmap(FdcObj, w, h)

    # Cropping Window
    FcDC.SelectObject(FdataBitMap)
    FcDC.BitBlt((0, 0), (w, h), FdcObj, (0, 30), win32con.SRCCOPY)

    # dataBitMap.SaveBitmapFile(cDC, 'Test.jpg')
    bmpinfo = FdataBitMap.GetInfo()
    bmpstr = FdataBitMap.GetBitmapBits(True)
    im1 = Image.frombuffer('RGB', (bmpinfo['bmWidth'], bmpinfo['bmHeight']),
                           bmpstr, 'raw', 'BGRX', 0, 1)
    Front = np.array(im1)
    Front = cv2.cvtColor(Front, cv2.COLOR_BGR2RGB)
    PressKey(ChangeView)
    time.sleep(delay)
    ReleaseKey(ChangeView)
    # time.sleep(0.0000000000000001)
    # Cleaning Some memory (Avoid Exception)
    FdcObj.DeleteDC()
    FcDC.DeleteDC()
    win32gui.ReleaseDC(Fhwnd, FwDC)
    win32gui.DeleteObject(FdataBitMap.GetHandle())
    return Front
コード例 #5
0
ファイル: Test_NN.py プロジェクト: tarqmamdouh/SLAVC
def main():
    last_time = time.time()
    for i in list(range(5))[::-1]:
        print("Your Testing Neural Network will start in : " + str(i + 1))
        time.sleep(1)

    paused = False
    while (True):

        if not paused:
            # 800x600 windowed mode
            # screen =  np.array(ImageGrab.grab(bbox=(0,40,800,640)))
            screen = Eyes.FrontFrameCapture()
            # 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)

            turn_thresh = .90
            fwd_thresh = 0.40

            if prediction[1] > fwd_thresh:
                straight()
            elif prediction[0] > turn_thresh:
                left()
            elif prediction[2] > turn_thresh:
                right()
            else:
                straight()

        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)
コード例 #6
0
            continue

        PFrame = Eyes.FrontFrameCapture()
        PFrame = cv2.cvtColor(PFrame, cv2.COLOR_BGR2GRAY)
        PFrame = cv2.resize(PFrame, (480, 270))
        keys = Register.key_check()
        output = Register.key_to_output(keys)
        Data.append([PFrame, output])

        # Save Bulk
        if len(Data) % 1000 == 0:
            print("################### Saving Bulk Number : " + str(i + 1) +
                  "###################")
            np.save('Naive-Data\\' + file_name + '-' + str(i + 1) + '.npy',
                    Data)
            i = i + 1
            Data.clear()

        # print('Loop took {} Seconds'.format(time.time() - last_time))
        # last_time = time.time()

        if 0xFF == ord('q'):
            cv2.destroyAllWindows()
            ReleaseKey(ChangeView)
            break

        # unneccssory Staff for now
        # PFrame, original_image, m1, m2 = Detector.Detect(PFrame)
        # cv2.imshow('Front', original_image)
        # cv2.waitKey(1)