26 lines
677 B
Python
26 lines
677 B
Python
import cv2
|
|
|
|
convert_gray_scale_cache = {}
|
|
|
|
|
|
def grayscale(img_test_path):
|
|
global convert_gray_scale_cache
|
|
|
|
try:
|
|
if img_test_path in convert_gray_scale_cache.keys():
|
|
pass
|
|
|
|
else:
|
|
# read image
|
|
img_test_rgb = cv2.imread(img_test_path)
|
|
# convert to gray scale
|
|
img_test_gray = cv2.cvtColor(img_test_rgb, cv2.COLOR_BGR2GRAY)
|
|
img_test_gray = cv2.resize(img_test_gray, (1024, 1024))
|
|
convert_gray_scale_cache[img_test_path] = img_test_gray
|
|
|
|
return convert_gray_scale_cache[img_test_path]
|
|
|
|
except:
|
|
print("error during converting to grayscale")
|
|
exit(0)
|