semi-automatic bbox finding
Semi-automatic cropping is implemented with a initial manual cropping that exclude the obvious decorating line or the spine part in scanned books and then an automatic cropping ie. background/foreground pixel detection restricted within the manual cropping area. This PR is a candidate for the solution of issue #141.
This commit is contained in:
1 parent
43240a7d98
commit
9cb9999865
2 files changed
+12
-9
No files matched your search
@@ -75,21 +75,24 @@ function KoptInterface:getContextHash(doc, pageno, bbox)
|
||||
end
|
||||
|
||||
function KoptInterface:getAutoBBox(doc, pageno)
|
||||
local bbox = {
|
||||
x0 = 0, y0 = 0,
|
||||
x1 = 0, y1 = 0,
|
||||
}
|
||||
-- use manual bbox
|
||||
local bbox = Document.getPageBBox(doc, pageno)
|
||||
local context_hash = self:getContextHash(doc, pageno, bbox)
|
||||
local hash = "autobbox|"..context_hash
|
||||
local cached = Cache:check(hash)
|
||||
if not cached then
|
||||
local page = doc._document:openPage(pageno)
|
||||
local kc = self:createContext(doc, pageno, bbox)
|
||||
bbox.x0, bbox.y0, bbox.x1, bbox.y1 = page:getAutoBBox(kc)
|
||||
DEBUG("Auto detected bbox", bbox)
|
||||
local auto_bbox = {}
|
||||
auto_bbox.x0, auto_bbox.y0, auto_bbox.x1, auto_bbox.y1 = page:getAutoBBox(kc)
|
||||
auto_bbox.x0 = auto_bbox.x0 + bbox.x0
|
||||
auto_bbox.y0 = auto_bbox.y0 + bbox.y0
|
||||
auto_bbox.x1 = auto_bbox.x1 + bbox.x0
|
||||
auto_bbox.y1 = auto_bbox.y1 + bbox.y0
|
||||
DEBUG("Auto detected bbox", auto_bbox)
|
||||
page:close()
|
||||
Cache:insert(hash, CacheItem:new{ autobbox = bbox })
|
||||
return bbox
|
||||
Cache:insert(hash, CacheItem:new{ autobbox = auto_bbox })
|
||||
return auto_bbox
|
||||
else
|
||||
return cached.autobbox
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user