Exemplo n.º 1
0
def get_circles(frame, left_crop, right_crop):
    red = frame[:, :, 0] - frame[:, :, 2]
    red = images.threshold(red, 65)
    opened = images.opening(red, (31, 31))
    w = opened.shape[1]
    im1 = images.crop(opened, left_crop.bbox)
    im2 = images.crop(opened, right_crop.bbox)
    m1 = list(images.center_of_mass(im1))
    m2 = list(images.center_of_mass(im2))
    m1[0] += left_crop.bbox.xmin
    m1[1] += left_crop.bbox.ymin
    m2[0] += right_crop.bbox.xmin
    m2[1] += right_crop.bbox.ymin

    return np.array([[m1[0], m1[1], 50], [m2[0], m2[1], 50]])
Exemplo n.º 2
0
 def get_frame(self, crop=True):
     frame = self.cam.get_frame()
     if self.R != 0:
         frame = ndimage.rotate(frame, self.R, reshape=False)
     if crop:
         frame = images.crop(frame, self.crop)
     return frame
Exemplo n.º 3
0
    def get_circles(self, frame):
        red = frame[:, :, 0] - frame[:, :, 2]
        red = images.threshold(red, 65)
        opened = images.opening(red, (31, 31))
        im1 = images.crop(opened, self.left_crop.bbox)
        im2 = images.crop(opened, self.right_crop.bbox)
        if self.TRACK_LEFT:
            m1 = list(images.center_of_mass(im1))
        else:
            m1 = [im1.shape[1] // 2, im1.shape[0] // 2]
        if self.TRACK_RIGHT:
            m2 = list(images.center_of_mass(im2))
        else:
            m2 = [im2.shape[1] // 2, im2.shape[0] // 2]

        m1[0] += self.left_crop.bbox.xmin
        m1[1] += self.left_crop.bbox.ymin
        m2[0] += self.right_crop.bbox.xmin
        m2[1] += self.right_crop.bbox.ymin

        return np.array([[m1[0], m1[1], 50], [m2[0], m2[1], 50]])
Exemplo n.º 4
0
def check(filename):
    core_name = os.path.splitext(filename)[0]
    vid_name = core_name + '.MP4'
    data_name = core_name + '.hdf5'
    out_name = core_name + '_check.png'
    data = dataframes.DataStore(data_name)
    crop = data.metadata['crop']
    vid = video.ReadVideo(vid_name)
    print(vid_name)
    frames = np.arange(4)*vid.num_frames//4
    ims = [images.crop(vid.read_frame(f), crop) for f in frames]
    circles = [data.get_info(f, ['x', 'y', 'r']) for f in frames]
    new_ims = [images.draw_circles(im, c) for im, c in zip(ims, circles)]
    out = images.vstack(images.hstack(new_ims[0], new_ims[1]),
                        images.hstack(new_ims[2], new_ims[3]))
    images.save(out, out_name)
Exemplo n.º 5
0
from particletracking import dataframes
from labvision import video, images
import numpy as np

import filehandling

file_store = "/media/data/Data/FirstOrder/Hysterisis/FlatPlate/Trial2/0.2_up_1.hdf5"
file_vid = "/media/data/Data/FirstOrder/Hysterisis/FlatPlate/Trial2/0.2_up_1.MP4"

metadata = dataframes.load_metadata(file_store)
vid = video.ReadVideo(file_vid)

box = metadata['crop']

frame = vid.read_frame(vid.num_frames - 1)
frame = images.crop(frame, box)

xmin = 750
xmax = 1250
ymin = 750
ymax = 1250

vertices = np.array([[xmin, ymin], [xmin, ymax], [xmax, ymax], [xmax, ymin]])

frame = images.draw_polygon(frame, vertices, thickness=3)
images.save(
    frame,
    "/media/data/Data/FirstOrder/Hysterisis/FlatPlate/Trial2/HexagonFigures/box_end.png"
)
images.display(frame)
Exemplo n.º 6
0
def get_frame():
    frame = cam.get_frame()
    if R != 0:
        frame = ndimage.rotate(frame, R, reshape=False)
    frame = images.crop(frame, crop)
    return frame
Exemplo n.º 7
0
def crop_then_mask(im):
    im = images.crop(im, metadata['crop'])
    return mask_from_polygon(im, metadata['boundary'])
def get_frame():
    frame = cam.get_frame()
    # frame = ndimage.rotate(frame, -120, reshape=False)
    frame = images.crop(frame, crop)
    return frame
Exemplo n.º 9
0
    '2': ['16870015', '16870016']
}

files = {r: [direc + d, direc + u] for r, (d, u) in files.items()}
for i, (rate, (down, up)) in enumerate(files.items()):
    print(i)
    print(rate)
    fig, ax = plt.subplots()
    ax.set_title(rate)
    down_data = dataframes.DataStore(down + '.hdf5')
    up_data = dataframes.DataStore(up + '.hdf5')

    if i == 0:
        up_video = video.ReadVideo(up + '.MP4')
        frame = up_video.read_next_frame()
        frame = images.crop(frame, up_data.metadata['crop'])
        result = images.crop_polygon(frame)
        bbox = result.bbox
        with open(save_direc + 'bbox.txt', 'w') as f:
            f.writelines([
                'BBOX xmin, xmax, ymin, ymax',
                str(bbox.xmin),
                str(bbox.xmax),
                str(bbox.ymin),
                str(bbox.ymax)
            ])
        frame = images.draw_polygon(
            frame,
            np.array([[bbox.xmin, bbox.ymin], [bbox.xmin, bbox.ymax],
                      [bbox.xmax, bbox.ymax], [bbox.xmax, bbox.ymin]],
                     dtype=np.float32),
Exemplo n.º 10
0
def get_frame():
    frame = cam.get_frame()
    frame = images.crop(frame, crop)
    return frame