Project

General

Profile

Feature #944 » MainDisplay.py

Xinai ZHANG , 01/18/2024 01:22 PM

 
1
#!/usr/bin/env python3
2
#-*- coding: utf-8 -*-
3

    
4
import cv2
5

    
6
##
7
# @brief Responsible for the main display operations of images.
8
#
9
# This class handles reading, setting, and displaying images using OpenCV.
10
##
11
class MainDisplay:
12

    
13
    ##
14
    # @brief Initializes the MainDisplay object.
15
    #
16
    # This constructor initializes the result image to None.
17
    ##
18
    def __init__(self):
19
        self.result_image = None
20

    
21
    ##
22
    # @brief Reads an image from a given file path.
23
    #
24
    # @param image_path str: The file path of the image to be read.
25
    # @return The read image.
26
    ##
27
    def readImage(self, image_path):
28
        image = cv2.imread(image_path)
29
        return image
30

    
31
    ##
32
    # @brief Sets the image for display.
33
    #
34
    # @param image: The image to be displayed.
35
    # @return The set image.
36
    ##
37
    def setImage(self, image):
38
        self.result_image = image
39
        return self.result_image
40

    
41
    ##
42
    # @brief Displays the set image.
43
    #
44
    # Opens a window to display the set image. The window closes upon any key press.
45
    ##
46
    def saveImage(self):
47
        cv2.imshow(f"Displaying {self.result_image}", self.result_image)
48
        cv2.waitKey(0)
49
        cv2.destroyAllWindows()
(1-1/3)