Exctract event's images ok

This commit is contained in:
xdrm-brackets 2017-09-13 16:55:49 +02:00
parent e977ef04c8
commit 84ee33f718
1 changed files with 47 additions and 10 deletions

View File

@ -159,8 +159,10 @@
/* [3] For each day -> get events
=========================================================*/ {
$uid = 0;
/* (1) For each day */
for( $day_n = 0 ; $day_n <= count($col_ind) ; $day_n++ ){
for( $day_n = 0 ; $day_n < count($col_ind)-1 ; $day_n++ ){
$col_x = $col_ind[$day_n];
@ -179,23 +181,23 @@
$start_y = $y;
$time = $this->yToTime($day_n, $start_y);
// {2} Store default event name if not already set //
if( !isset($d_db[$p1e]) )
$d_db[$p1e] = $p1e;
// {2} Incr uid //
$uid++;
// {3} Store event start //
$this->event[$p1e][$time] = [];
$this->event[$uid][$time] = [];
// {4} Seek end of event //
$y++;
while( $y < self::$stop_y && $this->getColor($col_x, $y) != 0 )
$y++;
// {5} If end reached //
$this->event[$p1e][$time] = $this->yToTime($day_n, $y);
$this->event[$uid][$time] = $this->yToTime($day_n, $y);
// {6} Exctract event's image //
$this->extractEvent([$col_x, $start_y+1], [$col_ind[$day_n+1]-1, $y]);
$this->extractEvent("$time-$uid", [$col_x, $start_y+1], [$col_ind[$day_n+1]-1, $y]);
}
@ -228,12 +230,44 @@
/* (3) Exctracts an event
*
* @uid<String> Image uid
* @start<Array> Start rect (x, y)
* @stop<Array> Stop rect (x, y)
*
---------------------------------------------------------*/
public function extractEvent($start=null, $stop=null){
var_dump("from (${start[0]}, ${start[1]}) to (${stop[0]}, ${stop[1]})");
public function extractEvent($uid, $start=null, $stop=null){
/* [1] Get the right clip
=========================================================*/
/* (1) Create clipped copy */
$clip = \imagecreatetruecolor($stop[0]-$start[0], $stop[1]-$start[1]);
$copied = \imagecopyresized(
$clip, // destin img
$this->img_res, // source img
0, // dest x
0, // dest y
$start[0], // src x
$start[1], // src y
$stop[0]-$start[0], // dest w
$stop[1]-$start[1], // dest h
$stop[0]-$start[0], // src w
$stop[1]-$start[1] // src h
);
/* (2) Manage copy error */
if( !$copied )
throw new \Exception("Cannot clip image");
/* (3) Save to file */
\imagesavealpha($clip, true);
if( !\imagejpeg($clip, __ROOT__."/tmp/$uid.jpeg") )
throw new \Exception("Cannot save image");
/* [2] Process OCR
=========================================================*/
// TODO:
}
@ -347,7 +381,10 @@
=========================================================*/
foreach($this->event as $event_col=>$events){
$type = $col_assoc[$event_col];
$type = "unknown";
if( isset($col_assoc[$event_col]) )
$type = $col_assoc[$event_col];
/* (2) For each event of each type
---------------------------------------------------------*/