def DrawLinesWithNoise(cls, img): img = binarize_cv_image(img) noise_pictures = 1 histogram_x = np.zeros(img.shape[0]) histogram_y = np.zeros(img.shape[1]) sum_x = np.zeros(img.shape[0]) sum_y = np.zeros(img.shape[1]) noise_img_return = ImageNoiserCV.Noise(img) for z in range(noise_pictures): noise_img = noise_img_return # ImageNoiser.Noise(img) noise_img = binarize_cv_image(noise_img) x_points, y_points = count_max_lines(noise_img) sum_x += x_points sum_y += y_points put_image_max_lines(x_points, y_points, histogram_x, histogram_y) histogram_x = np.array(histogram_x) / float(noise_pictures) histogram_y = np.array(histogram_y) / float(noise_pictures) average_x = sum_x / float(noise_pictures) average_y = sum_y / float(noise_pictures) print "Histogramm x: " + str(histogram_x) print "-----" print "Histogramm y: " + str(histogram_y) print "-----" print "Average x: " + str(average_x) print "-----" print "Average y: " + str(average_y) print "-----" x_points, y_points = count_max_lines(img) x_points, y_points = np.array(x_points), np.array(y_points) variance_x = (x_points - average_x) ** 2 variance_y = (y_points - average_y) ** 2 report = "" report += "Horizontal lines: \n" report += cls.form_report(x_points, variance_x) report += "Vertical lines: \n" report += cls.form_report(y_points, variance_y) print "Variance x: " + str(variance_x) print "-----" print "Variance y: " + str(variance_y) print "-----" img = noise_img_return for i in xrange(len(histogram_x)): x = histogram_x[i] if x > 0: draw_line_x(img, i, (255, 255, 255 - int(255 * x))) for i in xrange(len(histogram_y)): y = histogram_y[i] if y > 0: draw_line_y(img, i, (255, 255 - int(255 * y), 255)) return img, report, noise_img_return
def getBinarizedLines(cls, img, median_num=17): cls.median_num = median_num img = binarize_cv_image(img) x_points, y_points = count_max_lines(img) horizontal_lines = HistogrammPiksDetector.getPiksLinesBinarized(x_points) vertical_lines = HistogrammPiksDetector.getPiksLinesBinarized(y_points) return horizontal_lines, vertical_lines
def getLinesOnPicture(cls, img, median_num=17, font=""): cls.median_num = median_num img = binarize_cv_image(img) #x_points, y_points = count_max_lines(img) x_points, y_points = count_continius_lines_and_sides(img,font) horizontal_lines, horizontal_median = HistogrammPiksDetector.getPiksLines(x_points) vertical_lines, vertical_median = HistogrammPiksDetector.getPiksLines(y_points) # print u"Горизонтальные линии:" # for line in horizontal_lines: # print unicode(line) horiz_histogram = cls.horizontalHistogram(x_points, horizontal_lines, horizontal_median) vertical_histogram = cls.verticalHistogram(y_points, vertical_lines, vertical_median) return horizontal_lines, vertical_lines, horiz_histogram, vertical_histogram
def getLinesOnPicture(cls, img): img = binarize_cv_image(img) x_points, y_points = count_max_lines(img) return x_points, y_points
def DrawLines(cls, img): img = binarize_cv_image(img) x_points, y_points = count_max_lines(img) draw_max_lines(img, x_points, y_points) return img
def getHistogramLines(cls, img, median_num=17): cls.median_num = median_num img = binarize_cv_image(img) x_points, y_points = count_max_lines(img) return x_points, y_points