How to use getPointsBelowThreshold method of com.intuit.karate.robot.OpenCvUtils class

Best Karate code snippet using com.intuit.karate.robot.OpenCvUtils.getPointsBelowThreshold

Source:OpenCvUtils.java Github

copy

Full Screen

...91 return resized;92 }93 private static final int TARGET_MINVAL_FACTOR = 150; // magic number, lower is stricter94 private static final int BLOCK_SIZE = 5;95 private static List<int[]> getPointsBelowThreshold(Mat src, double threshold) {96 Mat dst = new Mat();97 threshold(src, dst, threshold, 1, CV_THRESH_BINARY_INV);98 Mat non = new Mat();99 findNonZero(dst, non);100 int len = (int) non.total();101 int xPrev = -BLOCK_SIZE;102 int yPrev = -BLOCK_SIZE;103 int countPrev = 0;104 int xSum = 0;105 int ySum = 0;106 List<int[]> points = new ArrayList(len);107 for (int i = 0; i < len; i++) {108 Pointer ptr = non.ptr(i);109 Point p = new Point(ptr);110 int x = p.x();111 int y = p.y();112 int xDelta = Math.abs(x - xPrev);113 int yDelta = Math.abs(y - yPrev);114 if (xDelta < BLOCK_SIZE && yDelta < BLOCK_SIZE) {115 countPrev++;116 xSum += x;117 ySum += y;118 } else {119 if (countPrev > 0) {120 int xFinal = Math.floorDiv(xSum, countPrev);121 int yFinal = Math.floorDiv(ySum, countPrev);122 // logger.debug("end: {}:{}", xFinal, yFinal);123 points.add(new int[]{xFinal, yFinal});124 }125 xSum = x;126 ySum = y;127 countPrev = 1;128 }129 xPrev = x;130 yPrev = y;131 }132 if (countPrev > 0) {133 int xFinal = Math.floorDiv(xSum, countPrev);134 int yFinal = Math.floorDiv(ySum, countPrev);135 points.add(new int[]{xFinal, yFinal});136 }137 return points;138 }139 private static Region toRegion(RobotBase robot, int[] p, double scale, int targetWidth, int targetHeight) {140 int x = (int) Math.round(p[0] / scale);141 int y = (int) Math.round(p[1] / scale);142 int width = (int) Math.round(targetWidth / scale);143 int height = (int) Math.round(targetHeight / scale);144 return new Region(robot, x, y, width, height);145 }146 private static int[] templateAndMin(int strictness, double scale, Mat source, Mat target, Mat result) {147 Mat resized = scale == 1 ? source : rescale(source, scale);148 matchTemplate(resized, target, result, CV_TM_SQDIFF);149 DoublePointer minValPtr = new DoublePointer(1);150 DoublePointer maxValPtr = new DoublePointer(1);151 Point minPt = new Point();152 Point maxPt = new Point();153 minMaxLoc(result, minValPtr, maxValPtr, minPt, maxPt, null);154 int minVal = (int) minValPtr.get();155 int x = minPt.x();156 int y = minPt.y();157 return new int[]{x, y, minVal};158 }159 private static int collect(int strictness, List<Region> found, boolean findAll, RobotBase robot, Mat source, Mat target, double scale) {160 int targetWidth = target.cols();161 int targetHeight = target.rows();162 int targetMinVal = targetWidth * targetHeight * TARGET_MINVAL_FACTOR * strictness; 163 Mat result = new Mat();164 int[] minData = templateAndMin(strictness, scale, source, target, result);165 int minValue = minData[2];166 if (minValue > targetMinVal) {167 logger.debug("no match at scale {}, minVal: {} / {} at {}:{}", scale, minValue, targetMinVal, minData[0], minData[1]);168 if (robot != null && robot.debug) {169 Rect rect = new Rect(minData[0], minData[1], targetWidth, targetHeight);170 Mat temp = drawOnImage(source, rect, Scalar.RED);171 show(temp, scale + " " + minData[0] + ":" + minData[1] + " " + minValue + " / " + targetMinVal);172 }173 return minData[2];174 }175 logger.debug("found match at scale {}, minVal: {} / {} at {}:{}", scale, minValue, targetMinVal, minData[0], minData[1]);176 if (findAll) {177 List<int[]> points = getPointsBelowThreshold(result, targetMinVal);178 for (int[] p : points) {179 Region region = toRegion(robot, p, scale, targetWidth, targetHeight);180 found.add(region);181 }182 } else {183 Region region = toRegion(robot, minData, scale, targetWidth, targetHeight);184 found.add(region);185 }186 return minValue;187 }188 public static List<Region> find(int strictness, boolean findAll, RobotBase robot, Mat source, Mat target, boolean resize) {189 List<Region> found = new ArrayList();190 collect(strictness, found, findAll, robot, source, target, 1);191 if (!found.isEmpty()) {...

Full Screen

Full Screen

getPointsBelowThreshold

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.OpenCvUtils2import java.awt.image.BufferedImage3import java.io.File4import javax.imageio.ImageIO5import java.awt.Color6import java.awt.Graphics2D7import java.awt.BasicStroke8import java.awt.Font9def image = ImageIO.read(new File('src/test/resources/opencv/opencv1.jpg'))10def points = OpenCvUtils.getPointsBelowThreshold(image, threshold)11def g = image.createGraphics()12g.setStroke(new BasicStroke(2))13g.setPaint(Color.red)14g.setFont(new Font('Arial Black', Font.BOLD, 20))15points.eachWithIndex{ point, index ->16 g.drawString(index.toString(), point.x, point.y)17 g.drawOval(point.x - 10, point.y - 10, 20, 20)18}19ImageIO.write(image, 'jpg', new File('target/opencv1.jpg'))20import com.intuit.karate.robot.OpenCvUtils21import java.awt.image.BufferedImage22import java.io.File23import javax.imageio.ImageIO24import java.awt.Color25import java.awt.Graphics2D26import java.awt.BasicStroke27import java.awt.Font28def image = ImageIO.read(new File('src/test/resources/opencv/opencv2.jpg'))29def points = OpenCvUtils.getPointsBelowThreshold(image, threshold)30def g = image.createGraphics()31g.setStroke(new BasicStroke(2))32g.setPaint(Color.red)33g.setFont(new Font('Arial Black', Font.BOLD, 20))34points.eachWithIndex{ point, index ->35 g.drawString(index.toString(), point.x, point.y)36 g.drawOval(point.x - 10, point.y - 10, 20, 20)37}38ImageIO.write(image, 'jpg', new File('target/opencv2.jpg'))39import com.intuit.karate.robot.OpenCvUtils40import java.awt.image.BufferedImage41import java.io.File42import javax.imageio.ImageIO43import java.awt.Color44import java.awt.Graphics2D45import java.awt.BasicStroke46import java.awt.Font47def image = ImageIO.read(new File('

Full Screen

Full Screen

getPointsBelowThreshold

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.OpenCvUtils2import org.opencv.core.Mat3import org.opencv.core.Point4def pointsBelowThreshold = OpenCvUtils.getPointsBelowThreshold(image, threshold)5def message = "There are " + pointsBelowThreshold.size() + " points below threshold " + threshold6log(message)7def pointsBelowThresholdAsString = pointsBelowThreshold.collect { Point point -> point.toString() }.join("\r8log(pointsBelowThresholdAsString)9* def pointsBelowThresholdAsString = pointsBelowThreshold.collect { Point point -> point.toString() }.join("\r10* log(pointsBelowThresholdAsString)11* def message = "There are " + pointsBelowThreshold.size() + " points below threshold " + threshold12* log(message)13* def pointsBelowThreshold = OpenCvUtils.getPointsBelowThreshold(image, threshold)14* def message = "There are " + pointsBelowThreshold.size() + " points below threshold " + threshold15* log(message)16* def pointsBelowThresholdAsString = pointsBelowThreshold.collect { Point point -> point.toString() }.join("\r17* log(pointsBelowThresholdAsString)18* def pointsBelowThreshold = OpenCvUtils.getPointsBelowThreshold(image, threshold)19* def message = "There are " + pointsBelowThreshold.size() + " points below threshold " + threshold20* log(message)21* def pointsBelowThresholdAsString = pointsBelowThreshold.collect { Point point -> point.toString() }.join("\r22* log(pointsBelowThresholdAsString)

Full Screen

Full Screen

getPointsBelowThreshold

Using AI Code Generation

copy

Full Screen

1def points = OpenCvUtils.getPointsBelowThreshold(image, threshold, maxPoints)2def points = OpenCvUtils.removePointsWithinRadius(image, points, radius)3def circleCenter = OpenCvUtils.findCircleCenter(image, threshold, minRadius, maxRadius)4def rectangleCenter = OpenCvUtils.findRectangleCenter(image, threshold, minArea, maxArea)5def triangleCenter = OpenCvUtils.findTriangleCenter(image, threshold, minArea, maxArea)6def squareCenter = OpenCvUtils.findSquareCenter(image, threshold, minArea, maxArea)7def pentagonCenter = OpenCvUtils.findPentagonCenter(image, threshold, minArea, maxArea)8def hexagonCenter = OpenCvUtils.findHexagonCenter(image, threshold, minArea, maxArea)9def starCenter = OpenCvUtils.findStarCenter(image, threshold, minArea, maxArea)

Full Screen

Full Screen

getPointsBelowThreshold

Using AI Code Generation

copy

Full Screen

1* def image = read('classpath:opencv/gradient.png')2* def gray = com.intuit.karate.robot.OpenCvUtils.toGray(image)3* def points = com.intuit.karate.robot.OpenCvUtils.getPointsBelowThreshold(gray, threshold)4* def image = read('classpath:opencv/gradient.png')5* def gray = com.intuit.karate.robot.OpenCvUtils.toGray(image)6* def points = com.intuit.karate.robot.OpenCvUtils.getPointsBelowThreshold(gray, threshold)7* fileChooser.sendKeys('C:\\Users\\abc\\Desktop\\test.xlsx')8* fileChooser.click()9* driver.switchTo().activeElement().sendKeys('C:\\Users\\abc\\Desktop\\test.xlsx')

Full Screen

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 Karate 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