05-14-2024, 01:31 PM | #2056 |
Connoisseur
Posts: 50
Karma: 5648
Join Date: Jan 2021
Device: Likebook Mars
|
What is the best way to run k2pdfopt on an Android phone? I'm assuming via Linux? Has anyone successfully been able to get it to work and would have step-by-step instructions?
|
05-16-2024, 05:48 AM | #2057 |
Junior Member
Posts: 4
Karma: 10
Join Date: May 2021
Device: None
|
Good question above. Hoping to get some help here.
|
05-16-2024, 11:42 AM | #2058 |
Fuzzball, the purple cat
Posts: 1,276
Karma: 11087488
Join Date: Jun 2011
Location: California
Device: iPad
|
I don't have a test platform for compiling or running on an Android phone. I might be able to cross-compile, but I'd still need to test it. Is there a virtual Android phone simulator that will run on either a PC or a Mac Mini?
|
07-26-2024, 05:22 AM | #2059 | |
Junior Member
Posts: 9
Karma: 55638
Join Date: Jul 2024
Device: Sony PRS-T3
|
Quote:
You should install Termux and install packages k2pdfopt and ghostscript. Termux may not be available on google play and should be downloaded and installed manually. |
|
07-26-2024, 06:01 AM | #2060 | |
the rook, bossing Never.
Posts: 12,096
Karma: 89198465
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper11
|
Quote:
All a free download from Google. It was very like doing a Java app, except Google is a pain and keeps changing how you do I/O to SD card or storage. Really Windows for Workgroups 3.11 was better (apart from lack of Explorer desktop, as long as Win32s, 32 bit TCP/IP and 32 bit Disk etc all added), stupid changes since Android 3 and poor UI. Material Design is idiotic. But then I think Win10/Win11/Chrome/Mozilla UIs are all rubbish compared to mac OS9, Win9x, NT4.0/2K/XP UIs. |
|
08-05-2024, 04:41 PM | #2061 |
Junior Member
Posts: 1
Karma: 10
Join Date: Aug 2024
Device: Kindle Paperwhite
|
Help?
Is this where I can ask for help with getting the formatting down? A lot of this is way over my head. And can I post screenshots here to show what I mean?
|
08-05-2024, 05:03 PM | #2062 | |
Grand Sorcerer
Posts: 5,391
Karma: 99236514
Join Date: Apr 2011
Device: pb360
|
Quote:
You can post screenshots here, but if they are larger than 600x600 please attach them rather than embed them. (Use the "Manage Attachments" tool.) Also, please don't post deep links to images because that frequently causes problems. |
|
Yesterday, 02:05 AM | #2063 |
Member
Posts: 11
Karma: 10
Join Date: Apr 2022
Device: none
|
I wrote myself a dirty piece of code to rotate every CJK character by 90 degrees, which is designed to ignore Latin script if a word is wide enough. Not an effective implementation but with many magic numbers, though.
Code:
#! /usr/bin/env python3 # -*- coding: utf-8 -*- import sys import cv2 import numpy def rotate_image(image, angle): (h, w) = image.shape[: 2] center = (w // 2, h // 2) M = cv2.getRotationMatrix2D(center, angle, 1.0) corrected = cv2.warpAffine(image, M, (w, h), flags = cv2.INTER_CUBIC, borderMode = cv2.BORDER_REPLICATE) return corrected def determine_score(arr): histogram = numpy.sum(arr, axis = 2, dtype = float) score = numpy.sum((histogram[..., 1 :] - histogram[..., : -1]) ** 2, axis = 1, dtype = float) return score def correct_skew(monoImg, delta = 0.1, limit = 5): angles = numpy.arange(-limit, limit + delta, delta) img_stack = numpy.stack([rotate_image(monoImg, angle) for angle in angles], axis = 0) scores = determine_score(img_stack) best_angle = angles[numpy.argmax(scores)] return best_angle orgImage = cv2.imread(sys.argv[1]) myImage = numpy.ascontiguousarray(numpy.rot90(orgImage)) (my_h, my_w, _) = myImage.shape grayImg = cv2.cvtColor(myImage, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(grayImg, (0,0), sigmaX=33, sigmaY=33) divide = cv2.divide(grayImg, blur, scale=255) _, myImage = cv2.threshold(divide,127,255,cv2.THRESH_BINARY) myImage = divide at_bs = 5 monoImg = cv2.ximgproc.niBlackThreshold(grayImg, 255, cv2.THRESH_BINARY, at_bs, -0.3, binarizationMethod=cv2.ximgproc.BINARIZATION_NICK) monoImg = cv2.adaptiveThreshold(monoImg, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2) monoImg = cv2.bitwise_not(monoImg) angle = correct_skew(monoImg) print(angle) if not -0.1 < angle < 0.1: monoImg = rotate_image(monoImg, angle) myImage = rotate_image(myImage, angle) erosion_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 1)) erosion = cv2.erode(monoImg, erosion_kernel, iterations = 1) dilation_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (18, 5)) dilation = cv2.dilate(erosion, dilation_kernel, iterations = 1) contours, hierarchy = cv2.findContours(dilation, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) dilation_kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 1)) dilation = cv2.dilate(monoImg, dilation_kernel, iterations = 1) newImage = numpy.full(myImage.shape, 255, dtype=numpy.uint8) for cnt in contours: x, y, w, h = cv2.boundingRect(cnt) ROI = dilation[y:y+h, x:x+w] # 1 1 0 1 1 # original 1 right pad # 1 1 1 0 1 # original 2 right pad ROI1 = numpy.c_[ROI, numpy.zeros(len(ROI),dtype=numpy.uint8)] # 1 1 0 1 1 # right shift 1 # 1 1 1 0 1 # right shift 2 ROI2 = numpy.c_[numpy.zeros(len(ROI),dtype=numpy.uint8), ROI] # 0 1 0 0 1 0 # AND 1 # 0 1 1 0 0 0 # AND 2 gap = cv2.bitwise_and(ROI1, ROI2) # gap between pixel #0 1 1 0 1 0 # reduced reducedArray = cv2.reduce(gap, 0, cv2.REDUCE_MAX, dtype=cv2.CV_8U) rcnt, length, i, left, started = [], len(reducedArray[0]), 0, 0, False while i < length: if reducedArray[0][i] >0: if not started: left = i-1 started = True else: if started: rcnt.append((x+left, y, i-left, h)) # absolute coordination started = False i=i+1 for rc in rcnt: _x, _y, _w, _h = rc if _h//_w>=2 or _w//_h>=3: continue xhigh = _x + _w//2 + _h//2 yhigh = _y + _h//2 + _w//2 xlow = xhigh - _h ylow = yhigh - _w if xlow <0: xlow = 0 xhigh = _h if xhigh > my_w: xhigh = my_w xlow = xhigh - _h if ylow <0: ylow = 0 yhigh = _w if yhigh > my_h: yhigh = my_h ylow = yhigh - _w if xlow >=0 and xhigh<=my_w and ylow >=0 and yhigh<=my_h: glyph = numpy.ascontiguousarray(numpy.rot90(myImage[_y:_y+_h, _x:_x+_w], -1)) cv2.rectangle(myImage, (_x, _y), (_x+_w, _y+_h), (255, 255, 255), -1) newImage[ylow:yhigh, xlow:xhigh] = cv2.min(newImage[ylow:yhigh, xlow:xhigh], glyph) cv2.imwrite(sys.argv[1]+".rotate.png", cv2.min(newImage,myImage)) |
Yesterday, 12:55 PM | #2064 |
Fuzzball, the purple cat
Posts: 1,276
Karma: 11087488
Join Date: Jun 2011
Location: California
Device: iPad
|
A little context here would be useful. What is your script intended to be used on? A PDF file? Does it work on any PDF?
|
Yesterday, 12:57 PM | #2065 | |
Fuzzball, the purple cat
Posts: 1,276
Karma: 11087488
Join Date: Jun 2011
Location: California
Device: iPad
|
Quote:
|
|
Today, 12:06 AM | #2066 | ||
Member
Posts: 11
Karma: 10
Join Date: Apr 2022
Device: none
|
Quote:
Quote:
It binarizes the image, rotate it by 90 degrees, align it horizontally, and filter out noise pixels. Reverse the color. Every white pixel will color adjacent pixels to make sure every radical of a single, square character is connected to one another. Chop the image to pieces, rotate back 90 degrees every rectangular piece (in the original image) that is square enough. |
||
Tags |
ebook apps, k5 tools, kindle tools, kindle touch, tools |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Viewing PDFs with another font | Font | PocketBook | 4 | 11-12-2010 08:27 AM |
Viewing Textbook PDFs... | NJReader | enTourage Archive | 4 | 08-17-2010 05:17 PM |
PRS-600 Restart bug while viewing PDFs? | conundrum | Sony Reader | 2 | 03-04-2010 08:46 PM |
More on viewing pdfs | dso371 | Bookeen | 8 | 03-11-2008 07:15 PM |
Viewing Untagged PDFs on Palm T|X | Eroica | Reading and Management | 3 | 12-10-2007 01:44 PM |