DeOldify icon indicating copy to clipboard operation
DeOldify copied to clipboard

results don't look as expected

Open nimamoradi opened this issue 7 years ago • 2 comments

i newbie in image processing so my question might look silly
i want to colorized and video i used cv2.VideoCapture to iterate video frame by frame
i don't want to save each frame to file both for original video and colorized one
so in loop i transformed images

          for filt in vis.filters:
             filtered_image = filt.filter(image, image_fir, render_factor=38)
           

here is a sample original picture

image i save filtered_image in VideoWriter
output is like this image

while i can produce good looking images if i use file



for img in os.listdir("/path/"):
  img_path = "/path/" + str(img)
  if os.path.isfile(img_path):
       vis.plot_transformed_image(img_path) 

image @jantic

nimamoradi avatar Mar 15 '19 17:03 nimamoradi

I don't have full context to be sure if I'm correct, but it looks most likely that you're not preprocessing the images in the same way as the open_image function does, which is used in visualize.py. I'll paste that here for convenience. So tl;dr- I'd use the open_image function if you aren't already to get the images.

def open_image(fn):
    """ Opens an image using OpenCV given the file path.
    Arguments:
        fn: the file path of the image
    Returns:
        The image in RGB format as numpy array of floats normalized to range between 0.0 - 1.0
    """
    flags = cv2.IMREAD_UNCHANGED+cv2.IMREAD_ANYDEPTH+cv2.IMREAD_ANYCOLOR
    if not os.path.exists(fn) and not str(fn).startswith("http"):
        raise OSError('No such file or directory: {}'.format(fn))
    elif os.path.isdir(fn) and not str(fn).startswith("http"):
        raise OSError('Is a directory: {}'.format(fn))
    else:
        #res = np.array(Image.open(fn), dtype=np.float32)/255
        #if len(res.shape)==2: res = np.repeat(res[...,None],3,2)
        #return res
        try:
            if str(fn).startswith("http"):
                req = urllib.urlopen(str(fn))
                image = np.asarray(bytearray(req.read()), dtype="uint8")
                im = cv2.imdecode(image, flags).astype(np.float32)/255
            else:
                im = cv2.imread(str(fn), flags).astype(np.float32)/255
            if im is None: raise OSError(f'File not recognized by opencv: {fn}')
            return cv2.cvtColor(im, cv2.COLOR_BGR2RGB)
        except Exception as e:
            raise OSError('Error handling image at: {}'.format(fn)) from e

jantic avatar Mar 19 '19 00:03 jantic

Closing

jantic avatar Mar 19 '19 19:03 jantic