GithubHelp home page GithubHelp logo

omr's Introduction

Optical Mark Recognition with PHP

Latest Stable Version Total Downloads Latest Unstable Version MIT license Build Status

This is an open source library written in PHP for recognition markings on questionnaires scans

See: https://en.wikipedia.org/wiki/Optical_mark_recognition

How to use

Add library:

$ composer require jansenfelipe/omr

Instantiate the Scanner class responsible for reading the image and enter its path

/*
 * Setup scanner
 */
$scanner = new ImagickScanner();
$scanner->setImagePath($imagePath);

You will need to scan a blank form and create the Target Mapping File to be able to use the library.

After creating the map.json file, enter its path:

/*
 * Setup map
 */
$map = MapJson::create($mapJsonPath);

Now you can scan and get the result

$result = $scanner->scan($map);

Scanners

This library currently has only one scanner class using Imagemagick 6. It has been tested using the following configurations:

  • PHP 7.3
  • imagemagick6
  • Extension imagick-3.4.4

See https://github.com/jansenfelipe/omr/blob/master/src/Scanners/ImagickScanner.php

Target Mapping File

It is a .json file that describes, in addition to the image information, the coordinates of the places (targets) that the script must do the pixel analysis. This file follows the following pattern:

{
    "width": 600,
    "height": 800,
    "targets": [
      {
        "x1": 50,
        "y1": 43,
        "x2": 65,
        "y2": 57,
        "id": "Foo",
        "type": "rectangle",
        "tolerance": 60
      }
    ] 
}

Example

In the example directory there is an image of a completed questionnaire response.png. There is also a map.json file that gives the coordinates of the image areas that will be analyzed the pixels.

To help with setting up the environment, there is a Dockerfile in the project based on the official PHP 7.3 image that adds composer, imagemagick and the imagick extension to PHP.

That way you can install the dependencies and run the command to process the image without headaches :)

  1. Clone this repo:
$ git clone https://github.com/jansenfelipe/omr.git
$ cd omr/
  1. Install dependencies:
$ docker-compose run php composer install
  1. Process example image:
$ docker-compose run php bin/omr scan example/response.png example/map.json

License

The MIT License (MIT)

omr's People

Contributors

cviniciussdias avatar ins0 avatar jansenfelipe avatar jgrossi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

omr's Issues

Promising script... Got this error though

Hello:

I got the following error after I enter the following command

$ docker-compose run php composer install

bitnami@ip-172-26-7-199:~/htdocs/omr$ docker-compose run php composer install
ERROR: Version in "./docker-compose.yml" is unsupported. You might be seeing this error bec
ause you're using the wrong Compose file version. Either specify a version of "2" (or "2.0"
) and place your service definitions under the services key, or omit the version key an
d place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-f
ile/

Any idea on how to solve this?

Create functional tests

Your project looks great and we had not any OMR implementation in PHP yet.

In order to make your project successful I recommend you to add some tests.

Scanned image is 100% black

All scanned images result in 100% black. This effect is displayed on the debugged image.

I leave as an example the image below:

0001_edited

Debug image

debug

Problema ao instalar a extenção imagick

Olá, tentei instalar a extenção imagick de várias formas diferentes mas nenhuma deu certo. Ela não aparece no php info. Pode me dizer alguma forma de instalar e quais versões? Pode ser pra ubuntu, ou windows?

Imagick::medianFilter()

Tried all earlier versions of the Imagick dLL medianFilter() is deprecated still kept showing....

Classes not found

Hi, i can't get the library installed and working properly. I'm trying to execute the demo snippet of code but i get:

Fatal error: Class 'OMR\src\Contracts\Scanner' not found in /var/www/clients/client0/web5/web/web/vendor/lib/OMR/src/Scanners/ImagickScanner.php on line 11

I don't have really clear how to manage Composer packages installation.

System infos: Debian 9.6, PHP 7.0 (FPM), Apache2

Here the code:

<?php

require 'OMR/src/Scanners/ImagickScanner.php';
require 'OMR/src/Contracts/Scanner.php';

/*namespace JansenFelipe\OMR\Scanners;

use Imagick;
use ImagickDraw;
use JansenFelipe\OMR\Area;
use JansenFelipe\OMR\Contracts\Scanner;
use JansenFelipe\OMR\Point;*/

$imagePath = 'Papers.Scanned/paper.jpeg';
$mapJsonPath = 'OMR/map.json';
/*
 * Setup Scanners/ImacickScanner
 */
$scanner = new ImagickScanner();
$scanner->setImagePath($imagePath);

/*
 * Scan
 */
$result = $scanner->scan(MapJson::create($mapJsonPath), 28);

//analysis
circleArea(011, 20, 5);
circleArea(012, 20, 5);
circleArea(013, 20, 5);
circleArea(014, 20, 5);

/*
 * Save result
 */
$imagePath = 'Papers.Scanned/Result/paper.jpeg';
createResult($imagePath);


debug()
?>

Thanks!!

Cant install with composer.

php composer.phar require jansenfelipe/omr

Give me this:

Using version ^2.0 for jansenfelipe/omr
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install jansenfelipe/omr 2.0
    - Conclusion: remove symfony/console v5.1.6
    - Installation request for jansenfelipe/omr ^2.0 -> satisfiable by jansenfelipe/omr[2.0, 2.0.x-dev].
    - Conclusion: don't install symfony/console v5.1.6
    - jansenfelipe/omr 2.0.x-dev requires symfony/console 2.7.* -> satisfiable by symfony/console[2.7.x-dev, v2.7.0, v2.7.0-BETA1, v2.7.0-BETA2, v2.7.1, v2.7.10, v2.7.11, v2.7.12, v2.7.13, v2.7.14, v2.7.15, v2.7.16, v2.7.17, v2.7.18, v2.7.19, v2.7.2, v2.7.20, v2.7.
21, v2.7.22, v2.7.23, v2.7.24, v2.7.25, v2.7.26, v2.7.27, v2.7.28, v2.7.29, v2.7.3, v2.7.30, v2.7.31, v2.7.32, v2.7.33, v2.7.34, v2.7.35, v2.7.36, v2.7.37, v2.7.38, v2.7.39, v2.7.4, v2.7.40, v2.7.41, v2.7.42, v2.7.43, v2.7.44, v2.7.45, v2.7.46, v2.7.47, v2.7.48, v2
.7.49, v2.7.5, v2.7.50, v2.7.51, v2.7.6, v2.7.7, v2.7.8, v2.7.9].
    - Can only install one of: symfony/console[2.7.x-dev, v5.1.6].
    - Can only install one of: symfony/console[v2.7.0, v5.1.6].
    - Can only install one of: symfony/console[v2.7.0-BETA1, v5.1.6].
    - Can only install one of: symfony/console[v2.7.0-BETA2, v5.1.6].
    - Can only install one of: symfony/console[v2.7.1, v5.1.6].
    - Can only install one of: symfony/console[v2.7.10, v5.1.6].
    - Can only install one of: symfony/console[v2.7.11, v5.1.6].
    - Can only install one of: symfony/console[v2.7.12, v5.1.6].
    - Can only install one of: symfony/console[v2.7.13, v5.1.6].
    - Can only install one of: symfony/console[v2.7.14, v5.1.6].
    - Can only install one of: symfony/console[v2.7.15, v5.1.6].
    - Can only install one of: symfony/console[v2.7.16, v5.1.6].
    - Can only install one of: symfony/console[v2.7.17, v5.1.6].
    - Can only install one of: symfony/console[v2.7.18, v5.1.6].
    - Can only install one of: symfony/console[v2.7.19, v5.1.6].
    - Can only install one of: symfony/console[v2.7.2, v5.1.6].
    - Can only install one of: symfony/console[v2.7.20, v5.1.6].
    - Can only install one of: symfony/console[v2.7.21, v5.1.6].
    - Can only install one of: symfony/console[v2.7.22, v5.1.6].
    - Can only install one of: symfony/console[v2.7.23, v5.1.6].
    - Can only install one of: symfony/console[v2.7.24, v5.1.6].
    - Can only install one of: symfony/console[v2.7.25, v5.1.6].
    - Can only install one of: symfony/console[v2.7.26, v5.1.6].
    - Can only install one of: symfony/console[v2.7.27, v5.1.6].
    - Can only install one of: symfony/console[v2.7.28, v5.1.6].
    - Can only install one of: symfony/console[v2.7.29, v5.1.6].
    - Can only install one of: symfony/console[v2.7.3, v5.1.6].
    - Can only install one of: symfony/console[v2.7.30, v5.1.6].
    - Can only install one of: symfony/console[v2.7.31, v5.1.6].
    - Can only install one of: symfony/console[v2.7.32, v5.1.6].
    - Can only install one of: symfony/console[v2.7.33, v5.1.6].
    - Can only install one of: symfony/console[v2.7.34, v5.1.6].
    - Can only install one of: symfony/console[v2.7.35, v5.1.6].
    - Can only install one of: symfony/console[v2.7.36, v5.1.6].
    - Can only install one of: symfony/console[v2.7.37, v5.1.6].
    - Can only install one of: symfony/console[v2.7.38, v5.1.6].
    - Can only install one of: symfony/console[v2.7.39, v5.1.6].
    - Can only install one of: symfony/console[v2.7.4, v5.1.6].
    - Can only install one of: symfony/console[v2.7.40, v5.1.6].
    - Can only install one of: symfony/console[v2.7.41, v5.1.6].
    - Can only install one of: symfony/console[v2.7.42, v5.1.6].
    - Can only install one of: symfony/console[v2.7.43, v5.1.6].
    - Can only install one of: symfony/console[v2.7.44, v5.1.6].
    - Can only install one of: symfony/console[v2.7.45, v5.1.6].
    - Can only install one of: symfony/console[v2.7.46, v5.1.6].
    - Can only install one of: symfony/console[v2.7.47, v5.1.6].
    - Can only install one of: symfony/console[v2.7.48, v5.1.6].
    - Can only install one of: symfony/console[v2.7.49, v5.1.6].
    - Can only install one of: symfony/console[v2.7.5, v5.1.6].
    - Can only install one of: symfony/console[v2.7.50, v5.1.6].
    - Can only install one of: symfony/console[v2.7.51, v5.1.6].
    - Can only install one of: symfony/console[v2.7.6, v5.1.6].
    - Can only install one of: symfony/console[v2.7.7, v5.1.6].
    - Can only install one of: symfony/console[v2.7.8, v5.1.6].
    - Can only install one of: symfony/console[v2.7.9, v5.1.6].
    - Installation request for symfony/console (locked at v5.1.6) -> satisfiable by symfony/console[v5.1.6].


How to adjust size and rotation?

I watched a lecture of yours in youtube (I'm Brazilian, but I'll do this in english so more people could understand) and in one point you talk about rotation and size adjustments to the input file, but reading out the script I found the functions but I have no clue how to use them. May you help me?

example

Res. Sir,
I was able to use this library for rectangle but for circle i am getting this error Fatal error: Uncaught Error: Call to a member function percentBlack() on bool

Can You Please help me on this

funcation of circleArea

funcation of circleArea is not working

error : " Uncaught Error: Call to a member function percentBlack() on boolean"

Como usar o sistema?

Baixei uma imagem qualquer na internet e executei o exemplo:
php vendor/bin/omr scan questionarie.jpg map.json

Foi criado uma imagem debug.jpg em branco. Como o sistema deveria funcionar? Existe uma outra forma de testar?

example with source code

Hi Felipe,
i would like to use your omr into my project. I trying to use it following an example founded https://jansenfelipe.com.br/2016/03/21/optical-mark-recognition-com-o-php/
but i don't understand how use it. I created and passed a map to scanner but results don't change

        $scanner = new ImagickScanner();
        $scanner->setImagePath($quest_images[0]);
        $result = $scanner->scan(MapJson::create($mapJsonPath));

i saw that debug image is always rotated and targets offset are differents, i tryed many changes into map file.
Could you add to project an example with image and map file ?
so it would be more sample know how add omr.

thanks
Armando

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.