We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

Create OMR Template with PHP SDK of Aspose.OMR REST API issue

I am new to ASPOSE Products.

My code is:

$omr = new Aspose\Omr\Api\OmrApi($appKey, $appSid);
$response = $omr->postRunOmrTask(" ans.txt “, “GenerateTemplate”);
file_put_contents(time().”.response.txt", $response);

I am getting following error:

**Fatal error** : Uncaught exception 'Aspose\Omr\ApiException' with message '[404] Client error: `POST [https://api.aspose.cloud/v1.1/omr/ans.txt/runOmrTask?actionName=GenerateTemplate`](https://api.aspose.cloud/v1.1/omr/ans.txt/runOmrTask?actionName=GenerateTemplate) resulted in a `404 Not Found` response: {"Message":"AmazonS3 exception: Error 'The specified key does not exist.', Bucket 'afc-filestorage', FilePath '82741/189 (truncated...) '

Please tell me what should I place in ans.txt file

Why is this error coming?


Thanks for your inquiry. As per your code you are generating a template for OMR operation and as per error it seems the required template file is missing on the storage.

The text file should include template details. Please check following documentation for more details. You can find sample documents from PHP SDK.

Template Generation
Template Requirements

  1. I have not configured that API to look for AWS S3 for storage. Then why is it looking for S3 Storage?
    Why we need S3. Can we use other Storage options? How?

  2. I had placed “ans.txt” (Which was placed in my local hdd) the following text:

?text=Name__________________________________ Date____________

#What is Aspose.OMR main function?
() OCR () Capture human-marked data
() There is no main function () Enhance images
#Can Aspose.OMR process not only scans, but also photos?
() Yes, indeed! () No
#Aspose.OMR is available on any platform, because it is:
() Cross-platform code () Cloud service
#Aspose.OMR works with any kind of OMR forms: tests, exams, questionnaires, surveys, etc.
() Yes, indeed! () No
#Excellent recognition results can be achieved only for filled bubbles at least for:
() 40% () 60% () 75% () 98%
#Does Aspose.OMR support bubbles mapping to any key names?
() No () Partially (only “A, B, C…” or “1, 2, 3…”) () Yes, any key names
#Do you have to mark up every question on the page?
(Yes) Yes, that will help a lot! (No) No
#Rate your preference from 0 to 9 with “0” being preference towards performance
and “9” being preference towards flexibility.
(0) (1) (2) (3) (4) (5) (6) (7) (8) (9)
#I found aspose omr to be a useful tool. (5 - strongly agree, 1 - strongly disagree)
(5) (4) (3) (2) (1)

?text= Answer sheet section


Is it incorrect?

  1. In dashboard it says
    Storage type: Aspose Cloud Storage
    Then why is it looking for S3.


Thanks for your inquiry. Please note our APIs are hosted at AWS S3, so you are getting the S3 in the error message.

Yes, you can use third party storage with Aspose Cloud APIs. Please check following article for details.

How to Configure 3rd Party Cloud Storages

For template, please use tab key to indent answers. Please find the updated template.
test.zip (783 Bytes)

Thank you!
Finally I am able to generate OMR sheets from text files.
Now I want to process the answers given. I have created a jpg file and used GIMP to fill the dots and then uploaded to my dropbox account.

My code is:
$omr = new OmrApi($appKey, $appSid);
$response = $omr->postRunOmrTask(“answersheet.jpg”, “RecognizeImage”, null, “XStore”);
file_put_contents(time().".RecognizeImage.txt", $response);

I don’t know what “RecognizeImage” will do. But it returned the following error:

“Status”: “OK”,
“ErrorCode”: 3,
“ErrorText”: “join() argument must be str or bytes, not ‘NoneType’ Error reference ID 0357b1fa-eaf1-4684-a2ad-f21873a9f2b8”,
“Payload”: {
“Result”: {
“TemplateId”: “”,
“ExecutionTime”: 0,
“ResponseFiles”: [],
“Info”: {
“ProcessedTasksCount”: 0,
“SuccessfulTasksCount”: 0,
“Details”: {
“RecognitionStatistics”: []
“ServerStat”: {
“StorageDownloadTime”: “00:00:00.6445892”,
“OmrFunctionCallTime”: “00:00:01.7411521”

I need some kind of json/csv/text output about what students have answered for each question. What should I do? We have our software which will generate the result. We just want to know the answers given for each question.


Thanks for your inquiry. Please check PHP working demo for understanding the complete OMR workflow with Aspose.OMR Cloud.

Furthermore, for JSON output check response content detail of Recognize Image function, it provides JSON results within OmrResponse.Payload.Result.Info.Details .

When I run the demo I get the following error:

php omr_demo.php

Starting OMR Demo
PHP Fatal error: Uncaught Exception: Config file not found: test_config.json in /home/ankurgupta/Server/websites/lab.nginx/omrdemo/omr_demo.php:189
Stack trace:
#0 /home/ankurgupta/Server/websites/lab.nginx/omrdemo/omr_demo.php(157): Aspose\Omr\Demo\OmrDemo->loadConfig()
#1 /home/ankurgupta/Server/websites/lab.nginx/omrdemo/omr_demo.php(469): Aspose\Omr\Demo\OmrDemo->__construct()
#2 {main}
thrown in /home/ankurgupta/Server/websites/lab.nginx/omrdemo/omr_demo.php on line 189

Where can I find test_config.json and where should I place this file? What this file should contain?


We are sorry for your inconvenience. Please make sure to update all the sub-modules, clone sub-modules as suggested in Readme. It will clone aspose-omr-cloud-demo-data module, it contains all the required sample data for demo.

Clone  `aspose-omr-cloud`   **with submodules** :

git clone https://github.com/aspose-omr-cloud/aspose-omr-cloud-php.git --recurse-submodules

While studying the code, I saw the following methods:

I only understand one of them: GenerateTemplate which is used to create template image from config file of answersheet.

What is difference among: CorrectTemplate, FinalizeTemplate and RecognizeImage

What they do? Which of them actually checks the filled (marked) omr sheet and create output?


Thanks for your feedback. Please check OMR API specifications for your questions. It provides details with sample code.

Actually I want to know what these words means or what these actions do. This is not explained in the link that you have given.
For example I know that “GenerateTemplate” creates a image of answersheet from the text specification we input. But I am confused about others, like what CorrectTemplate will do? Similarly what “FinalizeTemplate” will do? I think “RecognizeImage” will check the answers of student. Am I right?
and what is use of “ValidateTemplate”.

Thanks for sharing the additional information. I am looking into your questions and will update you shortly.


Please note, the template correction analyses position of all elements on the template image, corrects them and provides a more precise positioning. This is to cover cases when user provided input is imprecise, and to reduce possible future recognition errors caused by inaccurate positioning.

And template finalization is a process when template data required for the future recognition is calculated. This allows us to recognize actual photos faster, since most of the required information already processed in finalization. It takes quite a long time, but required only once per template.

Correction and Finalization are done only once per template, and then any amount of photos can be recognized. So this operation should be called when you are satisfied with your template and do not plan to add any changes to it. Hopefully it will answer your questions. Please feel free to ask if you still have any confusion.

This is my code:

$basePath = "https://api.aspose.cloud/v1.1";
$remFolder = "omrapi";
$templateFile = "source/template.txt";
$templateImage = "template.png";
$answerFile = "answersheet.jpg";

include "config.php";

//Upload template file to dropbox
$storage = new Storage($appKey, $appSid, $basePath);
$storage->uploadFile("./response/".$templateImage, $remFolder."/".$templateImage);

$omr = new OmrApi($appKey, $appSid); 

//Generate sheet from dropbox

try {     

    //$response = $omr->postRunOmrTask($filename, "RecognizeImage", null, "XStore", $remFolder);
    $corrResponse = $omr->postRunOmrTask($templateImage, "CorrectTemplate", null, "XStore", $remFolder);
    echo "<pre>";
    echo "</pre>";
    $templateId = $corrResponse->getPayload()->getResult()->getTemplateId();
    echo "<h1>";
    echo $templateId;
    $param = new AsposeOmr\Model\OMRFunctionParam();
    $response = $omr->postRunOmrTask($answerFile, "RecognizeImage", $param, "XStore", $remFolder);
} catch (Exception $exc) {
    echo $exc->getMessage(); 
$responseObj = (object)$response;
if ($responseObj->getStatus() != "OK"){
    throw new \Exception("Request failed {$text} : " . $responseObj->getStatus());

file_put_contents(time().".answer.txt", $response);
echo "Done";

I am getting the following error:
Request processing caused an exception. Check files uploaded correctly and try again. Template template does not exists. Error reference ID 5c66c581-74c9-4d5d-9d0c-291192a0721c

I tried your demo. It worked but its code is piece of puzzle. Even for loading a simple configuration file too much code has been written on it. One function is calling second, second calling third and third is calling fourth, only to load configuration file. This is very confusing. I am not able to reuse the code of demo. How ever I tried myself to write some code but unfortunately getting the above error.

Can you please explain how can I fix it.


Thanks for your inquiry. It seems you have not passed the omr template data in correct template action. Please note for CorrectTemplate action you need to pass omr file in specific form, it is JSON with the following structure:

Files[ {
string Name;
long Size;
string Data;
} ]
where Data is base64 string containing omr file data.