用java实现屏幕找图

实现原理

  • 截取当前屏幕
  • 读取需要查找的图片
  • 抽取特征
  • 根据特征遍历屏幕找到符合特征的块
  • 把找到的特征块和图片进行精确对比

代码如下

  • 首先定义图片查找接口
        public interface ImageFinder {
   
        /**
         * 查询到匹配的图片
         * @param image 需要查找的图片
         * @return
         */
           List<Coordinate> match(BufferedImage image,double percent);
        }
  • 定义查找到的返回坐标
        public class Coordinate {
            private int x;
            private int y;

            public Coordinate(int x, int y) {
                this.x = x;
                this.y = y;
            }

            public int getX() {
                return x;
            }

            public void setX(int x) {
                this.x = x;
            }

            public int getY() {
                return y;
            }

            public void setY(int y) {
                this.y = y;
            }
        }
  • 特征类
            public class ColorBlock {
   
    int[][] rgbs;
    private int width;
    private int height;
    private Point leftTop;
    private Point rightTop;
    private Point leftBottom;
    private Point rightBottom;
    private Point center;
    private int count = 0;
    public ColorBlock(BufferedImage image){
        this.width = image.getWidth();
        this.height = image.getHeight();
        this.rgbs = new int[this.width][this.height];

        for(int x=0;x<this.width;x++){
            for(int y=0; y<this.height;y++){
                this.rgbs[x][y] = image.getRGB(x,y);
                count =
  • 8
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值