def run():
    DC = 0
    line1 = []
    while DC <= DC_max:
        update_duty_cycle(DC)
        wait_for_temperature_to_equalize(DC)
        #line1 = live_plotter(DC_values,temperature_values,line1)
        DC += DC_step
    line1 = live_plotter(DC_values,temperature_values,line1)
Exemple #2
0
    return line.astype(np.float)

def follow(thefile):
    thefile.seek(0,2)
    while True:
        line = thefile.readline()
        if not line:
            time.sleep(0.1)
            continue
        yield line

if __name__ == '__main__':
    logfile = open("E:/laure/Documents/HackUTD/TapVRap/tap-standalonewin-sdk-master/TAPWinApp/bin/Debug/data.txt","r")
    loglines = follow(logfile)
    axis = 1
    
    size = 100
    x = np.linspace(0,1,size+1)[0:-1]
    y = np.zeros(len(x))
    
    line1 = []
    for line in loglines:
        data = line.split(',')
        data = np.array(data)
        newData = cleanData(data)
    
        y[-1] = newData[axis]
        line1 = live_plotter(x,y ,line1)
        y = np.append(y[1:],0.0)
    
Exemple #3
0
                        window_end_datetime = play_time + dt.timedelta(
                            minutes=window_length)

                #While realtime or replaying, simulate log gap times (and plot zeroes) (i.e. periods of inactivity)
                while play_time <= log_datetime:
                    play_time = play_time + dt.timedelta(seconds=30)

                    if plot:
                        y_vec_lp[-1] = 0
                        y_vec_pap[-1] = 0
                        line_lp, line_lp_avg, line_pap, line_pap_avg = live_plotter(
                            x_vec,
                            y_vec_lp,
                            line_lp,
                            y_vec_lp_avg,
                            line_lp_avg,
                            y_vec_pap,
                            line_pap,
                            y_vec_pap_avg,
                            line_pap_avg,
                            identifier='PHT Activity',
                            pause_time=.2)
                        y_vec_lp = np.append(y_vec_lp[1:], 0.0)
                        y_vec_lp_avg = np.append(y_vec_lp_avg[1:],
                                                 y_vec_lp_avg[-1])
                        y_vec_pap = np.append(y_vec_pap[1:], 0.0)
                        y_vec_pap_avg = np.append(y_vec_pap_avg[1:],
                                                  y_vec_pap_avg[-1])

                #Stop replay/file iteration
                if log_datetime > play_end:
                    playing = False
Exemple #4
0
        message = str(message).split(",")
        accelerometer_readings = []
        if timer > 1000:
            break
        for index, val in enumerate(message):
            val = val.strip()
            if val == "3":
                accelerometer_readings.append(
                    float(message[index + 1].replace("'", "").strip()))
                accelerometer_readings.append(
                    float(message[index + 2].replace("'", "").strip()))
                accelerometer_readings.append(
                    float(message[index + 3].replace("'", "").strip()))
                y_vec[-1] = accelerometer_readings[2]
                accelerometer_readings_z.append(accelerometer_readings[2])
                line1 = live_plotter(x_vec, y_vec, line1)
                y_vec = np.append(y_vec[1:], 0.0)
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        traceback.print_exc()

with open('accelerometer.csv', mode='w') as csv_file:
    fieldnames = ['accelerometer_z']
    writer = csv.DictWriter(csv_file, fieldnames=fieldnames)

    writer.writeheader()
    for reading in accelerometer_readings_z:
        writer.writerow({'accelerometer_z': reading})

print(accelerometer_readings_z)
Exemple #5
0
from pylive import live_plotter
import numpy as np

size = 100
x_vec = np.linspace(0, 1, size + 1)[0:-1]
y_vec = np.random.randn(len(x_vec))
line1 = []
while True:
    rand_val = np.random.randn(1)
    y_vec[-1] = rand_val
    line1 = live_plotter(x_vec, y_vec, line1, "TRIAL")
    y_vec = np.append(y_vec[1:], 0.0)
Exemple #6
0
from pylive import live_plotter
import numpy as np

size = 100
x_vec = np.linspace(0, 1, size + 1)[0:-1]
y_vec = np.random.randn(len(x_vec))
line1 = []
while True:
    rand_val = np.random.randn(1)
    y_vec[-1] = rand_val
    line1 = live_plotter(x_vec, y_vec, line1, "Dynamic Overall Load")
    y_vec = np.append(y_vec[1:], 0.0)
Exemple #7
0
def process(input):
    print("[INFO] loading source image and checkpoint...")
    source_path = input
    checkpoint_path = args['checkpoint']
    if args['input_video']:
        video_path = args['input_video']
    else:
        video_path = None
    source_image = imageio.imread(source_path)
    source_image = resize(source_image, (256, 256))[..., :3]

    generator, kp_detector = load_checkpoints(
        config_path='config/vox-256.yaml', checkpoint_path=checkpoint_path)

    # Load the cascade
    face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

    if not os.path.exists('output'):
        os.mkdir('output')

    relative = True
    adapt_movement_scale = True
    if args['cpu']:
        cpu = True
    else:
        cpu = False

    if video_path:
        cap = cv2.VideoCapture(video_path)
        print("[INFO] Loading video from the given path")
    else:
        cap = cv2.VideoCapture(0)
        print("[INFO] Initializing front camera...")
        # get vcap property
        width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)  # float `width`
        height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)  # float `height`
        fps = cap.get(cv2.CAP_PROP_FPS)
        frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
        print('resolution : {} x {}'.format(width, height))
        print('frame rate : {} \nframe count : {}'.format(fps, frame_count))

    fourcc = cv2.VideoWriter_fourcc(*'MJPG')
    out1 = cv2.VideoWriter('output/test.avi', fourcc, 12, (256 * 3, 256), True)

    cv2_source = cv2.cvtColor(source_image.astype('float32'),
                              cv2.COLOR_BGR2RGB)
    cv2_source2 = (source_image * 255).astype(np.uint8)

    if args['vc']:
        camera = pyfakewebcam.FakeWebcam('/dev/video7', 640, 360)
        camera._settings.fmt.pix.width = 640
        camera._settings.fmt.pix.height = 360

    img = np.zeros((360, 640, 3), dtype=np.uint8)
    yoff = round((360 - 256) / 2)
    xoff = round((640 - 256) / 2)
    img_im = img.copy()
    img_cv2_source = img.copy()
    img_im[:, :, 2] = 255
    img_cv2_source[:, :, 2] = 255
    with torch.no_grad():
        predictions = []
        source = torch.tensor(source_image[np.newaxis].astype(
            np.float32)).permute(0, 3, 1, 2)
        if not cpu:
            source = source.cuda()
        kp_source = kp_detector(source)
        count = 0
        fps = []
        if args['csv']:
            line1 = []
            size = 10
            x_vec = np.linspace(0, 1, size + 1)[0:-1]
            y_vec = np.random.randn(len(x_vec))
        while (True):
            start = time.time()
            ret, frame = cap.read()
            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            # Detect the faces
            faces = face_cascade.detectMultiScale(gray, 1.1, 4)
            frame = cv2.flip(frame, 1)
            if ret == True:

                if not video_path:
                    x = 143
                    y = 87
                    w = 322
                    h = 322
                    frame = frame[y:y + h, x:x + w]
                frame1 = resize(frame, (256, 256))[..., :3]

                if count == 0:
                    source_image1 = frame1
                    source1 = torch.tensor(source_image1[np.newaxis].astype(
                        np.float32)).permute(0, 3, 1, 2)
                    kp_driving_initial = kp_detector(source1)

                frame_test = torch.tensor(frame1[np.newaxis].astype(
                    np.float32)).permute(0, 3, 1, 2)

                driving_frame = frame_test
                if not cpu:
                    driving_frame = driving_frame.cuda()
                kp_driving = kp_detector(driving_frame)
                kp_norm = normalize_kp(
                    kp_source=kp_source,
                    kp_driving=kp_driving,
                    kp_driving_initial=kp_driving_initial,
                    use_relative_movement=relative,
                    use_relative_jacobian=relative,
                    adapt_movement_scale=adapt_movement_scale)
                out = generator(source,
                                kp_source=kp_source,
                                kp_driving=kp_norm)
                predictions.append(
                    np.transpose(out['prediction'].data.cpu().numpy(),
                                 [0, 2, 3, 1])[0])
                im = np.transpose(out['prediction'].data.cpu().numpy(),
                                  [0, 2, 3, 1])[0]
                #im = cv2.cvtColor(im,cv2.COLOR_RGB2BGR)
                #cv2_source = cv2.cvtColor(cv2_source,cv2.COLOR_RGB2BGR)
                im = (np.array(im) * 255).astype(np.uint8)
                #cv2_source = (np.array(cv2_source)*255).astype(np.uint8)
                img_im[yoff:yoff + 256, xoff:xoff + 256] = im
                img_cv2_source[yoff:yoff + 256, xoff:xoff + 256] = cv2_source2
                #print(faces)
                #print(type(im))
                if args['debug']:
                    #print("[DEBUG] FPS : ",1.0 / (time.time()-start))
                    fps.append(1.0 / (time.time() - start))
                    if args['cpu']:
                        print("[DEBUG] Avg. of FPS using CPU : ", mean(fps))
                    else:
                        print("[DEBUG] Avg. of FPS using GPU : ", mean(fps))

                if args['csv']:
                    y_vec[-1] = mean(fps)
                    line1 = live_plotter(x_vec, y_vec, line1)
                    y_vec = np.append(y_vec[1:], 0.0)

                if args['vc']:
                    if np.array(faces).any():
                        #joinedFrame = np.concatenate((cv2_source,im,frame1),axis=1)
                        camera.schedule_frame(img_im)
                    else:
                        #joinedFrame = np.concatenate((cv2_source,cv2_source,frame1),axis=1)
                        camera.schedule_frame(img_cv2_source)
                    #cv2.imshow('Test',joinedFrame)
                    #out1.write(img_as_ubyte(np.array(im)))
                count += 1
            else:
                break

        cap.release()
        out1.release()
        cv2.destroyAllWindows()