Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: example of image occurrence comparison in Typescript/Javascript #13833

Closed
wants to merge 1 commit into from
Closed

Conversation

MagicPoulp
Copy link
Contributor

Proposed changes

Add doc about how to run opencv with the Javascript client.

Full discussion on the Appium forum:
https://discuss.appium.io/t/how-to-do-image-comparison/29238

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ x] Documentation Update (if none of the other choices apply)

Checklist

  • [x ] I have read the CONTRIBUTING doc
  • [x ] I have signed the CLA
  • [ x] Lint and unit tests pass locally with my changes
  • [ x] I have added tests that prove my fix is effective or that my feature works
  • [x ] I have added necessary documentation (if appropriate)
  • [ x] Any dependent changes have been merged and published in downstream modules

Further comments

@jsf-clabot
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Thierry Vilmart seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

@coveralls
Copy link

coveralls commented Jan 14, 2020

Coverage Status

Coverage remained the same at 88.843% when pulling eabac2f on MagicPoulp:master into 67eeed5 on appium:master.


You must install opencv4nodejs using the -g option.

The Javascript client does not support (in January 2020) the "-image" strategy implemented in the Appium server. You will have more power and understanding while using openCV directly. Since The appium server is in Javascript, you can do all it does with opencv in the client.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

means the webdriverio client, because there are also others, for example wd

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

```javascript
Typescript / Javascript
/*
Typescsript code for occurence comparison using the template matching algorithm.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say it would be better to add this text to the bottom of the document under a separate heading

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you mean the text about difference between feature and occurrence. I moved it to the top of the occurrence heading.

You will also need to make a basic config/tsconfig_test.json and you will need an environemnt
variable giving the absolute path to where opencv4nodejs is located in nodejs
*/
const cv = require(process.env.OPENCV4NODEJS_PATH + '/lib/node_modules/opencv4nodejs');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually one can use the standard NODE_ROOT environment variable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mocha does not have NODE_ROOT built in. But I will use NODE_PATH like mocha documents.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. I meant NODE_PATH

/// Take screenshot and read the image
const screenImagePath = './appium_screenshot1.png';
driver.saveScreenshot(screenImagePath)
const screenImage = cv.imread(screenImagePath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer async functions to sync if such functions exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -97,6 +99,65 @@ File.open('find_result_visual.png', 'wb') { |f| f<< Base64.decode64(find_result_
assert File.size? 'find_result_visual.png'
```

```javascript
Typescript / Javascript
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should also be a comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

NODE_PATH=/path/to/nodejs TS_NODE_PROJECT=config/tsconfig_test.json --require ts-node/register --require tsconfig-paths/register
You will also need to make a basic config/tsconfig_test.json
*/
const cv = require(process.env.NODE_PATH + '/lib/node_modules/opencv4nodejs');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume NODE_PATH should already be pointing to the root of node_modules

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use path module to join parts of paths

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually dislike to have a dynamic require. Only imports should be used. But the paths in compilerOptions in tsconfig.json does not support absolute paths.

But ok.

const likedImagePath = './occurrence1.png';

// Load images
const originalMat = await cv.imreadAsync(screenImagePath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be done in parallel, like in the appium-support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

cv.imshow('We\'ve found Waldo!', originalMat);
await cv.waitKey();

// then you can know if the image was found by comparing the rectangle with a reference rectangle.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then you know if the image ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@MagicPoulp
Copy link
Contributor Author

MagicPoulp commented Jan 14, 2020

please wait before merge I have an error.

Now it works you can merge.

@MagicPoulp
Copy link
Contributor Author

MagicPoulp commented Jan 14, 2020

I have left the cv.imwrite as an exercise at the end since the image is too big to show. But I tested the final code with a imwrite and the image detection works.

@MagicPoulp
Copy link
Contributor Author

I do not know what I can do to pass the licence/Cla. WHen I click details it opens a page that says:
"You have signed the CLA for appium/appium". ANd my name and email cannot be edited.
But the email does not match the github email so maybe that is why it does not work.

@mykola-mokhnach
Copy link
Collaborator

Make sure the email address set for the local GitHub config is the same as used in CLA

@MagicPoulp
Copy link
Contributor Author

MagicPoulp commented Jan 15, 2020

git config user.author ""
git config user.email ""
are both set to what is shown by the CLA page.
And the commit I have contains also both correct data.

But the email is not the one in my git hub, So maybe github wants to see my real email. I could do it but I cannot edit th CLA now it is frozen.

What can I do? I tried chrome and firefox.

@mykola-mokhnach
Copy link
Collaborator

The bot compares the email address to the one returned by GitHub. You could update your local config and recreate the PR with the new config, so the bot understands the CLA is signed

@MagicPoulp MagicPoulp closed this Jan 16, 2020
@MagicPoulp
Copy link
Contributor Author

MagicPoulp commented Jan 16, 2020

this other PR is CLA signed green. #13847

But strangely the checks are red.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants