def _process_file(self, input_path, output_path, models): input_name = os.path.basename(input_path) print("Processing", input_name) # read input input_image = cv2.imread(input_path, cv2.IMREAD_UNCHANGED) if input_image is None: print("Unsupported image format:", input_path) return # start with an unmodified image output_image = input_image # apply all models from the list for model in models: print("Applying model '%s'" % model.name()) upscaler = upscale.RRDBNetUpscaler(model, self.torch) output_image = self._process_image(output_image, upscaler) # write output cv2.imwrite(output_path, output_image)
def fa(): page = int(request.args.get('page')) limit = int(request.args.get('limit')) if request.args.get('id'): # 判断是否有用搜所框查找 data = request.args.get('id') try: data = int(data) # 判断是按学号查找还是姓名查找 bb = {"code": 0, "msg": "", "count": 1000, "data": xuehao(data)} bb = json.dumps(bb) return bb except ValueError: bb = {"code": 0, "msg": "", "count": 1000, "data": name(data)} bb = json.dumps(bb) return bb else: bb = { "code": 0, "msg": "", "count": 1000, "data": qwe()[(page - 1) * limit:page * limit] } bb = json.dumps(bb) return bb
def main(self): parser = argparse.ArgumentParser(description="ESRGAN image upscaler") parser.add_argument("input", help="Path to input folder") parser.add_argument("output", help="Path to output folder") parser.add_argument( "--model", action="append", required=True, help="path to upscaling model file (can be used repeatedly)") parser.add_argument( "--device", default=self.device, help="select Torch device (typically 'cpu' or 'cuda')") parser.add_argument( "--prefilter", action="append", metavar="FILE", help= "path to model file applied before upscaling (can be used repeatedly)" ) parser.add_argument( "--postfilter", action="append", metavar="FILE", help= "path to model file applied after upscaling (can be used repeatedly)" ) parser.add_argument( "--tilesize", type=int, metavar="N", default=self.tile_size, help="width/height of tiles in pixels (0 = don't use tiles)") parser.add_argument( "--perchannel", action="store_true", help="process each channel individually as grayscale image") parser.add_argument( "--noalpha", action="store_true", help="ignore alpha channels from input and output RGB only") args = parser.parse_args() self.device = args.device self.torch = torch.device(self.device) self.tile_size = args.tilesize self.per_channel = args.perchannel self.no_alpha = args.noalpha self.models_upscale = self._parse_model(args.model) self.models_prefilter = self._parse_model(args.prefilter) self.models_postfilter = self._parse_model(args.postfilter) if not any((self.models_upscale, self.models_prefilter, self.models_postfilter)): print("No models selected or found!") return 1 for model_upscale in self.models_upscale: models = self.models_prefilter + [model_upscale ] + self.models_postfilter model_name = "_".join([model.name() for model in models]) print("Model pass '%s'" % model_name) output_dir = os.path.join(args.output, model_name) os.makedirs(output_dir, exist_ok=True) if os.path.isdir(args.input): for dirpath, _, filenames in os.walk(args.input): for filename in filenames: input_path = os.path.join(dirpath, filename) input_path_rel = os.path.relpath( input_path, args.input) output_path_rel = os.path.splitext( input_path_rel)[0] + ".png" output_path = os.path.join(output_dir, output_path_rel) os.makedirs(os.path.dirname(output_path), exist_ok=True) self._process_file(input_path, output_path, models) else: for input_path in glob.glob(args.input): if os.path.isdir(input_path): continue input_name = os.path.basename(input_path) output_name = os.path.splitext(input_name)[0] + ".png" output_path = os.path.join(output_dir, output_name) self._process_file(input_path, output_path, models)