Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检测与诊断;从Java BuffereImage中删除一系列颜色_Java_Ocr_Tesseract_Bufferedimage - Fatal编程技术网

检测与诊断;从Java BuffereImage中删除一系列颜色

检测与诊断;从Java BuffereImage中删除一系列颜色,java,ocr,tesseract,bufferedimage,Java,Ocr,Tesseract,Bufferedimage,我正在构建一个应用程序,它使用OCR从图像中读取文本(使用Tesser4j读取Google的Tesseract),但我想忽略棕色文本,只读取灰色文本 例如,在下图中,我只想读“Ricki”,而忽略“AOA”。 为了做到这一点,我认为在执行OCR之前从图像中删除棕褐色是我最好的选择 /* Remove RGB Value for Group Tag */ int width = image.getWidth(); int height = image.getHeight(

我正在构建一个应用程序,它使用OCR从图像中读取文本(使用Tesser4j读取Google的Tesseract),但我想忽略棕色文本,只读取灰色文本

例如,在下图中,我只想读“Ricki”,而忽略“AOA”。

为了做到这一点,我认为在执行OCR之前从图像中删除棕褐色是我最好的选择

    /* Remove RGB Value for Group Tag */
    int width = image.getWidth();
    int height = image.getHeight();
    int[] pixels = new int[width * height];
    image.getRGB(0, 0, width, height, pixels, 0, width);
    for (int i = 0; i < pixels.length; i++) {
        //If pixel is between dark-tan value and light-tan value
        if (pixels[i] > 0xFF57513b && pixels[i] < 0xFF6b6145)  {
            // Set pixel to black
            System.out.println("pixel found");
            pixels[i] = 0xFF000000;
        }
    }
    image.setRGB(0, 0, width, height, pixels, 0, width);
/*删除组标记的RGB值*/
int width=image.getWidth();
int height=image.getHeight();
int[]像素=新int[宽度*高度];
getRGB(0,0,宽度,高度,像素,0,宽度);
对于(int i=0;i0xFF57513b和像素[i]<0xFF6b6145){
//将像素设置为黑色
System.out.println(“找到像素”);
像素[i]=0xFF000000;
}
}
setRGB(0,0,宽度,高度,像素,0,宽度);

但这段代码也删除了几乎所有的灰色文本。您不能像我这样简单地比较十六进制颜色值和一系列值。有没有其他方法可以检测一系列颜色?还是用一种更好的不同方法来解决这个问题?

哈拉尔德通过提到转换RGB为我指明了正确的方向。通过位移位从十六进制值中获取单独的r、g和b int值,我可以比较一个范围内的颜色,并从图像中消除一个范围内的颜色

int baser = 108; //base red 
int baseg = 96;  //base green
int baseb = 68;  //base blue
int range = 10;  //threshold + and - from base values

/* Set all pixels within +- range of base RGB to black */
for (int i = 0; i < pixels.length; i++) {
        int a = (pixels[i]>>24)     &0xFF; //alpha
        int r = (pixels[i]>>16)     &0xFF; //red
        int g = (pixels[i]>>8)      &0xFF; //green
        int b = (pixels[i]>>0)      &0xFF; //blue

        if ( (r > baser-range && r < baser+range) && 
             (g > baseg-range && g < baseg+range) && 
             (b > baseb-range && b < baseb+range) ) {
                pixels[i] = 0xFF000000; //Set to black
        }
}
intbaser=108//底红
int-baseg=96//底绿
int-baseb=68//浅蓝色
int范围=10//阈值+和-自基值
/*将基本RGB+范围内的所有像素设置为黑色*/
对于(int i=0;i>24)&0xFF;//α
int r=(像素[i]>>16)&0xFF;//红色
int g=(像素[i]>>8)&0xFF;//绿色
int b=(像素[i]>>0)&0xFF;//蓝色
如果((r>baser范围和&rbaseg范围和gbaseb范围和&b
为什么不将其分解为各个组件?更好的方法是,将RGB值转换为HSV,并基于色调组件进行比较。@gpasch按各个组件表示各个颜色?问题在于,单个用户名中的每个像素都有大量不同的十六进制RGB值,即使这些值在其他4个用户名中也不一致。