ColorFinder.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:Auto.js 作者:
public static Point[] findAllColors(ImageWrapper image, int color, int threshold, Rect rect) {
    Mat bi = new Mat();
    Scalar lowerBound = new Scalar(Color.red(color) - threshold, Color.green(color) - threshold,
            Color.blue(color) - threshold, 255);
    Scalar upperBound = new Scalar(Color.red(color) + threshold, Color.green(color) + threshold,
            Color.blue(color) + threshold, 255);
    if (rect != null) {
        Core.inRange(new Mat(image.getMat(), rect), lowerBound, upperBound, bi);
    } else {
        Core.inRange(image.getMat(), lowerBound, upperBound, bi);
    }
    Mat nonZeroPos = new Mat();
    Core.findNonZero(bi, nonZeroPos);
    if (nonZeroPos.rows() == 0 || nonZeroPos.cols() == 0) {
        return new Point[0];
    }
    Point[] points = new MatOfPoint(nonZeroPos).toArray();
    if (rect != null) {
        for (int i = 0; i < points.length; i++) {
            points[i].x += rect.x;
            points[i].y += rect.y;
        }
    }
    return points;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号