OpenCV (cv2) đọc ảnh, chuyển RGB, dùng PIL/Pillow chuyển thành PhotoImage hiển thị trên Tkinter Label.
Các bước
- Cài OpenCV:
pip install opencv-python - Import cv2, numpy, PIL.
- Đọc ảnh: imread().
- Tách/kết hợp kênh màu BGR→RGB: split(), merge().
- Chuyển mảng thành Image: Image.fromarray().
- Tạo PhotoImage: ImageTk.PhotoImage().
- Hiển thị trên Label.
Ví dụ
# Import thư viện
from tkinter import *
import numpy as np
import cv2
from PIL import Image, ImageTk
# Tạo khung
win = Tk()
win.geometry("700x550")
# Đọc ảnh
img = cv2.imread('tutorialspoint.png')
# Sắp xếp lại kênh màu BGR -> RGB
blue, green, red = cv2.split(img)
img = cv2.merge((red, green, blue))
im = Image.fromarray(img)
imgtk = ImageTk.PhotoImage(image=im)
# Hiển thị
Label(win, image=imgtk).pack()
win.mainloop()Kết quả
Hiển thị ảnh tutorialspoint.png trong cửa sổ Tkinter.

Đảm bảo file ảnh cùng thư mục với code.