Exemplo n.º 1
0
def process_img(frame):
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    img = imgprocess.imageDW(gray,(common_config.CAP_HEIGHT,common_config.CAP_WIDTH),1)
    new_img = np.zeros(img.shape)
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            new_img[i][j] = 0 if img[i][j] < THRESHOLD else 255
    new_img = new_img.ravel()
    new_img = [y/255.0 for y in new_img]
    new_img = np.reshape(new_img, (common_config.NETWORK_INPUT_SIZE, 1))
    return new_img
Exemplo n.º 2
0
    cv2.imwrite(name, image)


## Main function
# major variables
cap = cv2.VideoCapture(0)
mo = move.Move()

while(cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    # Change frame to gray level image
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    img = imgprocess.imageDW(gray,gray.shape,4)

    # Display the resulting frame
    cv2.imshow('frame',frame)

    # Choose direction or quit
    input_key = cv2.waitKey(1) & 0xFF
    if input_key == ord('q'):
        break
    elif input_key == ord('w'):
        mo.forward(common_config.SLEEP_TIME)
        save_image("w", gray)
    elif input_key == ord('s'):
        mo.backward(common_config.SLEEP_TIME)
        save_image("s", gray)
    elif input_key == ord('a'):
    print "want to save file:"+name
    cv2.imwrite(name, image)


## Main function
# major variables
cap = cv2.VideoCapture(1)

while(cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    # Change frame to gray level image
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    img = imgprocess.imageDW(gray,gray.shape,2)

    # Do not display the resulting frame
    cv2.imshow('frame',img)

    # Choose direction or quit
    input_key = cv2.waitKey(1) & 0xFF
    if input_key == ord('q'):
        break
    elif input_key == ord('w'):
        save_image("w", img)
    elif input_key == ord('s'):
        save_image("s", img)
    elif input_key == ord('a'):
        save_image("a", img)
    elif input_key == ord('d'):
Exemplo n.º 4
0

tr = GetFrameThread()
tr.start()

## main loop
pre_a = np.ndarray((3, 1))
while (cap.isOpened()):
    # Capture frame-by-frame
    # ret, frame = cap.read()
    ret, current_frame = getFrame()

    # Our operations on the frame come here
    # Change frame to gray level image and do some trasition
    gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
    img = imgprocess.imageDW(
        gray, (common_config.CAP_HEIGHT, common_config.CAP_WIDTH), 1)
    new_img = np.zeros(img.shape)
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            new_img[i][j] = 0 if img[i][j] < THRESHOLD else 255
    new_img = new_img.ravel()
    new_img = [y / 255.0 for y in new_img]
    new_img = np.reshape(new_img, (common_config.NETWORK_INPUT_SIZE, 1))

    # decide direction
    a = net.feedforward(new_img)
    print a
    if (pre_a == a).all():
        print "Image not change. ignore this turn"
        continue
    pre_a = a.copy()
    return ret, frame

tr = GetFrameThread()
tr.start()

## main loop
pre_a = np.ndarray((3,1))
while(cap.isOpened()):
    # Capture frame-by-frame
    # ret, frame = cap.read()
    ret, current_frame = getFrame()

    # Our operations on the frame come here
    # Change frame to gray level image and do some trasition
    gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
    img = imgprocess.imageDW(gray,(common_config.CAP_HEIGHT,common_config.CAP_WIDTH),1)
    new_img = np.zeros(img.shape)
    for i in range(img.shape[0]):
        for j in range(img.shape[1]):
            new_img[i][j] = 0 if img[i][j] < THRESHOLD else 255
    new_img = new_img.ravel()
    new_img = [y/255.0 for y in new_img]
    new_img = np.reshape(new_img, (common_config.NETWORK_INPUT_SIZE, 1))

    # decide direction
    a = net.feedforward(new_img)
    print a
    if (pre_a == a).all():
        print "Image not change. ignore this turn"
        continue
    pre_a = a.copy()