-
Notifications
You must be signed in to change notification settings - Fork 4
/
lines2.R
55 lines (44 loc) · 1.01 KB
/
lines2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
showPix =
function(pix, file = tempfile())
{
pixWrite(pix, file, IFF_PNG)
Open(file)
}
library(Rtesseract)
f = "inst/images/SMITHBURN_1952_p3.png"
f = "../images/SMITHBURN_1952_p3.png"
p1 = pixRead(f)
p1 = pixConvertTo8(p1)
bin = pixThresholdToBinary(p1, 150)
angle = pixFindSkew(bin)
p2 = pixRotateAMGray(p1, angle[1]*pi/180, 255)
#debug(Rtesseract:::getLines)
# Horizontal lines
h = findLines(p2, 51, 3, TRUE, erode = integer())
m = pixGetPixels(h)
r = rowSums(m)
w = r > 1000
table(w)
diff(which(w))
tess = tesseract(f)
plot(tess)
abline(h = nrow(m) - which(w), col = "red")
if(FALSE) {
z = apply(m[w,], 1, rle)
points(1:ncol(m), rep(which(w)[1], ncol(m)), col = c("white", "red")[m[, which(w)[1]] + 1])
}
# Vertical lines
v = findLines(p2, 1, 101, TRUE) # vertical lines
m = pixGetPixels(v)
r = colSums(m)
w = r > 1000
table(w)
diff(which(w))
#tess = tesseract(f)
#plot(tess)
abline(v = which(w), col = "green")
if(FALSE) {
pixWrite(h, "h.png", IFF_PNG)
a = png::readPNG("h.png")
table(a == m)
}