Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
veca1982 committed Jan 1, 2019
0 parents commit 6d8f890
Show file tree
Hide file tree
Showing 110 changed files with 7,857 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
".idea"
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/UtilityMeterNumberRecognition.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

778 changes: 778 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"# UtilityMeterNumberRecognition"
1 change: 1 addition & 0 deletions dao/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'Krtalici'
37 changes: 37 additions & 0 deletions dao/trainingDao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
__author__ = 'Krtalici'
import pickle as pkl
import numpy as np

def writeTrainingData( imagesInVectorForm ) :
np.savetxt('test.txt', imagesInVectorForm)

def writeTargets( ) :
outcomes = open('trainingData/target.pkl', 'w')

#target = np.array([0,0,0,1,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0])
target = np.array([0,1,0,0,1])

pkl.dump(target, outcomes)
outcomes.close()

def readTrainingData() :
imagesInVectorForm = np.loadtxt('test.txt')
imagesInVectorForm = np.delete(imagesInVectorForm, 0, 0)
print "Size [%d,%d]"%imagesInVectorForm.shape

#matrica trening slika, svaka slika pretvorena pri zapisivanju u datoteku u vektor
return imagesInVectorForm

def readTrainingTarget() :
pkl_file = open('trainingData/target.pkl', 'r')
target = pkl.load(pkl_file)
pkl_file.close()
#matrica trening slika, svaka slika pretvorena pri zapisivanju u datoteku u vektor
return target

def pickleLoader(pklFile):
try:
while True:
yield pkl.load(pklFile)
except EOFError:
pass
5,000 changes: 5,000 additions & 0 deletions data/digits.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions display/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'Krtalici'
Binary file added display/__init__.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions display/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
__author__ = 'Krtalici'
import cv2

def display_images(images):
for image in images:
cv2.imshow("Image", image)
cv2.waitKey(0)


Binary file added display/display.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions image_preprocesing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__author__ = 'Krtalici'
Binary file added image_preprocesing/__init__.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions image_preprocesing/contrast_streching.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import numpy as np
import cv2
from skimage import data, img_as_float
from skimage import exposure
from image_preprocesing import image_enhancment as ie


if __name__ == "__main__":
image = cv2.imread('../watermeter21.png', cv2.IMREAD_GRAYSCALE)
cv2.imshow('orig', image)
p2, p98 = np.percentile(image, (2, 97))
img_rescale = exposure.rescale_intensity(image, in_range=(p2, p98))
image_to_return = ie.sharp_img_with_filter(img_rescale)
final = cv2.bilateralFilter(image_to_return, 9, 75, 75)
p2, p98 = np.percentile(image, (2, 97))
img_rescale = exposure.rescale_intensity(final, in_range=(p2, p98))
cv2.imshow('Streched', img_rescale)
cv2.imwrite('../watermeter23.png', img_rescale)
cv2.waitKey(0)
14 changes: 14 additions & 0 deletions image_preprocesing/filter_countours.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__author__ = 'Krtalici'
import cv2

def filterByHierarchy(cnts,hierarchy):
cntsWithMAxHierarchy = []
for i,cnt in enumerate(cnts):
if hierarchy[0,i,3] == -1 and cv2.contourArea(cnt[0]) > 80:
cntsWithMAxHierarchy.append(cnt)

return cntsWithMAxHierarchy




Binary file added image_preprocesing/filter_countours.pyc
Binary file not shown.
83 changes: 83 additions & 0 deletions image_preprocesing/histogram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
__author__ = 'Krtalici'
import cv2
import numpy as np
from image_preprocesing import image_tresholding as tresh
from image_preprocesing import image_enhancment as ie

def get_grey_hist_eq( image ):
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
eq = cv2.equalizeHist(image)
return eq

def sharp_img(path_to_image):

#Load source / input image as grayscale, also works on color images...
imgIn = cv2.imread(path_to_image, cv2.IMREAD_GRAYSCALE)
cv2.imshow("Original", imgIn)
blur = cv2.bilateralFilter(imgIn, 9, 75, 75)
#blur = cv2.medianBlur(imgIn, 7)

#Create the identity filter, but with the 1 shifted to the right!
kernel = np.zeros((9, 9), np.float32)
kernel[4, 4] = 2.0 #Identity, times two!

#Create a box filter:
boxFilter = np.ones((9, 9), np.float32) / 81.0

#Subtract the two:
kernel = kernel - boxFilter


#Note that we are subject to overflow and underflow here...but I believe that
# filter2D clips top and bottom ranges on the output, plus you'd need a
# very bright or very dark pixel surrounded by the opposite type.

custom = cv2.filter2D(blur, -1, kernel)
cv2.imshow("Sharpen", custom)

customSharp = cv2.filter2D(custom, -1, kernel)
cv2.imshow("Custom Sharpen", customSharp)

treshed = tresh.treshImageOtsuWithCorrection(customSharp, 0)
cv2.imshow('Treshed', treshed)
cv2.waitKey(0)

def sharp_that_image(grey_image):

#Load source / input image as grayscale, also works on color images...
cv2.imshow("Original", grey_image)
blur = cv2.bilateralFilter(grey_image, 9, 75, 75)
#blur = cv2.medianBlur(imgIn, 7)

#Create the identity filter, but with the 1 shifted to the right!
kernel = np.zeros((9, 9), np.float32)
kernel[4, 4] = 2.0 #Identity, times two!

#Create a box filter:
boxFilter = np.ones((9, 9), np.float32) / 81.0

#Subtract the two:
kernel = kernel - boxFilter


#Note that we are subject to overflow and underflow here...but I believe that
# filter2D clips top and bottom ranges on the output, plus you'd need a
# very bright or very dark pixel surrounded by the opposite type.

custom = cv2.filter2D(blur, -1, kernel)
cv2.imshow("Sharpen", custom)

#customSharp = cv2.filter2D(custom, -1, kernel)
#cv2.imshow("Custom Sharpen", customSharp)

treshed = tresh.treshImageOtsuWithCorrection(custom, 5)
cv2.imshow('Treshed', treshed)
cv2.waitKey(0)

if __name__ == "__main__":
image = cv2.imread('../watermeter21.png')
eq = get_grey_hist_eq(image)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Histogram Equalization", np.hstack([image, eq]))
cv2.waitKey(0)
sharp_that_image(grey_image=eq)
Loading

0 comments on commit 6d8f890

Please sign in to comment.