fileio.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:GulpIO 作者: TwentyBN 项目源码 文件源码
def read_frames(self, id_, slice_=None):
        """ Read frames for a single item.

        Parameters
        ----------
        id_: (str)
            The ID of the item
        slice_: (slice:
            A slice with which to select frames.
        Returns
        -------
        frames (int), meta(dict)
            The frames of the item as a list of numpy arrays consisting of
            image pixel values. And the metadata.

        """
        frame_infos, meta_data = self._get_frame_infos(id_)
        frames = []
        slice_element = slice_ or slice(0, len(frame_infos))

        def extract_frame(frame_info):
            self.fp.seek(frame_info.loc)
            record = self.fp.read(frame_info.length)
            img_str = record[:len(record)-frame_info.pad]
            nparr = np.fromstring(img_str, np.uint8)
            img = cv2.imdecode(nparr, cv2.IMREAD_ANYCOLOR)
            if img.ndim > 2:
                img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
            return img
        frames = [extract_frame(frame_info)
                  for frame_info in frame_infos[slice_element]]
        return frames, meta_data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号