Адаптивная обработка порога для больших черных букв

  public void ReadXmlFile()
    {
        string path = HttpContext.Current.Server.MapPath("~/App_Data"); // Finds the location of App_Data on server.
        XmlTextReader reader = new XmlTextReader(System.IO.Path.Combine(path, "XMLFile7.xml")); //Combines the location of App_Data and the file name
        while (reader.Read())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    break;
                case XmlNodeType.Text:
                    columnNames.Add(reader.Value);
                    break;
                case XmlNodeType.EndElement:
                    break;
            }
        }
    }

Вы можете избежать первого оператора и просто указать имя пути в конструкторе XmlTextReader.

0
задан Ahmed Hegazy 21 January 2019 в 15:10
поделиться

1 ответ

Следующий код:

import numpy as np
import cv2
import matplotlib.pyplot as plt

image = cv2.imread("FYROJ.png")
gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 3)

im_contours, contours, hier = cv2.findContours(thresh, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_NONE)
hier = hier[0]
kept_contours = [contour for idx, contour in enumerate(contours) if hier[idx][2] >= 0]

drawing = np.zeros_like(gray)
cv2.drawContours(drawing, kept_contours, -1, color=255)

ret, markers = cv2.connectedComponents(drawing)

watershed_res = cv2.watershed(image, np.int32(markers))

plt.imshow(watershed_res)
plt.show()

сгенерирует это изображение: enter image description here

Возможно, попробуйте начать отсюда и выберите регионы, где есть много черных пикселей в исходном изображении ...

0
ответ дан T.Lucas 21 January 2019 в 15:10
поделиться
Другие вопросы по тегам:

Похожие вопросы: