univ-pau-ics/build/service/Tesseract.php

91 lines
2.1 KiB
PHP
Executable File

<?php
namespace service;
class Tesseract{
/* [1] Attributes
=========================================================*/
private $filename = null;
private $content = null;
private $course = null;
private $teacher = null;
private $room = null;
/* (1) Constructs and initialise a readed file
*
* @return instance<Tesseract> New Tesseract
*
---------------------------------------------------------*/
public function __construct($filename){
$this->filename = $filename;
return $this;
}
/* (2) Read the image file
*
* @return this
*
---------------------------------------------------------*/
public function read(){
/* [1] Record the text from the image
=========================================================*/
$filename = $this->filename;
$this->content = shell_exec("tesseract $filename stdout -l fra");
$lists = explode(chr(10), $this->content);
if (count($lists) < 3) {
throw new \Exception('Result not interpreted');
}
$this->course = $lists[0];
$this->teacher = $lists[1];
$this->room = $lists[2];
return $this;
}
/* (3) Return the text readed by the Tesseract OCR
*
* @return $this->content
*
---------------------------------------------------------*/
public function getContent() {
return $this->content;
}
/* (4) Return the course readed by the Tesseract OCR
*
* @return $this->course
*
---------------------------------------------------------*/
public function getCourse() {
return $this->course;
}
/* (5) Return the teacher readed by the Tesseract OCR
*
* @return $this->teacher
*
---------------------------------------------------------*/
public function getTeacher() {
return $this->teacher;
}
/* (6) Return the room class readed by the Tesseract OCR
*
* @return $this->room
*
---------------------------------------------------------*/
public function getRoom() {
return $this->room;
}
}