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

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

Source:OpenCvUtils.java Github

copy

Full Screen

...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()) {192 return found;193 }194 int stepUp = collect(strictness, found, findAll, robot, source, target, 1.1);195 if (!found.isEmpty()) {196 return found;197 }198 int stepDown = collect(strictness, found, findAll, robot, source, target, 0.9);199 if (!found.isEmpty()) {200 return found;201 }202 boolean goUpFirst = stepUp < stepDown;203 for (int step = 2; step < 6; step++) {204 double scale = 1 + 0.1 * step * (goUpFirst ? 1 : -1);205 collect(strictness, found, findAll, robot, source, target, scale);206 }207 if (!findAll && !found.isEmpty()) {208 return found;209 }210 for (int step = 2; step < 6; step++) {211 double scale = 1 + 0.1 * step * (goUpFirst ? -1 : 1);212 collect(strictness, found, findAll, robot, source, target, scale);213 } 214 return found;215 }216 public static Mat loadAndShowOrExit(File file, int flags) {217 Mat image = read(file, flags);218 show(image, file.getName());219 return image;220 }221 public static BufferedImage readImageAsGreyScale(File file) {222 Mat mat = read(file, IMREAD_GRAYSCALE);223 return toBufferedImage(mat);224 }225 public static byte[] toBytes(BufferedImage img) {226 ByteArrayOutputStream baos = new ByteArrayOutputStream();227 try {228 ImageIO.write(img, "png", baos);229 return baos.toByteArray();230 } catch (Exception e) {231 throw new RuntimeException(e);232 }233 }234 public static Mat read(File file) {235 return read(file, IMREAD_GRAYSCALE);236 }237 public static Mat read(byte[] bytes) {238 return read(bytes, IMREAD_GRAYSCALE);239 }240 public static Mat read(byte[] bytes, int flags) {241 Mat image = imdecode(new Mat(bytes), flags);242 if (image.empty()) {243 throw new RuntimeException("image decode failed");244 }245 return image;246 }247 public static Mat read(File file, int flags) {248 Mat image = imread(file.getAbsolutePath(), flags);249 if (image.empty()) {250 throw new RuntimeException("image not found: " + file.getAbsolutePath());251 }252 return image;253 }254 public static File save(BufferedImage image, File file) {255 try {256 ImageIO.write(image, "png", file);257 return file;258 } catch (Exception e) {259 throw new RuntimeException(e);260 }261 }262 263 public static void show(byte[] bytes, String title) {264 Mat mat = read(bytes);265 show(toBufferedImage(mat), title);266 } 267 public static void show(Mat mat, String title) {268 show(toBufferedImage(mat), title);269 }270 public static void show(Image image, String title) {271 CanvasFrame canvas = new CanvasFrame(title, 1);272 canvas.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);273 canvas.showImage(image);274 }275 public static void save(Mat image, File file) {276 imwrite(file.getAbsolutePath(), image);277 }278 public static Mat drawOnImage(Mat image, Point2fVector points) {279 Mat dest = image.clone();280 int radius = 5;281 Scalar red = new Scalar(0, 0, 255, 0);282 for (int i = 0; i < points.size(); i++) {283 Point2f p = points.get(i);284 circle(dest, new Point(Math.round(p.x()), Math.round(p.y())), radius, red);285 }286 return dest;287 }288 public static Mat drawOnImage(Mat image, Rect overlay, Scalar color) {289 Mat dest = image.clone();290 rectangle(dest, overlay, color);291 return dest;292 }293 294 public static Mat negative(Mat src) {295 Mat dest = new Mat();296 bitwise_not(src, dest);297 return dest;298 }299 300 public static Mat toMat(BufferedImage bi) {301 return Java2DFrameUtils.toMat(bi);302 } ...

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import static com.intuit.karate.robot.OpenCvUtils.drawOnImage2import static com.intuit.karate.robot.OpenCvUtils.toBufferedImage3import static com.intuit.karate.robot.OpenCvUtils.toMat4import static com.intuit.karate.robot.OpenCvUtils.toMatOfPoint5import static com.intuit.karate.robot.OpenCvUtils.toMatOfPoint2f6import static com.intuit.karate.robot.OpenCvUtils.toMatOfPoint3f7import static com.intuit.karate.robot.OpenCvUtils.toMatOfRect8import static com.intuit.karate.robot.OpenCvUtils.toMatOfRect2d9import static com.intuit.karate.robot.OpenCvUtils.toMatOfRotatedRect10import static com.intuit.karate.robot.OpenCvUtils.toMatOfRotatedRect2d11import static com.intuit.karate.robot.OpenCvUtils.toMatOfScalar12import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize13import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize2d14import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize2f15import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize3d16import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize3f17import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize3i18import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize3l19import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize4f20import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize4i21import static com.intuit.karate.robot.OpenCvUtils.toMatOfSize4l22import static com.intuit.karate.robot.OpenCvUtils.toMatOfString23import static com.intuit.karate.robot.OpenCvUtils.toMatOfVec3f24import static com.intuit.karate.robot.OpenCvUtils.toMatOfVec4f25import static com.intuit.karate.robot.OpenCvUtils.toMatOfVec6f26import static com.intuit.karate.robot.OpenCvUtils.toMatOf

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.OpenCvUtils2import org.opencv.core.Core3import org.opencv.core.Mat4import org.opencv.imgcodecs.Imgcodecs5import org.opencv.imgproc.Imgproc6import org.opencv.core.Scalar7import org.opencv.core.Point8import org.opencv.core.Size9import org.opencv.core.Rect10import org.opencv.imgproc.Imgproc11import org.opencv.core.CvType12import org.opencv.core.MatOfPoint13 * def image = OpenCvUtils.loadImage('classpath:logo.png')14 * def imageWithCircle = OpenCvUtils.drawOnImage(image, 'circle', '10,10,10,255,5')15 * def imageWithRectangle = OpenCvUtils.drawOnImage(image, 'rectangle', '10,10,10,255,5')16 * def imageWithText = OpenCvUtils.drawOnImage(image, 'text', '10,10,10,255,5,Hello World')17 * def imageWithLine = OpenCvUtils.drawOnImage(image, 'line', '10,10,10,255,5,15,15')18 * def imageWithPolyLine = OpenCvUtils.drawOnImage(image, 'polyline', '10,10,10,255,5,15,15,20,20,25,25')19 * match imageWithCircle == OpenCvUtils.loadImage('classpath:logo_with_circle.png')20 * match imageWithRectangle == OpenCvUtils.loadImage('classpath:logo_with_rectangle.png')21 * match imageWithText == OpenCvUtils.loadImage('classpath:logo_with_text.png')22 * match imageWithLine == OpenCvUtils.loadImage('classpath:logo_with_line.png')23 * match imageWithPolyLine == OpenCvUtils.loadImage('classpath:logo_with_polyline.png')24 * def image = OpenCvUtils.loadImage('classpath:logo.png')

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import org.opencv.core.Point2import org.opencv.core.Scalar3import org.opencv.core.Size4import static com.intuit.karate.robot.OpenCvUtils.drawOnImage5* def image = read('classpath:sample.png')6* def point1 = new Point(20, 20)7* def point2 = new Point(100, 100)8* def color = new Scalar(0, 0, 255)9* def size = new Size(10, 10)10* def image1 = drawOnImage(image, point1, point2, color, thickness, lineType, shift)11* def image2 = drawOnImage(image, point1, size, color, thickness, lineType, shift)

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.OpenCvUtils2import org.opencv.core.Point3import org.opencv.core.Scalar4def image = OpenCvUtils.loadImage('classpath:karate-logo.png')5def output = OpenCvUtils.drawOnImage(image, { g ->6 g.setColor(Scalar.all(0))7 g.fillOval(new Point(50, 50), new Point(100, 100))8})9OpenCvUtils.saveImage(output, 'target/draw-on-image.jpg')10import com.intuit.karate.robot.OpenCvUtils11import org.opencv.core.Point12import org.opencv.core.Scalar13def image = OpenCvUtils.loadImage('classpath:karate-logo.png')14def output = OpenCvUtils.drawOnImage(image, { g ->15 g.setColor(Scalar.all(0))16 g.fillOval(new Point(50, 50), new Point(100, 100))17})18OpenCvUtils.saveImage(output, 'target/draw-on-image.jpg')19import com.intuit.karate.robot.OpenCvUtils20import org.opencv.core.Point21import org.opencv.core.Scalar22def image = OpenCvUtils.loadImage('classpath:karate-logo.png')23def output = OpenCvUtils.drawOnImage(image, { g ->24 g.setColor(Scalar.all(0))25 g.fillOval(new Point(50, 50), new Point(100, 100))26})27OpenCvUtils.saveImage(output, 'target/draw-on-image.jpg')28import com.intuit.karate.robot.OpenCvUtils29import org.opencv.core.Point30import org.opencv.core.Scalar31def image = OpenCvUtils.loadImage('classpath:karate-logo.png')32def output = OpenCvUtils.drawOnImage(image, { g ->

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.OpenCvUtils2def image = OpenCvUtils.loadImage('classpath:karate-logo.png')3def rect = OpenCvUtils.drawOnImage(image, [0, 0, 100, 100], [255, 0, 0])4OpenCvUtils.saveImage(rect, 'target/rect.png')5import com.intuit.karate.robot.OpenCvUtils6def image = OpenCvUtils.loadImage('classpath:karate-logo.png')7def text = OpenCvUtils.drawOnImage(image, 'hello world', [255, 0, 0])8OpenCvUtils.saveImage(text, 'target/text.png')9import com.intuit.karate.robot.OpenCvUtils10def image = OpenCvUtils.loadImage('classpath:karate-logo.png')11def line = OpenCvUtils.drawOnImage(image, [0, 0, 100, 100], [255, 0, 0], 2)12OpenCvUtils.saveImage(line, 'target/line.png')13import com.intuit.kar

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import static com.intuit.karate.robot.OpenCvUtils.drawOnImage2Given def image = read('classpath:sample.jpg')3And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])4Then match imageWithRect == read('classpath:sample-with-rect.jpg')5import static com.intuit.karate.robot.OpenCvUtils.drawOnImage6Given def image = read('classpath:sample.jpg')7And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])8Then match imageWithRect == read('classpath:sample-with-rect.jpg')9Given def image = read('classpath:sample.jpg')10And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])11Then match imageWithRect == read('classpath:sample-with-rect.jpg')12import static com.intuit.karate.robot.OpenCvUtils.drawOnImage13Given def image = read('classpath:sample.jpg')14And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])15Then match imageWithRect == read('classpath:sample-with-rect.jpg')16Given def image = read('classpath:sample.jpg')17And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])18Then match imageWithRect == read('classpath:sample-with-rect.jpg')19Given def image = read('classpath:sample.jpg')20And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])21Then match imageWithRect == read('classpath:sample-with-rect.jpg')22Given def image = read('classpath:sample.jpg')23And def imageWithRect = drawOnImage(image, 10, 10, 100, 100, 'rect', [255, 0, 0])

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1* def image = read('classpath:logo.png')2* def imageBytes = drawOnImage(image, 'rectangle', 10, 10, 100, 100, 3, 0, 0, 255)3* def image = imageBytesToMat(imageBytes)4* def image = resize(image, 300, 300)5* def image = toBufferedImage(image)6* match image == read('classpath:logo-rectangle.png')

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1import com.intuit.karate.robot.OpenCvUtils2import com.intuit.karate.robot.OpenCvUtils.*3def result = drawOnImage(image, logo, 10, 10, 0.5)4def result = drawOnImage(image, logo, 10, 10, 0.5, 0.5)5def result = drawOnImage(image, logo, 10, 10, 0.5, 0.5, 0.5)6def result = drawOnImage(image, logo, 10, 10, 0.5, 0.5, 0.5, 0.5)7def result = drawOnImage(image, logo, 10, 10, 0.5, 0.5, 0.5, 0.5, 0.5)8def result = drawOnImage(image, logo, 10, 10, 0.5, 0.5, 0

Full Screen

Full Screen

drawOnImage

Using AI Code Generation

copy

Full Screen

1def image = OpenCvUtils.loadImage('src/test/resources/robot/image.png')2def imageWithRect = OpenCvUtils.drawOnImage(image, rect, color, thickness)3OpenCvUtils.saveImage(imageWithRect, 'target/image-with-rect.png')4 * def image = OpenCvUtils.loadImage('src/test/resources/robot/image.png')5 * def imageWithRect = OpenCvUtils.drawOnImage(image, rect, color, thickness)6 * OpenCvUtils.saveImage(imageWith

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