pipeline.py 文件源码

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

项目:deepvisualminer 作者: pathbreak 项目源码 文件源码
def _execute_pipeline_on_image(self, input_data):

        if input_data['img'].ndim == 3:
            # It *appears* imageio imread returns RGB or RGBA, not BGR...confirmed using a blue
            # filled rectangle that imageio is indeed RGB which is opposite of OpenCV's default BGR.
            # Use RGB consistently everywhere.
            if input_data['img'].shape[-1] == 4:
                input_data['gray'] = cv2.cvtColor(input_data['img'], cv2.COLOR_RGBA2GRAY)
                print("Input image seems to be 4-channel RGBA. Creating 3-channel RGB version")
                input_data['img'] = cv2.cvtColor(input_data['img'], cv2.COLOR_RGBA2RGB)
            else:
                input_data['gray'] = cv2.cvtColor(input_data['img'], cv2.COLOR_RGB2GRAY)

        elif input_data['img'].ndim == 2:
            # If input is a grayscale image, it'll have just 2 dimensions, 
            # but Darkflow code expects 3 dimensions. So always keep 'img' a 3 dimension
            # image no matter what.
            print("Input image is grayscale. Creating RGB version")
            input_data['gray'] = input_data['img'].copy()
            input_data['img'] = cv2.cvtColor(input_data['img'], cv2.COLOR_GRAY2RGB)

        else:
            raise "Unknown image format " + input_data['img'].shape

        print("Input image:", input_data['img'].shape)
        print("Grayscale image:", input_data['gray'].shape)

        for comp in self.components:
            print("Executing %s on %s frame %d" % (comp.name, input_data['file'], input_data.get('frame', 0)))
            comp_outputs = comp.execute(input_data, self.input_directory, self.output_directory)

            # At each stage of the pipeline, collect the component's outputs
            # and add them to the input data so that they're available for 
            # downstream components.
            input_data[comp.name] = comp_outputs


        # Release the image arrays.
        input_data['img'] = None
        input_data['gray'] = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号