This commit is contained in:
xdrm-brackets 2017-09-13 18:40:21 +02:00
commit f42f89267d
1 changed files with 91 additions and 0 deletions

91
build/service/Tesseract.php Executable file
View File

@ -0,0 +1,91 @@
<?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;
}
}