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
Conversation
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. |
|
||
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
please wait before merge I have an error. Now it works you can merge. |
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. |
I do not know what I can do to pass the licence/Cla. WHen I click details it opens a page that says: |
Make sure the email address set for the local GitHub config is the same as used in CLA |
git config user.author "" 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. |
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 |
this other PR is CLA signed green. #13847 But strangely the checks are red. |
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
Checklist
Further comments