How to use imageDifference method in argos

Best JavaScript code snippet using argos

posit1.js

Source:posit1.js Github

copy

Full Screen

1/*2Copyright (c) 2012 Juan Mellado3Permission is hereby granted, free of charge, to any person obtaining a copy4of this software and associated documentation files (the "Software"), to deal5in the Software without restriction, including without limitation the rights6to use, copy, modify, merge, publish, distribute, sublicense, and/or sell7copies of the Software, and to permit persons to whom the Software is8furnished to do so, subject to the following conditions:9The above copyright notice and this permission notice shall be included in10all copies or substantial portions of the Software.11THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR12IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,13FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE14AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER15LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,16OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN17THE SOFTWARE.18*/19/*20References:21- "Iterative Pose Estimation using Coplanar Feature Points"22Denis Oberkampf, Daniel F. DeMenthon, Larry S. Davis23http://www.cfar.umd.edu/~daniel/daniel_papersfordownload/CoplanarPts.pdf24*/25var POS = POS || {};26POS.Posit = function(modelSize, focalLength){27 this.objectPoints = this.buildModel(modelSize);28 this.focalLength = focalLength;29 30 this.objectVectors = [];31 this.objectNormal = [];32 this.objectMatrix = [[],[],[]];33 34 this.init();35};36POS.Posit.prototype.buildModel = function(modelSize){37 var half = modelSize / 2.0;38 39 return [40 [-half, half, 0.0],41 [ half, half, 0.0],42 [ half, -half, 0.0],43 [-half, -half, 0.0] 44 ];45};46POS.Posit.prototype.init = function(){47 var np = this.objectPoints.length,48 vectors = [], n = [], len = 0.0, row = 2, i;49 50 for (i = 0; i < np; ++ i){51 this.objectVectors[i] = [this.objectPoints[i][0] - this.objectPoints[0][0],52 this.objectPoints[i][1] - this.objectPoints[0][1],53 this.objectPoints[i][2] - this.objectPoints[0][2]];54 55 vectors[i] = [this.objectVectors[i][0],56 this.objectVectors[i][1],57 this.objectVectors[i][2]];58 }59 60 while(0.0 === len){61 n[0] = this.objectVectors[1][1] * this.objectVectors[row][2] -62 this.objectVectors[1][2] * this.objectVectors[row][1];63 n[1] = this.objectVectors[1][2] * this.objectVectors[row][0] -64 this.objectVectors[1][0] * this.objectVectors[row][2];65 n[2] = this.objectVectors[1][0] * this.objectVectors[row][1] -66 this.objectVectors[1][1] * this.objectVectors[row][0];67 68 len = Math.sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]);69 70 ++ row;71 }72 73 for (i = 0; i < 3; ++ i){74 this.objectNormal[i] = n[i] / len;75 }76 77 POS.pseudoInverse(vectors, np, this.objectMatrix);78};79POS.Posit.prototype.pose = function(imagePoints){80 var posRotation1 = [[],[],[]], posRotation2 = [[],[],[]], posTranslation = [],81 rotation1 = [[],[],[]], rotation2 = [[],[],[]], translation1 = [], translation2 = [],82 error1, error2, valid1, valid2, i, j;83 84 this.pos(imagePoints, posRotation1, posRotation2, posTranslation);85 86 valid1 = this.isValid(posRotation1, posTranslation);87 if (valid1){88 error1 = this.iterate(imagePoints, posRotation1, posTranslation, rotation1, translation1);89 }else{90 error1 = {euclidean: -1.0, pixels: -1, maximum: -1.0};91 }92 93 valid2 = this.isValid(posRotation2, posTranslation);94 if (valid2){95 error2 = this.iterate(imagePoints, posRotation2, posTranslation, rotation2, translation2);96 }else{97 error2 = {euclidean: -1.0, pixels: -1, maximum: -1.0};98 }99 100 for (i = 0; i < 3; ++ i){101 for (j = 0; j < 3; ++ j){102 if (valid1){103 translation1[i] -= rotation1[i][j] * this.objectPoints[0][j];104 }105 if (valid2){106 translation2[i] -= rotation2[i][j] * this.objectPoints[0][j];107 }108 }109 }110 111 return error1.euclidean < error2.euclidean?112 new POS.Pose(error1.pixels, rotation1, translation1, error2.pixels, rotation2, translation2):113 new POS.Pose(error2.pixels, rotation2, translation2, error1.pixels, rotation1, translation1);114};115POS.Posit.prototype.pos = function(imagePoints, rotation1, rotation2, translation){116 var np = this.objectPoints.length, imageVectors = [],117 i0 = [], j0 = [], ivec = [], jvec = [], row1 = [], row2 = [], row3 = [],118 i0i0, j0j0, i0j0, delta, q, lambda, mu, scale, i, j;119 120 for (i = 0; i < np; ++ i){121 imageVectors[i] = [imagePoints[i].x - imagePoints[0].x,122 imagePoints[i].y - imagePoints[0].y];123 }124 125 //i0 and j0126 for (i = 0; i < 3; ++ i){127 i0[i] = 0.0;128 j0[i] = 0.0;129 for (j = 0; j < np; ++ j){130 i0[i] += this.objectMatrix[i][j] * imageVectors[j][0];131 j0[i] += this.objectMatrix[i][j] * imageVectors[j][1];132 }133 }134 135 i0i0 = i0[0] * i0[0] + i0[1] * i0[1] + i0[2] * i0[2];136 j0j0 = j0[0] * j0[0] + j0[1] * j0[1] + j0[2] * j0[2];137 i0j0 = i0[0] * j0[0] + i0[1] * j0[1] + i0[2] * j0[2];138 139 //Lambda and mu140 delta = (j0j0 - i0i0) * (j0j0 - i0i0) + 4.0 * (i0j0 * i0j0);141 142 if (j0j0 - i0i0 >= 0.0){143 q = (j0j0 - i0i0 + Math.sqrt(delta) ) / 2.0;144 }else{145 q = (j0j0 - i0i0 - Math.sqrt(delta) ) / 2.0;146 }147 148 if (q >= 0.0){149 lambda = Math.sqrt(q);150 if (0.0 === lambda){151 mu = 0.0;152 }else{153 mu = -i0j0 / lambda;154 }155 }else{156 lambda = Math.sqrt( -(i0j0 * i0j0) / q);157 if (0.0 === lambda){158 mu = Math.sqrt(i0i0 - j0j0);159 }else{160 mu = -i0j0 / lambda;161 }162 }163 164 //First rotation165 for (i = 0; i < 3; ++ i){166 ivec[i] = i0[i] + lambda * this.objectNormal[i];167 jvec[i] = j0[i] + mu * this.objectNormal[i];168 }169 170 scale = Math.sqrt(ivec[0] * ivec[0] + ivec[1] * ivec[1] + ivec[2] * ivec[2]);171 172 for (i = 0; i < 3; ++ i){173 row1[i] = ivec[i] / scale;174 row2[i] = jvec[i] / scale;175 }176 177 row3[0] = row1[1] * row2[2] - row1[2] * row2[1];178 row3[1] = row1[2] * row2[0] - row1[0] * row2[2];179 row3[2] = row1[0] * row2[1] - row1[1] * row2[0];180 181 for (i = 0; i < 3; ++ i){182 rotation1[0][i] = row1[i];183 rotation1[1][i] = row2[i];184 rotation1[2][i] = row3[i];185 }186 187 //Second rotation188 for (i = 0; i < 3; ++ i){189 ivec[i] = i0[i] - lambda * this.objectNormal[i];190 jvec[i] = j0[i] - mu * this.objectNormal[i];191 }192 193 for (i = 0; i < 3; ++ i){194 row1[i] = ivec[i] / scale;195 row2[i] = jvec[i] / scale;196 }197 198 row3[0] = row1[1] * row2[2] - row1[2] * row2[1];199 row3[1] = row1[2] * row2[0] - row1[0] * row2[2];200 row3[2] = row1[0] * row2[1] - row1[1] * row2[0];201 202 for (i = 0; i < 3; ++ i){203 rotation2[0][i] = row1[i];204 rotation2[1][i] = row2[i];205 rotation2[2][i] = row3[i];206 }207 208 //Translation209 translation[0] = imagePoints[0].x / scale;210 translation[1] = imagePoints[0].y / scale;211 translation[2] = this.focalLength / scale;212};213POS.Posit.prototype.isValid = function(rotation, translation){214 var np = this.objectPoints.length, zmin = Infinity, i = 0, zi;215 216 for (; i < np; ++ i){217 zi = translation[2] +218 (rotation[2][0] * this.objectVectors[i][0] +219 rotation[2][1] * this.objectVectors[i][1] +220 rotation[2][2] * this.objectVectors[i][2]221 );222 if (zi < zmin){223 zmin = zi;224 }225 }226 227 return zmin >= 0.0;228};229POS.Posit.prototype.iterate = function(imagePoints, posRotation, posTranslation, rotation, translation){230 var np = this.objectPoints.length,231 oldSopImagePoints = [], sopImagePoints = [],232 rotation1 = [[],[],[]], rotation2 = [[],[],[]],233 translation1 = [], translation2 = [],234 converged = false, iteration = 0,235 oldImageDifference, imageDifference, factor,236 error, error1, error2, delta, i, j;237 238 for (i = 0; i < np; ++ i){239 oldSopImagePoints[i] = {x: imagePoints[i].x,240 y: imagePoints[i].y241 };242 }243 244 for (i = 0; i < 3; ++ i){245 for (j = 0; j < 3; ++ j){246 rotation[i][j] = posRotation[i][j];247 }248 translation[i] = posTranslation[i];249 }250 251 for (i = 0; i < np; ++ i){252 factor = 0.0;253 for (j = 0; j < 3; ++ j){254 factor += this.objectVectors[i][j] * rotation[2][j] / translation[2];255 }256 sopImagePoints[i] = {x: (1.0 + factor) * imagePoints[i].x,257 y: (1.0 + factor) * imagePoints[i].y258 };259 }260 261 imageDifference = 0.0;262 263 for (i = 0; i < np; ++ i){264 imageDifference += Math.abs(sopImagePoints[i].x - oldSopImagePoints[i].x);265 imageDifference += Math.abs(sopImagePoints[i].y - oldSopImagePoints[i].y);266 }267 268 for (i = 0; i < 3; ++ i){269 translation1[i] = translation[i] -270 (rotation[i][0] * this.objectPoints[0][0] +271 rotation[i][1] * this.objectPoints[0][1] +272 rotation[i][2] * this.objectPoints[0][2]273 );274 }275 276 error = error1 = this.error(imagePoints, rotation, translation1);277 278 //Convergence279 converged = (0.0 === error1.pixels) || (imageDifference < 0.01);280 281 while( iteration ++ < 100 && !converged ){282 283 for (i = 0; i < np; ++ i){284 oldSopImagePoints[i].x = sopImagePoints[i].x;285 oldSopImagePoints[i].y = sopImagePoints[i].y;286 }287 288 this.pos(sopImagePoints, rotation1, rotation2, translation);289 290 for (i = 0; i < 3; ++ i){291 translation1[i] = translation[i] -292 (rotation1[i][0] * this.objectPoints[0][0] +293 rotation1[i][1] * this.objectPoints[0][1] +294 rotation1[i][2] * this.objectPoints[0][2]295 );296 297 translation2[i] = translation[i] -298 (rotation2[i][0] * this.objectPoints[0][0] +299 rotation2[i][1] * this.objectPoints[0][1] +300 rotation2[i][2] * this.objectPoints[0][2]301 );302 }303 304 error1 = this.error(imagePoints, rotation1, translation1);305 error2 = this.error(imagePoints, rotation2, translation2);306 307 if ( (error1.euclidean >= 0.0) && (error2.euclidean >= 0.0) ){308 if (error2.euclidean < error1.euclidean){309 error = error2;310 for (i = 0; i < 3; ++ i){311 for (j = 0; j < 3; ++ j){312 rotation[i][j] = rotation2[i][j];313 }314 }315 }else{316 error = error1;317 for (i = 0; i < 3; ++ i){318 for (j = 0; j < 3; ++ j){319 rotation[i][j] = rotation1[i][j];320 }321 }322 }323 }324 325 if ( (error1.euclidean < 0.0) && (error2.euclidean >= 0.0) ){326 error = error2;327 for (i = 0; i < 3; ++ i){328 for (j = 0; j < 3; ++ j){329 rotation[i][j] = rotation2[i][j];330 }331 }332 }333 334 if ( (error2.euclidean < 0.0) && (error1.euclidean >= 0.0) ){335 error = error1;336 for (i = 0; i < 3; ++ i){337 for (j = 0; j < 3; ++ j){338 rotation[i][j] = rotation1[i][j];339 }340 }341 }342 343 for (i = 0; i < np; ++ i){344 factor = 0.0;345 for (j = 0; j < 3; ++ j){346 factor += this.objectVectors[i][j] * rotation[2][j] / translation[2];347 }348 sopImagePoints[i].x = (1.0 + factor) * imagePoints[i].x;349 sopImagePoints[i].y = (1.0 + factor) * imagePoints[i].y;350 }351 352 oldImageDifference = imageDifference;353 imageDifference = 0.0;354 355 for (i = 0; i < np; ++ i){356 imageDifference += Math.abs(sopImagePoints[i].x - oldSopImagePoints[i].x);357 imageDifference += Math.abs(sopImagePoints[i].y - oldSopImagePoints[i].y);358 }359 360 delta = Math.abs(imageDifference - oldImageDifference);361 362 converged = (0.0 === error.pixels) || (delta < 0.01);363 }364 365 return error;366};367POS.Posit.prototype.error = function(imagePoints, rotation, translation){368 var np = this.objectPoints.length,369 move = [], projection = [], errorvec = [],370 euclidean = 0.0, pixels = 0.0, maximum = 0.0,371 i, j, k;372 373 if ( !this.isValid(rotation, translation) ){374 return {euclidean: -1.0, pixels: -1, maximum: -1.0};375 }376 377 for (i = 0; i < np; ++ i){378 move[i] = [];379 for (j = 0; j < 3; ++ j){380 move[i][j] = translation[j];381 }382 }383 384 for (i = 0; i < np; ++ i){385 for (j = 0; j < 3; ++ j){386 for (k = 0; k < 3; ++ k){387 move[i][j] += rotation[j][k] * this.objectPoints[i][k];388 }389 }390 }391 392 for (i = 0; i < np; ++ i){393 projection[i] = [];394 for (j = 0; j < 2; ++ j){395 projection[i][j] = this.focalLength * move[i][j] / move[i][2];396 }397 }398 399 for (i = 0; i < np; ++ i){400 errorvec[i] = [projection[i][0] - imagePoints[i].x,401 projection[i][1] - imagePoints[i].y];402 }403 404 for (i = 0; i < np; ++ i){405 euclidean += Math.sqrt(errorvec[i][0] * errorvec[i][0] +406 errorvec[i][1] * errorvec[i][1]407 );408 409 pixels += Math.abs( Math.round(projection[i][0]) - Math.round(imagePoints[i].x) ) +410 Math.abs( Math.round(projection[i][1]) - Math.round(imagePoints[i].y) );411 412 if (Math.abs(errorvec[i][0]) > maximum){413 maximum = Math.abs(errorvec[i][0]);414 }415 if (Math.abs(errorvec[i][1]) > maximum){416 maximum = Math.abs(errorvec[i][1]);417 }418 }419 420 return {euclidean: euclidean / np, pixels: pixels, maximum: maximum};421};422POS.pseudoInverse = function(a, n, b){423 var w = [], v = [[],[],[]], s = [[],[],[]],424 wmax = 0.0, cn = 0,425 i, j, k;426 427 SVD.svdcmp(a, n, 3, w, v);428 429 for (i = 0; i < 3; ++ i){430 if (w[i] > wmax){431 wmax = w[i];432 }433 }434 435 wmax *= 0.01;436 437 for (i = 0; i < 3; ++ i){438 if (w[i] < wmax){439 w[i] = 0.0;440 }441 }442 443 for (j = 0; j < 3; ++ j){444 if (0.0 === w[j]){445 ++ cn;446 for (k = j; k < 2; ++ k){447 for (i = 0; i < n; ++ i){448 a[i][k] = a[i][k + 1];449 }450 for (i = 0; i < 3; ++ i){451 v[i][k] = v[i][k + 1];452 }453 }454 }455 }456 457 for (j = 0; j < 2; ++ j){458 if (0.0 === w[j]){459 w[j] = w[j + 1];460 }461 }462 463 for (i = 0; i < 3; ++ i){464 for (j = 0; j < 3 - cn; ++ j){465 s[i][j] = v[i][j] / w[j];466 }467 }468 469 for (i = 0; i < 3; ++ i){470 for (j = 0; j < n; ++ j){471 b[i][j] = 0.0;472 for (k = 0; k < 3 - cn; ++ k){473 b[i][j] += s[i][k] * a[j][k];474 }475 }476 }477};478POS.Pose = function(error1, rotation1, translation1, error2, rotation2, translation2){479 this.bestError = error1;480 this.bestRotation = rotation1;481 this.bestTranslation = translation1;482 this.alternativeError = error2;483 this.alternativeRotation = rotation2;484 this.alternativeTranslation = translation2;...

Full Screen

Full Screen

css.js

Source:css.js Github

copy

Full Screen

1const express = require("express");2const Css = require("../models/Css");3const User = require("../models/User");4const verifyAdmin = require("./verifyAdmin");5const verifyToken = require("./verifyToken");6const { upload } = require("../s3");7const router = express.Router();8// Get all levels9router.get("/", async (req, res) => {10 try {11 const levels = await Css.find(12 req.query.level ? { level: req.query.level } : {}13 );14 res.json(req.query.level ? levels[0] || {} : levels);15 } catch (err) {16 res.json({ message: err });17 }18});19// Get single level by id20router.get("/:levelId", async (req, res) => {21 try {22 const level = await Css.findById(req.params.levelId);23 res.json(level);24 } catch (err) {25 res.json({ message: err });26 }27});28// Create level - if logged in - if admin29router.post(30 "/",31 upload.single("image"),32 verifyToken(),33 verifyAdmin,34 async (req, res) => {35 const levels = await Css.find();36 console.log("File: ", req.file);37 const level = new Css({38 name: req.body.name,39 code: req.body.code,40 colors: JSON.parse(req.body.colors),41 level: levels.length + 1,42 solutionImage: req.file.location,43 });44 try {45 const savedLevel = await level.save();46 res.json(savedLevel);47 } catch (err) {48 res.json({ message: err });49 }50 }51);52// Delete level - if logged in53router.delete("/:levelId", verifyToken(), verifyAdmin, async (req, res) => {54 try {55 const removedLevel = await Css.deleteOne({ _id: req.params.levelId });56 res.json(removedLevel);57 } catch (err) {58 res.json({ message: err });59 }60});61// Update level - if logged in62router.patch("/:levelId", verifyToken(), verifyAdmin, async (req, res) => {63 try {64 const updatedLevel = await Css.updateOne(65 { _id: req.params.levelId },66 {67 $set: {68 name: req.body.name,69 code: req.body.code,70 colors: req.body.colors,71 },72 }73 );74 res.json(updatedLevel);75 } catch (err) {76 res.json({ message: err });77 }78});79const Jimp = require("jimp");80var multer = require("multer");81var uploadd = multer();82// Submit level - if logged in83router.post(84 "/:levelId/submit",85 uploadd.single("image"),86 verifyToken(true),87 async (req, res) => {88 try {89 const level = await Css.findById(req.params.levelId);90 const solutionImage = await Jimp.read(level.solutionImage);91 const submitedImage = await Jimp.read(req.file.buffer);92 const imageDifference = Jimp.diff(submitedImage, solutionImage).percent;93 const codeLength = req.body.code.length;94 const totalScore = Number(95 (codeLength / (imageDifference <= 0 ? 0.01 : imageDifference)).toFixed(96 297 )98 );99 if (req.user) {100 const user = await User.findById(req.user?._id);101 var highestScore = totalScore;102 const playedGame = user.played.find(103 (game) => game.game.toString() === level._id.toString()104 );105 if (typeof playedGame !== "undefined") {106 if (totalScore > playedGame.highestScore)107 playedGame.highestScore = totalScore;108 else highestScore = playedGame.highestScore;109 } else {110 user.played.push({111 game: level._id,112 highestScore: totalScore,113 isLevel: true,114 });115 }116 if (imageDifference <= 0) {117 user.levelsPassed =118 user.levelsPassed < level.level ? level.level : user.levelsPassed;119 }120 await user.save();121 res.json({122 success: 1,123 message: "Level passed",124 data: {125 score: totalScore,126 codeLength,127 imageDifference,128 highestScore,129 },130 user,131 });132 } else {133 res.json({134 success: 1,135 message: "Level passed",136 data: {137 score: totalScore,138 codeLength,139 imageDifference,140 },141 });142 }143 } catch (err) {144 res.json({ message: err });145 }146 }147);...

Full Screen

Full Screen

imageDifference.test.js

Source:imageDifference.test.js Github

copy

Full Screen

1import path from 'path'2import imageDifference from './imageDifference'3describe('imageDifference', () => {4 it('simple', async () => {5 const result = await imageDifference({6 compareScreenshotPath: path.join(__dirname, '__fixtures__/simple/compare.png'),7 baseScreenshotPath: path.join(__dirname, '__fixtures__/simple/base.png'),8 diffResultPath: path.join(__dirname, '__fixtures__/simple/diff_tmp.png'),9 })10 expect(result.score > 0).toBe(true)11 expect(result).toMatchSnapshot()12 })13 it('simple with enough fuzz', async () => {14 const result = await imageDifference({15 compareScreenshotPath: path.join(__dirname, '__fixtures__/simple/compare.png'),16 baseScreenshotPath: path.join(__dirname, '__fixtures__/simple/base.png'),17 diffResultPath: path.join(__dirname, '__fixtures__/simple/diff_tmp.png'),18 fuzz: 70 ** 2,19 })20 expect(result.score).toBe(0)21 expect(result).toMatchSnapshot()22 })23 it('alphaBackground', async () => {24 const result = await imageDifference({25 compareScreenshotPath: path.join(__dirname, '__fixtures__/alphaBackground/compare.png'),26 baseScreenshotPath: path.join(__dirname, '__fixtures__/alphaBackground/base.png'),27 diffResultPath: path.join(__dirname, '__fixtures__/alphaBackground/diff_tmp.png'),28 })29 expect(result.score).toBe(0)30 expect(result).toMatchSnapshot()31 })32 it('boxShadow', async () => {33 const result = await imageDifference({34 compareScreenshotPath: path.join(__dirname, '__fixtures__/boxShadow/compare.png'),35 baseScreenshotPath: path.join(__dirname, '__fixtures__/boxShadow/base.png'),36 diffResultPath: path.join(__dirname, '__fixtures__/boxShadow/diff_tmp.png'),37 })38 expect(result.score).toBe(0)39 expect(result).toMatchSnapshot()40 })41 it('border', async () => {42 const result = await imageDifference({43 compareScreenshotPath: path.join(__dirname, '__fixtures__/border/compare.png'),44 baseScreenshotPath: path.join(__dirname, '__fixtures__/border/base.png'),45 diffResultPath: path.join(__dirname, '__fixtures__/border/diff_tmp.png'),46 })47 expect(result.score).toBe(0)48 expect(result).toMatchSnapshot()49 })50 it('fontAliasing', async () => {51 const result = await imageDifference({52 compareScreenshotPath: path.join(__dirname, '__fixtures__/fontAliasing/compare.png'),53 baseScreenshotPath: path.join(__dirname, '__fixtures__/fontAliasing/base.png'),54 diffResultPath: path.join(__dirname, '__fixtures__/fontAliasing/diff_tmp.png'),55 })56 expect(result).toMatchSnapshot()57 })58 it('imageCompression', async () => {59 const result = await imageDifference({60 compareScreenshotPath: path.join(__dirname, '__fixtures__/imageCompression/compare.png'),61 baseScreenshotPath: path.join(__dirname, '__fixtures__/imageCompression/base.png'),62 diffResultPath: path.join(__dirname, '__fixtures__/imageCompression/diff_tmp.png'),63 })64 expect(result.score).toBe(0)65 expect(result).toMatchSnapshot()66 })67 it('imageCompression2', async () => {68 const result = await imageDifference({69 compareScreenshotPath: path.join(__dirname, '__fixtures__/imageCompression2/compare.png'),70 baseScreenshotPath: path.join(__dirname, '__fixtures__/imageCompression2/base.png'),71 diffResultPath: path.join(__dirname, '__fixtures__/imageCompression2/diff_tmp.png'),72 })73 expect(result).toMatchSnapshot()74 })75 it('imageCompression3', async () => {76 const result = await imageDifference({77 compareScreenshotPath: path.join(__dirname, '__fixtures__/imageCompression3/compare.png'),78 baseScreenshotPath: path.join(__dirname, '__fixtures__/imageCompression3/base.png'),79 diffResultPath: path.join(__dirname, '__fixtures__/imageCompression3/diff_tmp.png'),80 })81 expect(result).toMatchSnapshot()82 })...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos');2var fs = require('fs');3var image1 = fs.readFileSync('image1.png');4var image2 = fs.readFileSync('image2.png');5argos.imageDifference(image1, image2, function(err, result) {6 if (!err) {7 console.log(result);8 } else {9 console.log(err);10 }11});12{ isDifferent: true, difference: 0.0010000000474974513 }13var argos = require('argos');14var fs = require('fs');15var image1 = fs.readFileSync('image1.png');16var image2 = fs.readFileSync('image2.png');17argos.imageSimilarity(image1, image2, function(err, result) {18 if (!err) {19 console.log(result);20 } else {21 console.log(err);22 }23});24{ similarity: 0.9989999532699585 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos');2var image1Path = 'image1.jpg';3var image2Path = 'image2.jpg';4argos.imageDifference(image1Path, image2Path, function(err, result) {5 if(err) {6 } else {7 }8});9var argos = require('argos');10var image1Path = 'image1.jpg';11var image2Path = 'image2.jpg';12argos.imageDifference(image1Path, image2Path, function(err, result) {13 if(err) {14 } else {15 }16});17var argos = require('argos');18var image1Path = 'image1.jpg';19var image2Path = 'image2.jpg';20argos.imageDifference(image1Path, image2Path, function(err, result) {21 if(err) {22 } else {23 }24});25var argos = require('argos');26var image1Path = 'image1.jpg';27var image2Path = 'image2.jpg';28argos.imageDifference(image1Path, image2Path, function(err, result) {29 if(err) {30 } else {31 }32});33var argos = require('argos');34var image1Path = 'image1.jpg';35var image2Path = 'image2.jpg';36argos.imageDifference(image1Path, image2Path, function(err, result) {37 if(err) {38 } else {39 }40});41var argos = require('argos');42var image1Path = 'image1.jpg';

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos');2var imageDiff = new argos.ImageDifference();3var image1 = 'image1.png';4var image2 = 'image2.png';5imageDiff.imageDifference(image1, image2, function(err, result) {6 if (err) {7 console.log('Error: ', err);8 } else {9 console.log('Image Difference: ', result);10 }11});12var argos = require('argos');13var imageDiff = new argos.ImageDifference();14var image1 = 'image1.png';15var image2 = 'image2.png';16imageDiff.imageSimilarity(image1, image2, function(err, result) {17 if (err) {18 console.log('Error: ', err);19 } else {20 console.log('Image Similarity: ', result);21 }22});23var argos = require('argos');24var imageDiff = new argos.ImageDifference();25var image1 = 'image1.png';26var image2 = 'image2.png';27imageDiff.imageSimilarity(image1, image2, function(err, result) {28 if (err) {29 console.log('Error: ', err);30 } else {31 console.log('Image Similarity: ', result);32 }33});34var argos = require('argos');35var imageDiff = new argos.ImageDifference();36var image1 = 'image1.png';37var image2 = 'image2.png';38imageDiff.imageSimilarity(image1, image2, function(err, result) {39 if (err) {40 console.log('Error: ', err);41 } else {42 console.log('Image Similarity: ', result);43 }44});45var argos = require('argos');46var imageDiff = new argos.ImageDifference();47var image1 = 'image1.png';48var image2 = 'image2.png';49imageDiff.imageSimilarity(image1, image2, function(err, result) {50 if (err) {51 console.log('Error: ', err);

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos');2var imageOne = 'image1.png';3var imageTwo = 'image2.png';4var threshold = 0.9;5argos.imageDifference(imageOne, imageTwo, threshold, function(err, result) {6 if (err) {7 console.log('Error: ' + err);8 } else {9 console.log('Result: ' + result);10 }11});12var result = argos.syncImageDifference(imageOne, imageTwo, threshold);13console.log('Result: ' + result);14The MIT License (MIT)15Copyright (c) 2014-2015 Daniel Lobo

Full Screen

Using AI Code Generation

copy

Full Screen

1var imageDiff = require('argos').imageDifference;2var img1 = 'img1.png';3var img2 = 'img2.png';4imageDiff(img1, img2, function(err, diff) {5 if (err) {6 console.log(err);7 } else {8 console.log(diff);9 }10});11var imageDiff = require('argos').imageDifference;12var img1 = 'img1.png';13var img2 = 'img2.png';14imageDiff(img1, img2)15 .then(function(diff) {16 console.log(diff);17 })18 .catch(function(err) {19 console.log(err);20 });

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos');2var img1 = argos.image('image1.png');3var img2 = argos.image('image2.png');4img1.imageDifference(img2, function(err, result) {5 if (err) {6 console.log(err);7 } else {8 console.log('Difference: ' + result);9 }10});11var argos = require('argos');12var img1 = argos.image('image1.png');13var img2 = argos.image('image2.png');14img1.imageDifference(img2, function(err, result) {15 if (err) {16 console.log(err);17 } else {18 console.log('Difference: ' + result);19 }20});21var argos = require('argos');22var img1 = argos.image('image1.png');23var img2 = argos.image('image2.png');24img1.imageDifference(img2, function(err, result) {25 if (err) {26 console.log(err);27 } else {28 console.log('Difference: ' + result);29 }30});31var argos = require('argos');32var img1 = argos.image('image1.png');33var img2 = argos.image('image2.png');34img1.imageDifference(img2, function(err, result) {35 if (err) {36 console.log(err);37 } else {38 console.log('Difference: ' + result);39 }40});41var argos = require('argos');42var img1 = argos.image('image1.png');43var img2 = argos.image('image2.png');44img1.imageDifference(img2, function(err, result) {45 if (err) {46 console.log(err);47 } else {48 console.log('Difference: ' + result);49 }50});51var argos = require('argos');52var img1 = argos.image('image1.png');53var img2 = argos.image('image2.png');

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos-cli');2argos.imageDifference(image1, image2, function(err, res) {3 console.log(res);4});5var argos = require('argos-cli');6argos.imageDifference(image1, image2, function(err, res) {7 console.log(res);8});9var argos = require('argos-cli');10argos.imageDifference(image1, image2, function(err, res) {11 console.log(res);12});13var argos = require('argos-cli');14argos.imageDifference(image1, image2, function(err, res) {15 console.log(res);16});17var argos = require('argos-cli');18argos.imageDifference(image1, image2, function(err, res) {19 console.log(res);20});21var argos = require('argos-cli');

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run argos automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful