A simple UI for displaying a photo

This commit is contained in:
2024-03-06 21:44:13 -05:00
parent 3f22a0373f
commit 0a830b2dd7
3 changed files with 176 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
downloaded_files/
downloaded_files/
testing/

50
gui.py Normal file
View File

@ -0,0 +1,50 @@
# This module handles the GUI of coin
import pytesseract
import cv2, os, sys
from PIL import Image
import PyQt5
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5 import uic
from PyQt5 import QtCore, QtGui, QtWidgets
import glob
# [!!!] Change this if tesseract can't find any data
models_path = '/usr/share/tessdata/'
# Automatically finds all available language models
models_list = glob.glob(models_path + "*.traineddata")
model_names = []
for path in models_list:
base_name = os.path.basename(path)
base_name = os.path.splitext(base_name)[0]
model_names.append(base_name)
class coin_app(QtWidgets.QMainWindow):
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
self.ui = uic.loadUi('selector.ui', self)
self.image = None
self.ui.openButton.clicked.connect(self.open)
def open(self):
filename = QFileDialog.getOpenFileName(self, 'Select File')
print("Opening file: ", filename[0])
self.image = cv2.imread(str(filename[0]))
if self.image.size == 0:
print("Error: image is empty!")
frame = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB)
image = QImage(frame, frame.shape[1], frame.shape[0],
frame.strides[0], QImage.Format_RGB888)
self.ui.photo.setPixmap(QPixmap.fromImage(image))
print("Updated photo")
app = QtWidgets.QApplication(sys.argv)
mainWindow = coin_app()
mainWindow.show()
sys.exit(app.exec_())

124
selector.ui Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1280</width>
<height>720</height>
</rect>
</property>
<property name="font">
<font>
<family>Droid Sans Mono</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="windowTitle">
<string>coin</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QPushButton" name="openButton">
<property name="geometry">
<rect>
<x>680</x>
<y>20</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Open image</string>
</property>
</widget>
<widget class="QScrollArea" name="imageView">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>651</width>
<height>671</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOn</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>635</width>
<height>655</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="photo">
<property name="text">
<string>Photo</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QPushButton" name="saveButton">
<property name="geometry">
<rect>
<x>970</x>
<y>20</y>
<width>171</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Save to database</string>
</property>
</widget>
<widget class="QPushButton" name="getNameButton">
<property name="geometry">
<rect>
<x>810</x>
<y>20</y>
<width>151</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Get item names</string>
</property>
</widget>
<widget class="QTableView" name="itemsTable">
<property name="geometry">
<rect>
<x>685</x>
<y>61</y>
<width>581</width>
<height>631</height>
</rect>
</property>
</widget>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>