"""
Some support function for tkinter
"""
import logging
import tkinter

import numpy as np
from PIL import Image, ImageTk

LOGGER = logging.getLogger(__name__)

class TkConverter(object):
    def __init__(self):
        super().__init__()

    @staticmethod
    def read(image_path):
        img = Image.open(image_path)
        photo = ImageTk.PhotoImage(img)
        return photo

    @staticmethod
    def ndarray_to_photo(arr):
        h, w = arr.shape[0], arr.shape[1]
        byte_photo = Image.frombytes('L', (w, h), arr.astype('b').tostring())
        tk_photo = ImageTk.PhotoImage(byte_photo)
        return tk_photo

@@ -66,16 +66,27 @@
 kinter%0A%0A
+import cv2%0A
 import n
@@ -627,12 +627,205 @@
 rn tk_photo%0A
+%0A    @staticmethod%0A    def cv2_to_photo(img):%0A        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)%0A        arr = Image.fromarray(img)%0A        photo = ImageTk.PhotoImage(arr)%0A        return photo%0A

convert cv2 image to photo