PDA

View Full Version : OCR e linux


Willy McBride
08-02-2008, 17:44
Visto che la settimana scorsa mi hanno regalato un vecchio scanner inutilizzato ho deciso di provare tesseract 2.01. Ho fatto una scansione a 300 dpi di una fotocopia che avevo in scrivania e l'ho passata al programma senza modifiche per facilitargli il lavoro (es: lavoro sulle curve per ridurre il rumore nelle parti bianche o miglioramento del contrasto) ed ho ottenuto questo:
PRINCIPLES OF NARROW BAND SPECTROMETRY IN THE VISIBLE AND
IR: INSTRUMENTS AND DATA ANALYSIS
A. F. H. GOETZ
Center for the Study of Earth from Space
Cooperative Institute for Research in Environmental Sciences
University 0f Colorado . ’
Boulder, Colorado, USA 80309-0449
1. Introduction ,
The development of sensors and data analysis techniques must go hand-in-hand for the best
information return. However, often the sensor is developed in relative isolation from those who
develop data analysis techniques. In this chapter, at least, common practice will be ignored and
both will be discussed together. The reason for the unnatural separation of the two efforts lies in
the fact that sensors are developed by engineers and data analysis techniques by scientists with
specific applications. Often resources are limited and, in general, since the sensor was started first
it commands the l.ion's share of the resources. In the development of imaging spectrometry in the
US, vastly more resources have been allotted to instrument than to data analysis techniques. As
the instruments prove their capabi1ities,_program managers in funding agencies are alerted and are
more willing to part with funds to analyze the data.
2. Imaging` spectrometers
Figure l shows the different configurations of multispectral imaging systems and imaging
spectrometers. Multispectral imaging systems have developed from the type of optomechanical
scarmer using discrete detectors shown in figure la to multispectral imaging with line arrays
shown in figure lb. Two types of imaging spectrometers have been built and flown. Imaging
spectrometry with line arrays having one detector for each wavelength are known as whisk—broom
systems (figure lc). The Airbome Visible and Infrared Imaging Spectrometer (AVIRIS) discussed
below is of this type. Spacebome imaging spectrometers having high spatial resolution require an
additional multiplex advantage and use area arrays (figure ld) which provide a detector for each
cross-track picture element and a detector element for each wavelength covered by that picture
element.
While it may appear that the area array design is the most desirable, there are a number of trade-
offs to be considered. The trade-offs are in the areas of optical field of view, calibration, and
si gnal-to-noise ratio.
Wide spectral coverage imagers such as AVIRIS and the Airbome Imaging Spectrometer (AIS)
require the use of all—reflecting systems because it is not feasible to create an achromatic lens over 2
l/2 octaves in wavelength. All-reflecting systems are difficult to build to cover a wide field of
view. Aberrations become severe if the field of view is greater than approximately 3°. Therefore,
to cover a wide field of view, such as the 30° field—of—view of AVIRIS or the 90° field—of—view of
Moderate Resolution Imaging Spectrometer (MODIS), being developed for the NASA Eos
platform, require an optomechanical system.
I Calibration of a whisk—broom scanner having one detector for each wavelength is vastly less

Il testo ha (secondo gedit) 485 parole; ci sono 14 parole errate, più 6 caratteri inseriti erroneamente.
Qui sotto una copia, ridotta in dimensioni, dell'immagine di partenza con segnati gli errori: puntino rosso per lettere riconosciute male, puntino verde per caratteri aggiunti.

http://img152.imageshack.us/img152/8981/outnx5.th.jpg (http://img152.imageshack.us/my.php?image=outnx5.jpg)

Come si può vedere, quasi tutti gli errori sono su caratteri i/1/l e sui blocchi composti da r/m/n. Mi pare un buon risultato, però non ho mai avuto a che fare con software ocr commerciali e non ho idea di come si comportino.

Adesso vedrò di provare con qualche testo in italiano.

mykol
08-02-2008, 17:55
in confronto a quelli che ho visto io sono ottimi ... certo dipende molto dalla qualità dell'originale scansionato e dalle impostazioni di luminosità, contrasto e dai DPI impostati.
Com'era la qualità del tuo originale ?

Com'è sto tesseract, ha un'intefaccia grafica, come come si usa ?

Dacci notizie, perchè il prob dell'OCR è uno dei maggiori tra il soft linux.

Willy McBride
08-02-2008, 18:18
in confronto a quelli che ho visto io sono ottimi ... certo dipende molto dalla qualità dell'originale scansionato e dalle impostazioni di luminosità, contrasto e dai DPI impostati.
Com'era la qualità del tuo originale ?

Com'è sto tesseract, ha un'intefaccia grafica, come come si usa ?

Dacci notizie, perchè il prob dell'OCR è uno dei maggiori tra il soft linux.

Altra prova in inglese.

Originale (tiff, 1.31 mb): http://www.megaupload.com/it/?d=CR5F2FWB (su megaupload, per qualche motivo imageshack lo converte in png a bassa risoluzione)

Ridimensionato, errori evidenziati come prima:
http://img504.imageshack.us/img504/8997/erroriyq5.th.jpg (http://img504.imageshack.us/my.php?image=erroriyq5.jpg)

Testo ottenuto:
. 5
discussion is derived in part from four authors (Goetz, 1989; Hunt, 1980; Nassau, 1980; Burns,
1970). The reader is referred to their papers, and those additional publications referenced therein,
for further details.
Quantum mechanics specifies that electrons in an atom must occupy specific quantized omits,
and there are'f6*iii· quantum numbers: a principalfan angular momentum, a magnetic, and a spin
quantum number. At energies corresponding to the visible and near-infrared portion of the
spectrum, the angular momentum quantum number is the most important for polyatomic
compounds such as minerals. The transition rules become quite complicated and, therefore, the
electronic states of polyatomic molecules are usually described in terms of their symmetry
behavior, i.e. the symmetry of the electronic wave function that is compatible with the symmetry
of the crystal lattice. Only a small number of symmetry groups are required to encompass
hundreds of thousands of molecules, and the molecular symmetries can be described in terms of
five symmetry elements: identity, plane of symmetry, center of symmetry, axis of symmetry, and
rotation reflection axis (Hunt, 1980). Only a few combinations of the symmetry elements occur,
and the combination of elements is called a group. Symmetry space groups are appropriate for
crystal lattices since the entire unit ceH is translated by an operation to another completely
equivalent position in the crystal. Energy levels are assigned to various symmetries call symmetry
species. Group theory allows certain states to be designated and as well provides selection rules
that detennine whether a transition between energy levels is allowed of forbidden.
When cations such as iron are imbedded in a crystal lattice, some of their electrons may end up
being shared by the solid as a whole instead of with a particular atom. The energy levels in this
case become more or less continuous and separated into regions called valence and conduction
bands separated by a forbidden region, as shown in figure 2. This behavior is associated with
semiconductors. The spectral reflectance of semiconductors, as shown in figure 3, exhibits very
low reflectance at short wavelengths until the critical wavelength equivalent to the width of the
forbidden band is reached, and the reflectance rapidly rises to a high value. The sloped edge of the
reflectance curve is due to impurities and defects in the lattice and lack of order in the crystal.
Charge-transfer transitions are a special case of semiconductor behavior in which electrons do
not enter into a conduction band, but rather transfer from one atom to another and remain localized
in the lattice. The charge transfer between iron and oxygen is the most common and results in a
strong absorption in the UV region. The wing of the band reaches into the visible portion of the
spectrum, giving rise to an increased reflectance toward longer wavelengths. The fact that almost
all materials have lower reflectance in the blue portion of the spectrum than in the red attests to the
fact that iron is nearly ubiquitous in minerals. The curves for hematite and goethite in figure 4 are
representative of this behavior.
Silicon, aluminum, and oxygen, which are the major constituents of crustal rocks, do not have
electronic energy levels that show features in the visible and near—infrared portions of the
spectrum. However, the transition elements, Fe, Cr, Ni, Ti, Co, Mn, Wo, and Sc all have
unfilled 3d shells that determine the energy levels but are under the influence of the crystal field in
which they are embedded. The symmetry of the field determines the energy levels and the
transitions. The excited states of these electrons have energies corresponding to the visible
wavelengths and are responsible for a wide range of colors. An example is the transition element
chromium in corundum (Al203). In corundum (ruby), the substitution of chromium for a few
percent of the aluminum ion creates the red color. The chromium ion has three unpaired electrons,
creating a complicated spectnun of excited states. The excited states form bands modified by the
presence of the crystal matrix. The position of each level in the energy spectrum is detennined by
the electric field in which the ion is placed. The symmetry and strength of the materials depends
on the other ions surrormding the chromium.
In corundum, each aluminum ion is surrounded by six oxygen ions in a distorted octahedron.
The crystal field of corundum is brought about because the valence electron pairs are more closely
coupled with the oxygen ions than they are with the aluminum, and this gives rise to an electric
field called the crystal field or ligand yield. A chromium ion placed in this field has three excited
stares of its unpaired electrons, which have energies in the visible portion of the spectnrm. Figure
5 is a schematic representation of an energy transition in ruby, showing the violet as well as green
and yellow absorptions due to excitations from the ground level, for A 2, to the excited states, for

Risultato: 828 parole, 11 errori "rossi", 4 errori "verdi".

Tesseract non ha interfaccia grafica, accetta solo tiff e restituisce un file txt. Per queste prove ho usato tesseract 2.01 con i dati 2.00 italiani e inglesi, il comando usato è semplicemente 'tesseract immagine.tiff testo -l eng'.

Qualche mese fa avevo letto di un progetto per integrare tesseract (e ocropus, un software sempre di google che usa tesseract e fa anche analisi del layout) in gnome-scan, però non so se poi si sia fatto qualcosa.

Adesso cerco qualcosa in italiano per vedere come funziona con la nostra lingua.

Willy McBride
08-02-2008, 19:27
Testo in italiano, da un giornale, modificata leggermente la curva dei colori perché la carta era molto scura: http://www.megaupload.com/?d=3SETCJVV

Testo ottenuto:
ono più forti i pregiudizi nei confronti delle donne 0 quelli raz-
ziali? Chi dei due stidanti avrebbe più chance di vincere le pre-
sidenziali? La maggioranza degli americani ha delle idee ben
precisein proposito, ma conosce davvero la realtà dei fatti? Cia-
scuno cita i suoi dati. Le donne sottolineano che i neri hanno conqui-
stato il diritto di voto già nel 1865, mentre il suffragio femminile è da-
`tato 1919. I neri ribattono che si trattava di un diritto solo formale, per-
che la massiccia discriminazione ne impedì l’effettivo esercizio lino
agli anni '60. Le donne sostengono di essere ancor meno rappresen-
tate dei neri al Congresso: pur costituendo il 50 per cento della popo-
lazione hanno solo il 17 per cento dei seggi nelle due camere. I neri so-
no il dodici per cento della popolazione e detengono circa l’otto per
cento dei seggi alCongresso. Sono sottorappresentati, èvero, ma sem-
pre meno delle donne. Le cariche amministrative elettive del paese so-
no ricoperte solo per il due per cento da neri (circa 9.000 amministra-
tori su 500.000) mentre alle donne va circail trentatrè per cento. Quan-
to incidono i pregiudizi di genere e razziali sulle chance di eleggibilità
dei candidati? Il tema è sempre più 0 etto di ricerche rivelatrici.
Secondo Leonie Huddy, docenteéñ scienze politiche della State
University of New York di Stonybrook, autrice di numerose pubblica-
zioni a riguardo, non c’è una risposta semplice al quesito. Ma aggiun-
ge. "In media il pregiudizio razziale èverosimilmente più penalizzan-
te per un candidato nero di quanto lo sia il pregiudizio di genere per
un candidato donna".
L’aspetto interessante è che le due forme di pregiudizio agiscono in
maniera assai diversa. E' vero che i candidati donna devono combat-
tere con gi stereotipi di genere (gli uomini sono più risoluti, le donne
più sensi ili) ma essi possono sia penalizzare che aiutare un candida-
to donna, a seconda delle circostanze.
Si considerano le donne più portate ad affrontare temi come la sa-
nità, la scuola e i problemi sociali, indipendentemente dalle idée che
hanno in proposito. Così quando il senatore dell’Illinois Paul Simon,
di posizioni molto liberal, si scontro in campagna elettorale con una
candidata conservatrice, Lynne Martin, perse parte dei consensi del
suo elettorato femminile sul tema del diritto all’aborto anche se il suo
programma era più ‘femminista’ di quello della sua avversaria. Le
donne danno anche l’impressione di una maggior onesta rispetto al-
la loro controparte maschile, per via del1’antico stereotipo che vuole
la corruzione prerogativa del politico maschio. In realtà i partecipan-
ti ad un esperimento condotto dalla Huddy e dai suoi colleghi, do-
vendosi esprimere su due politici, prima di integerrima reputazione e
poi accusati di corruzione, sulla base di una serie di informazioni for-
nite, identiche per entrambi, reputarono più onesta la donna, a di-
spetto dei dati di fatto. _
Al contempo l’opinione comune vuole le donne, in astratto, meno
capaci di affrontare problematiche come la difesa nazionale e l'eco-
nomia, considerate punti forti dei maschi. Così l’essere donna puo ri-
velarsiun vantaggio o uno svantaggio per un candidato, aseconda del-
le situazioni. In un’elezione dominata da temi di politica interna il
candidato donna puo essere avvantaggiato mentre può essere pena-
lizzato quando a prevalere sono i temi di politica estera e di sicurezza.
Pero, e qui la ricerca offre scenari davvero interessanti, i candidati
donna possono in alcuni casi ribaltare gli stereotipi di genere evince-
re comunque. Poiché gli stereotipi di genere sono profondamente ra-
dicati, le candidate che aspirano al successo a livello nazionale, spes-
so adottano degli stereotipi maschili per apparire ‘determinate’, ‘ag-
gressive` dei ‘fa chi' in politica estera. Cosi Margaret Thatcher dava di
sé un’immagine più dura e più ‘maschia’ dei suoi contemporanei uo-
mini. “Basta tergiversare! " disse a George Bush senior che mostrava
qualche titubanza alla vigilia della prima Guerra del golfo. Questo
spiega in parte la volontà di Hillary Clinton di apparire più aggressiva
in tema di difesa degli altri candidati democratici, il suo voto a favore
della Guerra in Iraq e la sua presenza nella commissione difesa del Se-
nato. .
Se essere donna può rivelarsi sia uno svantaggio che un vantaggio
per un candidato, il colore della pelle penalizza comunque i candida-
ti neri. In un esperimento condotto da Nayda Terkildsen, sempre del-
la State University of New York, ai partecipanti è stato fornito un dos-
sier di informazioni su dei candidati. Il curriculum e la posizione po-
litica erano identici, ma al primo gruppo è stata data lafoto di un bian-


Errori:
http://img135.imageshack.us/img135/7067/erroripy9.th.jpg (http://img135.imageshack.us/my.php?image=erroripy9.jpg)
Circa 800 parole.
In rosso, 14, parole sbagliate (la maggior parte accenti non riconosciuti)
In verde, 9, spazi non riconosciuti (c'è da dire che il testo è molto compresso per motivi di spazio disponibile).
In blu, 3, caratteri spurii aggiunti.

Risultati peggiori di prima, però l'immagine di partenza era di qualità inferiore e non so quanto sia completo il training per l'italiano, quindi può darsi che ci siano miglioramenti nelle prossime versioni.

iron84
08-02-2008, 22:02
devo provarlo. Ho sempre cercato un programma ocr in linux.

Willy McBride
09-02-2008, 23:26
Oggi ho fatto qualche altra prova con testi in italiano di varia origine (giornali, libri, enciclopedia): l'accuratezza media è stata del 97.5%. Per curiosità ho provato a usare sulle stesse scansioni (300 dpi, niente post-processing, direttamente come uscivano dallo scanner) ocrad e gocr: impressionante, spesso c'erano due o tre righe di seguito senza una singola parola corretta.

Tesseract, già nella sua versione 2.01, è su un livello completamente diverso. Sono anche curioso di vedere cosa verrà fuori dall'integrazione con ocropus, che dovrebbe fornire le feature che tesseract ancora non supporta (preprocessing, analisi del layout).