Beispiel #1
0
 public function run(array $context = [])
 {
     $ocr = Number::instance($this->manager, $this->app);
     $point = Manager::readConfig($context, 'point');
     Position::assertPoint($point);
     $this->logger->info('Test for X=%.4f, Y=%.4f', $point[Position::X], $point[Position::Y]);
     $ocr->setRules(['Test' => ['J' => [$point], 'T' => 1, 'F' => 0]]);
     $rect = Position::makeRectangle(0, 0, 1, 1);
     for ($i = 0; $i <= 9; $i++) {
         $this->screen->load(sprintf('tests/digits/%u.png', $i), Screen::PORTRAIT);
         $this->logger->info('OCR Result for digit %u is %s', [$i, $ocr->ocr('Test', $rect, [Number::CFG_COLOR => '000000', Number::CFG_WIDTH => 1, Number::CFG_MARGIN => 0])]);
     }
     return Manager::RET_LOOP;
 }
Beispiel #2
0
 public static function checkRule(array &$rule)
 {
     if (!isset($rule[self::RULE_JUDGE]) || !is_array($rule[self::RULE_JUDGE])) {
         throw new \InvalidArgumentException('OCR Rule lacks judgement or is not array.');
     }
     foreach ($rule[self::RULE_JUDGE] as &$point) {
         Position::assertPoint($point);
     }
     if (!array_key_exists(self::RULE_TRUE, $rule)) {
         throw new \InvalidArgumentException('OCR Rule lacks true decision.');
     }
     if (!array_key_exists(self::RULE_FALSE, $rule)) {
         throw new \InvalidArgumentException('OCR Rule lacks false decision.');
     }
     if (is_array($rule[self::RULE_TRUE])) {
         self::checkRule($rule[self::RULE_TRUE]);
     }
     if (is_array($rule[self::RULE_FALSE])) {
         self::checkRule($rule[self::RULE_FALSE]);
     }
     return true;
 }
Beispiel #3
0
 public function tapPoint($point)
 {
     Position::assertPoint($point);
     return $this->tap($point[Position::X], $point[Position::Y]);
 }
Beispiel #4
0
 public static function assertRules(array $rules)
 {
     foreach ($rules as $color => $positions) {
         if (!preg_match(self::REGEXP_COLOR, $color)) {
             throw new \InvalidArgumentException("Invalid color notation '{$color}'.");
         }
         if (!is_array($positions)) {
             throw new \InvalidArgumentException('Points array in rule entry does not exist.');
         }
         foreach ($positions as $position) {
             try {
                 Position::assertPoint($position);
             } catch (\Exception $e) {
                 Position::assertRect($position);
             }
         }
     }
     return true;
 }