1from GameBEye.gbcamimage import gbcamimage
2from GameBEye.gbcamcolors.color_helpers import hex_to_rgb
3import numpy as np
4import cv2
5import os
6
7for root, dirs, images in os.walk("images"):
8 images = [
9 os.path.join("images", image)
10 for image in images
11 if image.endswith(".png")
12 ]
13 for image in images:
14 gb_image = gbcamimage.GBCamImage()
15
16 # Reading of the file
17 gb_image.read(image)
18
19 # Displaying the colorized image
20 image_title = "Colorized image with {} color palette".format(
21 gb_image.color_palette.name
22 )
23 cv2.imshow(image_title, gb_image.data)
24
25 # Create a numpy image with each color of the gb_image color palette
26 # Join them to have a 4-elements array to print the color palette
27 color_palettes = []
28 for color in gb_image.color_palette.value:
29 rgb_color = hex_to_rgb(color)
30 red = rgb_color[0] * np.ones((112, 128)).astype("uint8")
31 green = rgb_color[1] * np.ones((112, 128)).astype("uint8")
32 blue = rgb_color[2] * np.ones((112, 128)).astype("uint8")
33 color_palettes.append(cv2.merge([blue, green, red]))
34 color_palettes = cv2.hconcat(color_palettes)
35
36 color_palette_title = "Color palettes {}".format(
37 gb_image.color_palette.name
38 )
39 cv2.imshow(color_palette_title, color_palettes)
40
41 cv2.waitKey()
42 cv2.destroyWindow(image_title)
43 cv2.destroyWindow(color_palette_title)