예제 #1
0
def process_omr(omr, template, filename):
    # Preprocess
    for pp in template.preprocessors:  # run preprocessors
        omr = pp.apply_filter(omr, None)
    omr = utils.resize_util(
        omr,  # resize to conform to template
        config.uniform_width,
        config.uniform_height)

    omr_resp_dict = utils.readResponse(template, omr, name='')[0]
    return get_result(omr_resp_dict, template)
예제 #2
0
파일: template.py 프로젝트: VSMourya/omr-ml
    def __init__(self, path):
        with open(path, "r") as f:
            json_obj = json.load(f)
        self.path = path
        self.QBlocks = []
        # throw exception on key not exist
        self.dims = json_obj["Dimensions"]
        self.bubbleDims = json_obj["BubbleDimensions"]
        self.concats = json_obj["Concatenations"]
        self.singles = json_obj["Singles"]

        # Add new qTypes from template
        if "qTypes" in json_obj:
            qtype_data.update(json_obj["qTypes"])

        # process local options
        self.options = json_obj.get("Options", {})

        self.marker = None
        self.marker_path = None
        # process markers
        if "Marker" in self.options:
            markerOps = self.options["Marker"]
            self.marker_path = os.path.join(
                os.path.dirname(path), markerOps.get(
                    "RelativePath", config.MARKER_FILE))
            if(not os.path.exists(self.marker_path)):
                print(
                    "Error: Marker not found at path provided in template:",
                    self.marker_path)
                exit(31)

            marker = cv2.imread(self.marker_path, cv2.IMREAD_GRAYSCALE)
            if("SheetToMarkerWidthRatio" in markerOps):
                marker = utils.resize_util(marker, config.uniform_width /
                                     int(markerOps["SheetToMarkerWidthRatio"]))
            marker = cv2.GaussianBlur(marker, (5, 5), 0)
            marker = cv2.normalize(
                marker,
                None,
                alpha=0,
                beta=255,
                norm_type=cv2.NORM_MINMAX)
            # marker_eroded_sub = marker-cv2.erode(marker,None)
            self.marker = marker - \
                cv2.erode(marker, kernel=np.ones((5, 5)), iterations=5)


        # Add QBlocks
        for name, block in json_obj["QBlocks"].items():
            self.addQBlocks(name, block)