如何在python中为子文件夹中的所有图像运行mogrify脚本?

2024-04-25 23:29:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用opencv在wiki数据集中加载图像,其中的图像被组织到99个文件夹中。我有这个密码。你知道吗

def load_images(self,dataframe):
        if dataframe is None:
            return None
        else:
            assert type(dataframe) == pd.core.frame.DataFrame, "argument to load image should be dataframe"
            assert  "file_location" in dataframe.columns, "dataframe should contain file_location column"
            output_images = np.zeros((len(dataframe),self.config.image_shape[0],self.config.image_shape[1],self.config.image_shape[2]))
            for index,row in dataframe.iterrows():
                img = cv2.imread(os.path.join(self.config.dataset_dir,row["file_location"][0]))

                if img is None:
                    Log.WARNING("Unable to read images from "+os.path.join(self.config.dataset_dir,row["file_location"][0]))
                    continue
                face_location = row["face_location"][0].astype(int)
                face_image = img[face_location[1]:face_location[3],face_location[0]:face_location[2]]
                face_image = cv2.cvtColor(face_image,cv2.COLOR_BGR2GRAY)
                face_image = cv2.resize(face_image,(self.config.image_shape[0],self.config.image_shape[1]))
                output_images[index] = face_image.reshape(self.config.image_shape)
            return output_images

我想在运行代码时删除这样的错误

libpng warning: iCCP: profile 'icc': 'RGB ': RGB color space not permitted on grayscale PNG

Tags: 图像imageselfnoneconfigdataframeimgoutput