Example #1
0
    def _track_process(self, group_number):
        data_name = (str(group_number) + '.hdf5'
                     if self.multiprocess else self.dataname)
        with dataframes.DataStore(data_name, load=False) as data:
            data.add_metadata('num_frames', self.num_frames)
            data.add_metadata('video_filename', self.vidname)
            data.add_metadata('crop', self.manager.preprocessor.crop)
            start = self.frame_div * group_number
            vid = video.ReadVideo(self.vidname)
            vid.set_frame(start)
            if group_number == 3:
                missing = self.num_frames - self.num_processes * (
                    self.frame_div)
                frame_div = self.frame_div + missing
            else:
                frame_div = self.frame_div

            # Iterate over frames
            for f in tqdm(range(frame_div), 'Tracking'):
                frame = vid.read_next_frame()
                info, boundary, info_headings = self.manager.analyse_frame(
                    frame)
                data.add_tracking_data(start + f, info,
                                       col_names=info_headings)
                if f == 0:
                    data.add_metadata('boundary', boundary)
Example #2
0
    def _get_video_info(self):
        vid = video.ReadVideo(self.vidname)
        self.num_frames = vid.num_frames
        self.fps = vid.fps
        self.frame_div = self.num_frames // self.num_processes

        # Get width and height of a processed frame (may be different)
        frame = vid.read_next_frame()
        new_frame, _, _ = self.manager.process(frame)
Example #3
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)
Example #4
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)
Example #5
0
def get_crop_result(file):
    vid = video.ReadVideo(file)
    frame = vid.read_next_frame()
    return images.crop_polygon(frame)
Example #6
0
    return mask_from_polygon(im, metadata['boundary'])

def get_crop_region(im, corners, factor=0.8):
    center = np.mean(corners, axis=0)
    vectors = corners - center
    angles = np.arctan2(vectors[:, 1], vectors[:, 0])
    lengths = np.sqrt(vectors[:, 0] ** 2 + vectors[:, 1] ** 2)
    new_vectors = np.array([np.cos(angles), np.sin(angles)]).T
    new_vectors *= lengths[:, np.newaxis] * factor
    new_corners = center + new_vectors
    return new_corners

vid_file = "/media/data/Data/FirstOrder/Hysterisis/5Repeats/RedTrayDense/0.1_down_1.MP4"
data_file = os.path.splitext(vid_file)[0] + '.hdf5'

vid = video.ReadVideo(vid_file)
metadata = dataframes.load_metadata(data_file)

print(metadata['boundary'].shape)

start = vid.read_frame(0)
middle = vid.read_frame(vid.num_frames // 2)
end = vid.read_frame(vid.num_frames - 1)

start = crop_then_mask(start)
middle = crop_then_mask(middle)
end = crop_then_mask(end)

save_direc = "/media/data/Data/FirstOrder/Hysterisis/5Repeats/RedTrayDense/HexagonFigures"

images.save(start, f'{save_direc}/start.png')
from labvision import video, images

vid = video.ReadVideo("/home/ppxjd3/Code/labvision/labvision/data/numbered_video.mp4", frame_range=(0, 100, 10))

for f in range(vid.num_frames):
    frame = vid.read_next_frame()
    images.display(frame, f"{f}")
Example #8
0
    '0.8': ['16870011', '16870012'],
    '1': ['16870013', '16870014'],
    '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],
from labvision import video, images

vid = video.ReadVideo(
    "/home/ppxjd3/Code/labvision/labvision/data/numbered_video.mp4")

frame_numbers = [0, 1, 2, 3, 10, 11, 20, 21, 20, 19, 18]

for f in frame_numbers:
    frame1 = vid.read_frame(f)
    frame2 = vid.read_frame(f)
    frame = images.hstack(frame1, frame2)
    images.display(frame, title=f'{f}')
Example #10
0
 def test_read_mkv(self):
     vid = video.ReadVideo(mkvpath)
     frame = vid.read_next_frame()
     self.assertTrue(type(frame) == np.ndarray)
Example #11
0
 def test_video_slicerator(self):
     vid = video.ReadVideo(videopath)
     for frame in vid[:2]:
         self.assertTrue(type(frame) == np.ndarray)
from labvision import video, images
from scipy import ndimage

liquid_file = "/media/data/Data/Orderphobic/TwoIntruders/SpikyIntruder/Logging/080121_liquid_580/out.mp4"

solid_file = "/media/data/Data/Orderphobic/TwoIntruders/SpikyIntruder/Logging/060121_solid_600_more_balls/out.mp4"

liquid = video.ReadVideo(liquid_file)
solid = video.ReadVideo(solid_file)

NL = liquid.num_frames
NS = solid.num_frames

N = min(NL, NS)


def get_crop_result(vid):
    frame = vid.read_next_frame()
    frame = ndimage.rotate(frame, -120, reshape=False)
    crop_result = images.crop_rectangle(frame)
    vid.set_frame(0)
    return crop_result


def fix_frame(frame):
    frame = ndimage.rotate(frame, -120, reshape=False)
    frame = images.crop_and_mask(frame, crop_result.bbox, crop_result.mask)
    return frame


crop_result = get_crop_result(liquid)
Example #13
0
from labvision import images, video

vid = video.ReadVideo(
    "/media/data/Data/BallBearing/HIPS/PhaseDiagrams/2,31mm/density70.MP4")

frame = vid.read_next_frame()

crop_result = images.crop_polygon(frame)

cropped = images.crop_and_mask(frame, crop_result.bbox, crop_result.mask)

images.displa