-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
".idea" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"# UtilityMeterNumberRecognition" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'Krtalici' |
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 |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'Krtalici' |
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) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'Krtalici' |
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) |
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 | ||
|
||
|
||
|
||
|
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) |