Commit d1e7ea17 authored by njean42's avatar njean42
Browse files

Debugging in separate lib.

parent 811eecef
#!/usr/bin/env python
import os, json, sys, tempfile, requests
......@@ -7,6 +6,7 @@ import numpy as np
from urllib.parse import urlparse
from lib.panel import Panel
from lib.debug import Debug
......@@ -20,7 +20,9 @@ class Kumiko:
def __init__(self,options={}):
for o in ['debug_dir','progress','rtl']:
self.dbg = Debug(options['debug_dir'] if 'debug_dir' in options else False)
for o in ['progress','rtl']:
self.options[o] = o in options and options[o]
if self.options['rtl']:
......@@ -102,13 +104,11 @@ class Kumiko:
else:
raise Exception('Fatal error, unknown background color: '+str(bgcol))
if self.options['debug_dir']:
cv.imwrite(os.path.join(self.options['debug_dir'],os.path.basename(filename)+'-020-thresh[{}].jpg'.format(bgcol)),thresh)
self.dbg.write_image(thresh,filename+'-020-thresh[bg:{}].jpg'.format(bgcol))
return contours
subpanel_colours = [(0,255,0),(255,0,0),(200,200,0),(200,0,200),(0,200,200),(150,150,150)]
def split_panels(self,panels,img,contourSize):
new_panels = []
old_panels = []
......@@ -118,9 +118,7 @@ class Kumiko:
old_panels.append(p)
new_panels += new
if self.options['debug_dir']:
for i in range(len(new)):
cv.drawContours(img, [new[i].polygon], 0, self.subpanel_colours[i % len(self.subpanel_colours)], contourSize)
self.dbg.write_contours(img, list(map(lambda n: n.polygon, new)), contourSize)
for p in old_panels:
panels.remove(p)
......@@ -255,8 +253,7 @@ class Kumiko:
if panel.w < infos['size'][0] * self.options['min_panel_size_ratio'] or panel.h < infos['size'][1] * self.options['min_panel_size_ratio']:
continue
if self.options['debug_dir']:
cv.drawContours(self.img, [approx], 0, (0,0,255), contourSize)
self.dbg.write_contours(self.img, [approx], contourSize, colour=(0,0,255))
panels.append(Panel(polygon=approx))
......@@ -288,8 +285,7 @@ class Kumiko:
infos['panels'] = panels
# write panel numbers on debug image
if self.options['debug_dir']:
cv.imwrite(os.path.join(self.options['debug_dir'],os.path.basename(filename)+'-010-gray.jpg'),self.gray)
cv.imwrite(os.path.join(self.options['debug_dir'],os.path.basename(filename)+'-040-contours.jpg'),self.img)
self.dbg.write_image(self.gray, filename+'-010-gray.jpg')
self.dbg.write_image(self.img, filename+'-040-contours.jpg')
return infos
import os
import cv2 as cv
class Debug:
def __init__(self, debug_dir):
self.debug_dir = debug_dir
def write_image(self, img, filename):
if not self.debug_dir:
return
cv.imwrite(os.path.join(self.debug_dir, os.path.basename(filename)),img)
subpanel_colours = [(0,255,0),(255,0,0),(200,200,0),(200,0,200),(0,200,200),(150,150,150)]
def write_contours(self, img, contours, contourSize, colour='auto'):
if not self.debug_dir:
return
for i in range(len(contours)):
if colour == 'auto':
colour = Debug.subpanel_colours[i % len(Debug.subpanel_colours)]
cv.drawContours(img, [contours[i]], 0, colour, contourSize)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment