File: img_utils.py

package info (click to toggle)
opencv 4.10.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 282,092 kB
  • sloc: cpp: 1,178,079; xml: 682,621; python: 49,092; lisp: 31,150; java: 25,469; ansic: 11,039; javascript: 6,085; sh: 1,214; cs: 601; perl: 494; objc: 210; makefile: 173
file content (19 lines) | stat: -rw-r--r-- 474 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import cv2
import numpy as np

from .test.configs.default_preprocess_config import BASE_IMG_SCALE_FACTOR


def read_rgb_img(img_file, is_bgr_to_rgb=True):
    img = cv2.imread(img_file, cv2.IMREAD_COLOR)
    if is_bgr_to_rgb:
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    return img


def get_pytorch_preprocess(img):
    img = img.astype(np.float32)
    img *= BASE_IMG_SCALE_FACTOR
    img -= [0.485, 0.456, 0.406]
    img /= [0.229, 0.224, 0.225]
    return img