在 Python OpenCV 中将字符串渲染为库属性
Render String as a Library Attribute in Python OpenCV
我想呈现一个包含字符串值作为库属性的数组,但第 3 行抛出错误。
color_maps = ['AUTUMN','BONE', 'COOL', 'HOT', 'HSV', 'JET', 'OCEAN', 'PINK', 'RAINBOW','SPRING', 'SUMMER', 'WINTER']
image = cv2.imread('hurricane katrina 1.png', cv2.IMREAD_GRAYSCALE)
image_color_map = cv2.applyColorMap(image, cv2."COLORMAP_" + color_maps[0])
我将如何在 Python 中做到这一点?
使用getattrbuilt-in函数:
color_maps = ['AUTUMN','BONE', 'COOL', 'HOT', 'HSV', 'JET', 'OCEAN', 'PINK', 'RAINBOW','SPRING', 'SUMMER', 'WINTER']
image = cv2.imread('hurricane katrina 1.png', cv2.IMREAD_GRAYSCALE)
image_color_map = cv2.applyColorMap(image, getattr(cv2,"COLORMAP_" + color_maps[0]))
我想呈现一个包含字符串值作为库属性的数组,但第 3 行抛出错误。
color_maps = ['AUTUMN','BONE', 'COOL', 'HOT', 'HSV', 'JET', 'OCEAN', 'PINK', 'RAINBOW','SPRING', 'SUMMER', 'WINTER']
image = cv2.imread('hurricane katrina 1.png', cv2.IMREAD_GRAYSCALE)
image_color_map = cv2.applyColorMap(image, cv2."COLORMAP_" + color_maps[0])
我将如何在 Python 中做到这一点?
使用getattrbuilt-in函数:
color_maps = ['AUTUMN','BONE', 'COOL', 'HOT', 'HSV', 'JET', 'OCEAN', 'PINK', 'RAINBOW','SPRING', 'SUMMER', 'WINTER']
image = cv2.imread('hurricane katrina 1.png', cv2.IMREAD_GRAYSCALE)
image_color_map = cv2.applyColorMap(image, getattr(cv2,"COLORMAP_" + color_maps[0]))