def get_sport_clip(clip_name, verbose=True):
"""
Loads a clip to be fed to C3D for classification.
TODO: should I remove mean here?
Parameters
----------
clip_name: str
the name of the clip (subfolder in 'data').
verbose: bool
if True, shows the unrolled clip (default is True).
Returns
-------
Tensor
a pytorch batch (n, ch, fr, h, w).
"""
clip = sorted(glob(join('data', clip_name, '*.png')))
clip = np.array([resize(io.imread(frame), output_shape=(112, 200), preserve_range=True) for frame in clip])
clip = clip[:, :, 44:44+112, :] # crop centrally
if verbose:
clip_img = np.reshape(clip.transpose(1, 0, 2, 3), (112, 16 * 112, 3))
io.imshow(clip_img.astype(np.uint8))
io.show()
clip = clip.transpose(3, 0, 1, 2) # ch, fr, h, w
clip = np.expand_dims(clip, axis=0) # batch axis
clip = np.float32(clip)
return torch.from_numpy(clip)
python类show()的实例源码
def selectiveSearch(image):
segments = felzenszwalb(image, scale=kFelzenszwalbScale)
numRegions = segments.max()
rectangles = []
for regionTag in range(numRegions):
selectedRegion = segments == regionTag
regionPixelIndices = np.transpose(np.nonzero(selectedRegion))
rectangle = aabb(regionPixelIndices)
rectangles.append(rectangle)
# Implement similarities, neighbourhood merging.
# Felzenszwalb's segmentation is ridiculously good already.
def debug():
marked = np.zeros(image.shape, dtype=np.uint8)
for rectangle in rectangles:
rr, cc = rectangle.pixels(marked.shape)
randcolor = randint(0, 255), randint(0, 255), randint(0, 255)
marked[rr, cc] = randcolor
print(image.shape, segments.shape, marked.shape)
io.imshow_collection([image, segments, marked])
io.show()
# debug()
return rectangles