コード例 #1
0
def CheckCropping(videopath,
                  filename,
                  x1,
                  x2,
                  y1,
                  y2,
                  cropping,
                  videotype,
                  time=start):
    ''' Display frame at time "time" for video to check if cropping is fine. 
    Select ROI of interest by adjusting values in myconfig.py
    
    USAGE for cropping:
    clip.crop(x1=None, y1=None, x2=None, y2=None, width=None, height=None, x_center=None, y_center=None)
    
    Returns a new clip in which just a rectangular subregion of the
    original clip is conserved. x1,y1 indicates the top left corner and
    x2,y2 is the lower right corner of the croped region.
    
    All coordinates are in pixels. Float numbers are accepted.
    '''
    videos = auxiliaryfunctions.GetVideoList(filename, videopath, videotype)
    if filename != 'all':
        videotype = filename.split('.')[1]

    for vindex, video in enumerate(videos):
        clip = VideoFileClip(os.path.join(videopath, video))
        print("Extracting ", video)

        ny, nx = clip.size  # dimensions of frame (width, height)
        if cropping == True:
            # Select ROI of interest by adjusting values in myconfig.py
            clip = clip.crop(y1=y1, y2=y2, x1=x1, x2=x2)

        image = clip.get_frame(
            time * clip.duration
        )  #frame is accessed by index *1./clip.fps (fps cancels)
        io.imsave("IsCroppingOK" + video.split('.')[0] + ".png", image)

        if vindex == len(videos) - 1:
            print(
                "--> Open the CroppingOK-videofilename-.png file(s) to set the output range! <---"
            )
            print("--> Adjust shiftx, shifty, fx and fy accordingly! <---")
    return image
コード例 #2
0
x2,y2 is the lower right corner of the croped region.

All coordinates are in pixels. Float numbers are accepted.
'''

image = clip.get_frame(1.2)
io.imsave("IsCroppingOK.png", image)
print("--> Open CroppingOK.png file to set the output range! <---")
print("--> Adjust shiftx, shifty, fx and fy accordingly! <---")

####################################################
# Creating folder with name of experiment and extract random frames
####################################################

print("Videoname: ", filename)
folder = filename.split('.')[0]
auxiliaryfunctions.attempttomakefolder(basefolder + folder)

frames = np.random.randint(math.floor(clip.duration * clip.fps * portion),
                           size=numframes2pick - 1)
width = int(np.ceil(np.log10(clip.duration * clip.fps)))

for index in frames:
    try:
        image = img_as_ubyte(clip.get_frame(index * 1. / clip.fps))
        io.imsave(
            basefolder + folder + "/img" + str(index).zfill(width) + ".png",
            image)
    except:
        print("Frame # ", index, " does not exist.")
コード例 #3
0
basefolder = './' + 'data-' + Task
numbodyparts = len(bodyparts)

# Data frame to hold data of all data sets for different scorers, bodyparts and images
DataCombined = None

os.chdir(basefolder)

DataCombined = pd.read_hdf(
    'CollectedData_' + cfg_scorer + '.h5', 'df_with_missing')

# Make list of different video data sets:
folders = [
    videodatasets for videodatasets in os.listdir(os.curdir)
    if os.path.isdir(videodatasets) and
    filename.split('.')[0] in videodatasets and 'labeled' not in videodatasets
]

print(folders)
# videos=np.sort([fn for fn in os.listdir(os.curdir) if ("avi" in fn)])
scale = 1  # for plotting
msize=25   #size of labels

for folder in folders:
    tmpfolder = folder + 'labeled'
    try:
        os.mkdir(tmpfolder)
    except:
        pass
    os.chdir(folder)
    # sort image file names according to how they were stacked (when labeled in Fiji)
コード例 #4
0
basefolder = './' + 'data-' + Task
numbodyparts = len(bodyparts)

# Data frame to hold data of all data sets for different scorers, bodyparts and images
DataCombined = None

os.chdir(basefolder)

DataCombined = pd.read_hdf('CollectedData_' + cfg_scorer + '.h5',
                           'df_with_missing')

# Make list of different video data sets:
folders = [
    videodatasets for videodatasets in os.listdir(os.curdir)
    if os.path.isdir(videodatasets) and filename.split('.')[0] in videodatasets
    and 'labeled' not in videodatasets
]

print(folders)
# videos=np.sort([fn for fn in os.listdir(os.curdir) if ("avi" in fn)])
scale = 1  # for plotting
msize = 25  #size of labels

for folder in folders:
    tmpfolder = folder + 'labeled'
    try:
        os.mkdir(tmpfolder)
    except:
        pass
    os.chdir(folder)