Project

General

Profile

Files » sharedDataClass.py

SharedDataClass - Zhuorong LIU, 10/31/2024 01:20 PM

 
1
import cv2 as cv
2
import numpy as np
3
import tkinter as tk
4
from tkinter import filedialog, messagebox
5
import os
6
from PIL import Image, ImageTk
7
import configparser
8

    
9

    
10
class SharedData:
11
    def __init__(self):
12
        self.left_image = None
13
        self.right_image = None
14
        self.overlap_region = 0
15

    
16
    def save_to_ini(self, filename):
17
        """Save the current data to an .ini file."""
18
        config = configparser.ConfigParser()
19
        
20
        # Create a section and add attributes
21
        config['Images'] = {
22
            'left_image': self.left_image,
23
            'right_image': self.right_image,
24
            'overlap_region': str(self.overlap_region)
25
        }      
26
        # Write to the .ini file
27
        with open(filename, 'w') as configfile:
28
            config.write(configfile)
29

    
30
    def load_from_ini(self, filename):
31
        """Load data from an .ini file."""
32
        config = configparser.ConfigParser()
33
        config.read(filename)
34

    
35
        # Read attributes from the section
36
        if 'Images' in config:
37
            self.left_image = config['Images'].get('left_image')
38
            self.right_image = config['Images'].get('right_image')
39
            self.overlap_region = config['Images'].getint('overlap_region')
40

    
(22-22/49)