Free OCR package in Python and selecting appropriate widget for the GUI
Mohsen Owzar
mohsen.owzar at gmail.com
Sun Sep 26 12:54:16 EDT 2021
Mohsen Owzar schrieb am Donnerstag, 23. September 2021 um 08:53:15 UTC+2:
> DFS schrieb am Mittwoch, 22. September 2021 um 09:41:42 UTC+2:
> > On 9/22/2021 1:54 AM, Mohsen Owzar wrote:
> > > DFS schrieb am Mittwoch, 22. September 2021 um 05:10:30 UTC+2:
> > >> On 9/21/2021 10:38 PM, Mohsen Owzar wrote:
> > >>> DFS schrieb am Dienstag, 21. September 2021 um 15:45:38 UTC+2:
> > >>>> On 9/21/2021 4:36 AM, Mohsen Owzar wrote:
> > >>>>> Hi Guys
> > >>>>> Long time ago I've written a program in Malab a GUI for solving Sudoku puzzles, which worked not so bad.
> > >>>>> Now I try to write this GUI with Python with PyQt5 or TKinter.
> > >>>>> First question is:
> > >>>>> Is there any free OCR software, packages or code in Python, which I can use to recognize the given digits and their positions in the puzzle square.
> > >>>>> Second:
> > >>>>> Because, I can not attach a picture to this post, I try to describe my picture of my GUI.
> > >>>> Draw your GUI in PyQt designer or other graphics tool, then upload a
> > >>>> screenshot of it to imgur, then post the link to the picture.
> > >>> Thanks, for your answer. Hi
> > >>> But, what is "imgur"?
> > >>> I'm not so familiar with handling of pictures in this group.
> > >>> How can I call "imgur" or how can I get there?
> > >>>
> > >>> Regards
> > >>> Mohsen
> > >> www.imgur.com
> > >>
> > >> It's a website you can upload image files or screenshots to. Then you
> > >> can copy a link to your picture and post the link here.
> > > I have already posted the link, but I can not see it anywhere.
> > > Now, I post it again:
> > > https://imgur.com/a/Vh8P2TE
> > > I hope that you can see my two images.
> > > Regards
> > > Mohsen
> > Got it.
> >
> > I haven't used tkinter. In PyQt5 designer I think you should use one
> > QTextEdit control for each square.
> >
> >
> > Each square with the small black font can be initially populated with
> >
> > 1 2 3
> > 4 5 6
> > 7 8 9
> >
> >
> >
> > https://imgur.com/lTcEiML
> >
> >
> >
> > some starter python code (maybe save as sudoku.py)
> >
> > =====================================================================
> > from PyQt5 import Qt, QtCore, QtGui, QtWidgets, uic
> > from PyQt5.Qt import *
> > from PyQt5.QtCore import *
> > from PyQt5.QtGui import *
> > from PyQt5.QtWidgets import *
> >
> > #objects
> > app = QtWidgets.QApplication([])
> > frm = uic.loadUi("sudoku.ui")
> >
> >
> > #grid = a collection of squares
> > grids = 1
> >
> > #squares = number of squares per grid
> > squares = 9
> >
> > #fill the squares with 1-9
> > def populateSquares():
> > for i in range(grids,grids+1):
> > for j in range(1,squares+1):
> > widget = frm.findChild(QtWidgets.QTextEdit, "txt{}_{}".format(i,j))
> > widget.setText("1 2 3 4 5 6 7 8 9")
> >
> > #read data from squares
> > def readSquares():
> > for i in range(grids,grids+1):
> > for j in range(1,squares+1):
> > print("txt%d_%d contains: %s" %
> > (i,j,frm.findChild(QtWidgets.QTextEdit,
> > "txt{}_{}".format(i,j)).toPlainText()))
> >
> >
> > #connect pushbuttons to code
> > frm.btnPopulate.clicked.connect(populateSquares)
> > frm.btnReadContents.clicked.connect(readSquares)
> >
> > #show main form
> > frm.show()
> >
> > #initiate application
> > app.exec()
> > =====================================================================
> >
> >
> >
> >
> >
> > .ui file (ie save as sudoku.ui)
> > =====================================================================
> >
> > <?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>325</width>
> > <height>288</height>
> > </rect>
> > </property>
> > <property name="windowTitle">
> > <string>Sudoku</string>
> > </property>
> > <widget class="QWidget" name="centralwidget">
> > <widget class="QTextEdit" name="txt1_1">
> > <property name="geometry">
> > <rect>
> > <x>32</x>
> > <y>22</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_2">
> > <property name="geometry">
> > <rect>
> > <x>114</x>
> > <y>22</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_3">
> > <property name="geometry">
> > <rect>
> > <x>196</x>
> > <y>22</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_4">
> > <property name="geometry">
> > <rect>
> > <x>32</x>
> > <y>86</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_5">
> > <property name="geometry">
> > <rect>
> > <x>114</x>
> > <y>86</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_6">
> > <property name="geometry">
> > <rect>
> > <x>196</x>
> > <y>86</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_7">
> > <property name="geometry">
> > <rect>
> > <x>32</x>
> > <y>150</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_8">
> > <property name="geometry">
> > <rect>
> > <x>114</x>
> > <y>150</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QPushButton" name="btnPopulate">
> > <property name="geometry">
> > <rect>
> > <x>32</x>
> > <y>228</y>
> > <width>121</width>
> > <height>35</height>
> > </rect>
> > </property>
> > <property name="text">
> > <string>Populate with numbers</string>
> > </property>
> > </widget>
> > <widget class="QTextEdit" name="txt1_9">
> > <property name="geometry">
> > <rect>
> > <x>196</x>
> > <y>150</y>
> > <width>83</width>
> > <height>65</height>
> > </rect>
> > </property>
> > <property name="font">
> > <font>
> > <family>Courier</family>
> > <pointsize>12</pointsize>
> > <weight>50</weight>
> > <bold>false</bold>
> > </font>
> > </property>
> > <property name="acceptDrops">
> > <bool>false</bool>
> > </property>
> > <property name="styleSheet">
> > <string notr="true">color: rgb(0, 0, 127);
> > background-color: rgb(255, 255, 127);</string>
> > </property>
> > <property name="frameShape">
> > <enum>QFrame::StyledPanel</enum>
> > </property>
> > <property name="frameShadow">
> > <enum>QFrame::Sunken</enum>
> > </property>
> > <property name="horizontalScrollBarPolicy">
> > <enum>Qt::ScrollBarAlwaysOff</enum>
> > </property>
> > <property name="acceptRichText">
> > <bool>true</bool>
> > </property>
> > </widget>
> > <widget class="QPushButton" name="btnReadContents">
> > <property name="geometry">
> > <rect>
> > <x>170</x>
> > <y>228</y>
> > <width>109</width>
> > <height>35</height>
> > </rect>
> > </property>
> > <property name="text">
> > <string>Read contents</string>
> > </property>
> > </widget>
> > </widget>
> > <widget class="QStatusBar" name="statusbar"/>
> > </widget>
> > <resources/>
> > <connections/>
> > </ui>
> >
> > =====================================================================
> Thank you,
>
> I'll try to use this QTextEdit, to see if I'm able to manage my needs.
>
> Regards
> Mohsen
Hi DFS,
I’ve copied your code and ran it.
It is almost that what I wanted except the fact, the 9 digits are not behave as a 3x3 matrix.
When I click on the button “Populate with numbers”, on my screen looks like below in each square:
1 2 3 4
5 6 7 8
9
I want to get the numbers in a matrix form as:
1 2 3
4 5 6
7 8 9
And they should be placed centered in each square.
And when a digit is missing, let say 4, 5 doesn’t have to take its place , so that:
1 2 3
5 6
7 8 9
And when the real number / digit is found, it should be a big one digit in the center of the square.
I don’t know how to bring these two different font sizes and digit placements under one hat.
Do you have any idea?
Regards
Mohsen
More information about the Python-list
mailing list