| 1 | import cv2 as cv
 | 
  
    | 2 | import numpy as np
 | 
  
    | 3 | import os
 | 
  
    | 4 | from PIL import Image
 | 
  
    | 5 | import tkinter as tk
 | 
  
    | 6 | 
 | 
  
    | 7 | class ImageIO:
 | 
  
    | 8 |     def __init__(self, shared_data):
 | 
  
    | 9 |         self.shared_data = shared_data
 | 
  
    | 10 | 
 | 
  
    | 11 |     def load_image(self, path):
 | 
  
    | 12 |         return cv.imread(path, cv.IMREAD_COLOR)
 | 
  
    | 13 | 
 | 
  
    | 14 |     def write_image(self, img, fileName="image.png"):
 | 
  
    | 15 |         if cv.imwrite(fileName, img):
 | 
  
    | 16 |             print(f"File {fileName} Written Successfully")
 | 
  
    | 17 |         else:
 | 
  
    | 18 |             print("File writing failed")
 | 
  
    | 19 | 
 | 
  
    | 20 |     def show_image(self, img, title="Image Title", canvas=None):
 | 
  
    | 21 |         # Set up OpenCV fullscreen window in the main thread
 | 
  
    | 22 |         cv.namedWindow(title, cv.WINDOW_NORMAL)
 | 
  
    | 23 |         cv.setWindowProperty(title, cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN)
 | 
  
    | 24 |         
 | 
  
    | 25 |         # Resize the image to 1920x1080 resolution
 | 
  
    | 26 |         img_resized = cv.resize(img, (1920, 1080), interpolation=cv.INTER_LINEAR)
 | 
  
    | 27 |         
 | 
  
    | 28 |         # Display the resized image in OpenCV and keep it open without blocking Tkinter
 | 
  
    | 29 |         cv.imshow(title, img_resized)
 | 
  
    | 30 | 
 | 
  
    | 31 |         # Run a non-blocking loop to keep OpenCV window and Tkinter GUI responsive
 | 
  
    | 32 |         while cv.getWindowProperty(title, cv.WND_PROP_VISIBLE) >= 1:
 | 
  
    | 33 |             cv.waitKey(1)
 | 
  
    | 34 |             if canvas:
 | 
  
    | 35 |                 canvas.update_idletasks()
 | 
  
    | 36 |                 canvas.update()
 | 
  
    | 37 | 
 | 
  
    | 38 |         # Close the OpenCV window once the loop ends
 | 
  
    | 39 |         cv.destroyAllWindows()
 |