Innerhlab dieses Repositorys ist ein showcase ausgearbeitet, welcher live die Funktion des EVM Algorithmus darstellt.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parser.py 2.6KB

3 weeks ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import configparser
  2. # Erstelle eine Parser-Klasse für INI-Dateien
  3. class ParameterParser:
  4. def __init__(self, config_file='config.ini'):
  5. self.config_file = config_file
  6. self.config = configparser.ConfigParser()
  7. self.config.read(self.config_file)
  8. # Ensure 'Parameters' and 'Video' sections exist
  9. if 'Parameters' not in self.config:
  10. self.config['Parameters'] = {}
  11. if 'Video' not in self.config:
  12. self.config['Video'] = {}
  13. def get_parameters(self):
  14. # Lese die Parameter aus der Konfigurationsdatei
  15. try:
  16. alpha = self.config.getfloat('Parameters', 'alpha')
  17. cutoff = self.config.getfloat('Parameters', 'cutoff')
  18. low = self.config.getfloat('Parameters', 'low')
  19. high = self.config.getfloat('Parameters', 'high')
  20. chromAttenuation = self.config.getfloat('Parameters', 'chromAttenuation')
  21. mode = self.config.getint('Parameters', 'mode')
  22. # Read video parameters
  23. width = self.config.getint('Video', 'width', fallback=1280)
  24. height = self.config.getint('Video', 'height', fallback=720)
  25. fps = self.config.getint('Video', 'fps', fallback=30)
  26. return {
  27. "alpha": alpha,
  28. "cutoff": cutoff,
  29. "low": low,
  30. "high": high,
  31. "chromAttenuation": chromAttenuation,
  32. "mode": mode,
  33. "width": width,
  34. "height": height,
  35. "fps": fps
  36. }
  37. except Exception as e:
  38. print(f"Error reading config: {e}")
  39. return None
  40. def set_parameters(self, alpha, cutoff, low, high, chromAttenuation, mode, width, height, fps):
  41. # Schreibe die Parameter in die Konfigurationsdatei
  42. self.config['Parameters'] = {
  43. 'alpha': str(alpha),
  44. 'cutoff': str(cutoff),
  45. 'low': str(low),
  46. 'high': str(high),
  47. 'chromAttenuation': str(chromAttenuation),
  48. 'mode': str(mode)
  49. }
  50. # Save video parameters
  51. self.config['Video'] = {
  52. 'width': str(width),
  53. 'height': str(height),
  54. 'fps': str(fps)
  55. }
  56. with open(self.config_file, 'w') as configfile:
  57. self.config.write(configfile)
  58. # Beispiel: Erstellen und Speichern von Parametern
  59. if __name__ == "__main__":
  60. parser = ParameterParser()
  61. # Beispielwerte speichern
  62. parser.set_parameters(0.5, 1.0, 0.2, 1.5, 0.8, 1, 1280, 720, 30)
  63. # Parameter auslesen
  64. parameters = parser.get_parameters()
  65. print(parameters)