Skip to content

Commit

Permalink
fix: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Udayraj123 committed Jan 3, 2023
1 parent 36d3dfd commit df4462b
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 209 deletions.
2 changes: 0 additions & 2 deletions samples/community/Sandeep-1507/template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"Globals": {
"window_width": 1189,
"window_height": 1682,
"display_width": 1189,
"display_height": 1682
},
Expand Down
2 changes: 1 addition & 1 deletion samples/sample5/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"threshold_params": {
"MIN_JUMP": 200
"MIN_JUMP": 20
}
}
2 changes: 0 additions & 2 deletions samples/sample5/template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"Globals": {
"window_width": 1189,
"window_height": 1682,
"display_width": 1189,
"display_height": 1682
},
Expand Down
2 changes: 0 additions & 2 deletions samples/sample6/template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"Globals": {
"window_width": 2480,
"window_height": 3508,
"display_width": 2480,
"display_height": 3508
},
Expand Down
2 changes: 0 additions & 2 deletions samples/sample6/template_fb_align.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"Globals": {
"window_width": 2480,
"window_height": 3508,
"display_width": 2480 ,
"display_height": 3508
},
Expand Down
2 changes: 0 additions & 2 deletions samples/sample6/template_no_fb_align.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"Globals": {
"window_width": 2480,
"window_height": 3508,
"display_width": 2480,
"display_height": 3508
},
Expand Down
7 changes: 2 additions & 5 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
EVALUATION_FILENAME = "evaluation.json"
CONFIG_FILENAME = "config.json"

SCHEMA_NAMES = {
SCHEMA_NAMES = DotMap({
"template": "template",
"evaluation": "evaluation",
"config": "config",
}
})

#
ERROR_CODES = DotMap(
Expand Down Expand Up @@ -57,9 +57,6 @@
GLOBAL_PAGE_THRESHOLD_WHITE = 200
GLOBAL_PAGE_THRESHOLD_BLACK = 100

# Filepaths - object is better


class Paths:
def __init__(self, output_dir):
self.output_dir = output_dir
Expand Down
13 changes: 4 additions & 9 deletions src/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@
from src.template import Template

# TODO: further break utils down and separate the imports
from src.utils.imgutils import (
ImageUtils,
MainOperations,
draw_template_layout,
setup_dirs,
)
from src.utils.image import ImageUtils, MainOperations, draw_template_layout, setup_dirs
from src.utils.parsing import (
evaluate_concatenated_response,
get_concatenated_response,
Expand Down Expand Up @@ -265,10 +260,10 @@ def process_files(omr_files, template, tuning_config, evaluation_config, args, o
)

# TODO: Get rid of saveImgList
for i in range(ImageUtils.save_image_level):
ImageUtils.reset_save_img(i + 1)
for i in range(InstanceImageUtils.save_image_level):
InstanceImageUtils.reset_save_img(i + 1)

ImageUtils.append_save_img(1, in_omr)
InstanceImageUtils.append_save_img(1, in_omr)

# resize to conform to template
in_omr = ImageUtils.resize_util(
Expand Down
8 changes: 5 additions & 3 deletions src/defaults/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# https://docs.python.org/3/tutorial/modules.html#:~:text=The%20__init__.py,on%20the%20module%20search%20path.
from .config import * # NOQA
from .evaluation import * # NOQA
from .template import * # NOQA
# Use all imports relative to root directory
# (https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html)
from src.defaults.config import * # NOQA
from src.defaults.evaluation import * # NOQA
from src.defaults.template import * # NOQA
2 changes: 0 additions & 2 deletions src/defaults/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"display_width": 640,
"processing_height": 820,
"processing_width": 666,
"window_width": 1280,
"window_height": 720,
},
"threshold_params": {
"GAMMA_LOW": 0.7,
Expand Down
22 changes: 11 additions & 11 deletions src/processors/CropOnMarkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import numpy as np

from src.logger import logger
from src.utils.imgutils import (
from src.processors.interfaces.ImagePreprocessor import ImagePreprocessor
from src.utils.image import (
ImageUtils,
MainOperations,
four_point_transform,
normalize_util,
)

from .interfaces.ImagePreprocessor import ImagePreprocessor


class CropOnMarkers(ImagePreprocessor):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -45,7 +44,7 @@ def __init__(self, *args, **kwargs):
# TODO: processing_width should come through proper channel
marker = ImageUtils.resize_util(
marker,
self.tuning_config.dimensions.processing_width
config.dimensions.processing_width
/ int(marker_ops["sheetToMarkerWidthRatio"]),
)
marker = cv2.GaussianBlur(marker, (5, 5), 0)
Expand Down Expand Up @@ -101,7 +100,7 @@ def getBestMatch(self, image_eroded_sub):
logger.warning(
"\tTemplate matching too low! Consider rechecking preProcessors applied before this."
)
if self.tuning_config.outputs.show_image_level >= 1:
if config.outputs.show_image_level >= 1:
MainOperations.show("res", res, 1, 0)

if best_scale is None:
Expand All @@ -111,6 +110,7 @@ def getBestMatch(self, image_eroded_sub):
return best_scale, all_max_t

def apply_filter(self, image, args):
config = self.tuning_config
image_eroded_sub = normalize_util(
image
if self.apply_erode_subtract
Expand All @@ -133,7 +133,7 @@ def apply_filter(self, image, args):
best_scale, all_max_t = self.getBestMatch(image_eroded_sub)
if best_scale is None:
# TODO: Plot and see performance of marker_rescale_range
if self.tuning_config.outputs.show_image_level >= 1:
if config.outputs.show_image_level >= 1:
MainOperations.show("Quads", image_eroded_sub)
return None

Expand Down Expand Up @@ -167,7 +167,7 @@ def apply_filter(self, image, args):
"\t all_max_t",
all_max_t,
)
if self.tuning_config.outputs.show_image_level >= 1:
if config.outputs.show_image_level >= 1:
MainOperations.show(
"no_pts_" + args["current_file"].name, image_eroded_sub, 0
)
Expand Down Expand Up @@ -202,15 +202,15 @@ def apply_filter(self, image, args):
# appendSaveImg(1,image_eroded_sub)
# appendSaveImg(1,image_norm)

ImageUtils.append_save_img(2, image_eroded_sub)
InstanceImageUtils.append_save_img(2, image_eroded_sub)
# Debugging image -
# res = cv2.matchTemplate(image_eroded_sub,optimal_marker,cv2.TM_CCOEFF_NORMED)
# res[ : , midw:midw+2] = 255
# res[ midh:midh+2, : ] = 255
# show("Markers Matching",res)
if (
self.tuning_config.outputs.show_image_level >= 2
and self.tuning_config.outputs.show_image_level < 4
config.outputs.show_image_level >= 2
and config.outputs.show_image_level < 4
):
image_eroded_sub = ImageUtils.resize_util_h(
image_eroded_sub, image.shape[0]
Expand All @@ -220,7 +220,7 @@ def apply_filter(self, image, args):
MainOperations.show(
"Warped: " + args["current_file"].name,
ImageUtils.resize_util(
h_stack, int(self.tuning_config.dimensions.display_width * 1.6)
h_stack, int(config.dimensions.display_width * 1.6)
),
0,
0,
Expand Down
7 changes: 3 additions & 4 deletions src/processors/CropPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
import numpy as np

from src.logger import logger
from src.utils.imgutils import ImageUtils, four_point_transform

from .interfaces.ImagePreprocessor import ImagePreprocessor
from src.processors.interfaces.ImagePreprocessor import ImagePreprocessor
from src.utils.image import four_point_transform, grab_contours

MIN_PAGE_AREA = 80000

Expand Down Expand Up @@ -86,7 +85,7 @@ def find_page(self, image):

# findContours returns outer boundaries in CW and inner boundaries in ACW
# order.
cnts = ImageUtils.grab_contours(
cnts = grab_contours(
cv2.findContours(edge, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
)
# hullify to resolve disordered curves due to noise
Expand Down
5 changes: 2 additions & 3 deletions src/processors/FeatureBasedAlignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import cv2
import numpy as np

from src.utils.imgutils import MainOperations

from .interfaces.ImagePreprocessor import ImagePreprocessor
from src.processors.interfaces.ImagePreprocessor import ImagePreprocessor
from src.utils.image import MainOperations


class FeatureBasedAlignment(ImagePreprocessor):
Expand Down
2 changes: 1 addition & 1 deletion src/processors/builtins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cv2
import numpy as np

from .interfaces.ImagePreprocessor import ImagePreprocessor
from src.processors.interfaces.ImagePreprocessor import ImagePreprocessor


class Levels(ImagePreprocessor):
Expand Down
4 changes: 1 addition & 3 deletions src/schemas/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
"display_height": { "type": "integer" },
"display_width": { "type": "integer" },
"processing_height": { "type": "integer" },
"processing_width": { "type": "integer" },
"window_width": { "type": "integer" },
"window_height": { "type": "integer" }
"processing_width": { "type": "integer" }
},
"threshold_params": {
"GAMMA_LOW": { "type": "number", "minimum": 0, "maximum": 1 },
Expand Down
Loading

0 comments on commit df4462b

Please sign in to comment.