This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import matplotlib.pyplot as plt | |
im = cv2.imread(r’img\barcodes.jpg’, cv2.IMREAD_GRAYSCALE) | |
plt.imshow(im, cmap=’Greys_r’) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#riscalatura dell'immagine | |
scale = 800.0 / im.shape[1] | |
im = cv2.resize(im, (int(im.shape[1] * scale), int(im.shape[0] * scale))) | |
#blackhat | |
kernel = np.ones((1, 3), np.uint8) | |
im = cv2.morphologyEx(im, cv2.MORPH_BLACKHAT, kernel, anchor=(1, 0)) | |
#sogliatura | |
thresh, im = cv2.threshold(im, 10, 255, cv2.THRESH_BINARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kernel = np.ones((1, 5), np.uint8) | |
im = cv2.morphologyEx(im, cv2.MORPH_DILATE, kernel, anchor=(2, 0), iterations=2) #dilatazione | |
im = cv2.morphologyEx(im, cv2.MORPH_CLOSE, kernel, anchor=(2, 0), iterations=2) #chiusura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kernel = np.ones((21, 35), np.uint8) | |
im = cv2.morphologyEx(im, cv2.MORPH_OPEN, kernel, iterations=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#rilettura dell'immagine, stavolta a colori | |
im_out = cv2.imread(r'img\barcodes.jpg') | |
#estrazione dei componenti connessi | |
contours, hierarchy = cv2.findContours(im, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) | |
unscale = 1.0 / scale | |
if contours != None: | |
for contour in contours: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import matplotlib.pyplot as plt | |
import numpy as np | |
im = cv2.imread(r'img\barcodes.jpg', cv2.IMREAD_GRAYSCALE) | |
im_out = cv2.imread(r'img\barcodes.jpg') | |
#riscalatura dell'immagine | |
scale = 800.0 / im.shape[1] | |
im = cv2.resize(im, (int(im.shape[1] * scale), int(im.shape[0] * scale))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import matplotlib.pyplot as plt | |
im = cv2.imread(r'img\text.jpg', cv2.IMREAD_GRAYSCALE) | |
plt.imshow(im, cmap='Greys_r') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import matplotlib.pyplot as plt | |
#caricamento dell'immagine da disco | |
im = cv2.imread(r'img\text.jpg', cv2.IMREAD_GRAYSCALE) | |
h, w = im.shape | |
#ridimensionamento dell'immagine | |
im = cv2.resize(im, (w/3,h/3)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def houghSpace(im): | |
maxTheta = 180 | |
#la larghezza dello spazio corrisponde alla massima angolatura presa in considerazione | |
houghMatrixCols = maxTheta | |
#dimensioni dell'immagine originale | |
h, w = im.shape | |
#non puo' esistere nell'immagine una distanza superiore alla diagonale | |
rhoMax = math.sqrt(w * w + h * h) | |
#l'altezza dello spazio è il doppio della rho massima, per considerare anche |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def houghSpace(im): | |
maxTheta = 180 | |
#la larghezza dello spazio corrisponde alla massima angolatura presa in considerazione | |
houghMatrixCols = maxTheta |
OlderNewer