Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.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_Bufferedimage_Image Segmentation_Flood Fill - Fatal编程技术网

Java在BuffereImage上查找网格和泛洪填充

Java在BuffereImage上查找网格和泛洪填充,java,ocr,bufferedimage,image-segmentation,flood-fill,Java,Ocr,Bufferedimage,Image Segmentation,Flood Fill,我有一个问题,当我试图分割棋盘游戏与第一次尝试寻找网格和洪水填充。但是我卡住了,我把所有的像素从白变红,我不知道如何只填充网格,没有数字或其他,只填充网格线 我现在的成绩是这样的 我想这样填充 这段代码我使用了`boolean flood(buffereImage img,boolean[][]标记, boolean flood(BufferedImage img, boolean[][] mark, int row, int col,

我有一个问题,当我试图分割棋盘游戏与第一次尝试寻找网格和洪水填充。但是我卡住了,我把所有的像素从白变红,我不知道如何只填充网格,没有数字或其他,只填充网格线

我现在的成绩是这样的

我想这样填充

这段代码我使用了`
boolean flood(buffereImage img,boolean[][]标记,
boolean flood(BufferedImage img, boolean[][] mark,
                             int row, int col, Color srcColor, Color tgtColor) {

// make sure row and col are inside the image if (row < 0) return false; if (col < 0) return false; if (row >= img.getHeight()) return false; if (col >= img.getWidth()) return false; // make sure this pixel hasn't been visited yet if (mark[row][col]) return false; Color asli = new Color(img.getRGB(col, row)); // make sure this pixel is the right color to fill if (!asli.equals(srcColor)) return false; // fill pixel with target color and mark it as visited img.setRGB(col, row, tgtColor.getRGB()); mark[row][col] = true; // recursively fill surrounding pixels flood(img, mark, row - 1, col, srcColor, tgtColor); flood(img, mark, row + 1, col, srcColor, tgtColor); flood(img, mark, row, col - 1, srcColor, tgtColor); flood(img, mark, row, col + 1, srcColor, tgtColor); return true; } boolean[][] mark = new boolean[citra.getHeight()][citra.getWidth()]; for (int y = 0; y < citra.getHeight(); y++) { for (int x = 0; x < citra.getWidth(); x++) { Color warna = new Color(citra.getRGB(x, y)); if (warna.equals(Color.WHITE)){ flood(citra, mark, x, y, Color.WHITE, Color.RED); break; } } } imagebiner.setIcon(new ImageIcon(citra.getScaledInstance(300, 300, Image.SCALE_SMOOTH))); repaint();
int行、int列、颜色srcColor、颜色tgtColor){

//确保行和列位于图像内部 如果(行<0)返回false; 如果(col<0)返回false; if(row>=img.getHeight())返回false; 如果(col>=img.getWidth())返回false; //确保尚未访问此像素 if(标记[行][col])返回false; Color asli=新颜色(img.getRGB(列,行)); //确保此像素是要填充的正确颜色 如果(!asli.equals(srcColor))返回false; //用目标颜色填充像素并将其标记为已访问 setRGB(col,row,tgtColor.getRGB()); 标记[行][列]=真; //递归填充周围像素 泛光(img、标记、第1行、col、srcColor、tgtColor); 泛光(img、标记、行+1、列、srcColor、tgtColor); 泛光(img、mark、row、col-1、srcColor、tgtColor); 泛光(img、标记、行、列+1、srcColor、tgtColor); 返回true; } 布尔值[][]标记=新布尔值[citra.getHeight()][citra.getWidth()]; 对于(int y=0;y

我希望任何人都能为这样的问题找到解决方案。

这在很大程度上取决于您是否每次都使用相同的图像布局。如果提供的格式与示例图像中的格式相同,则任务是直接进行的:

  • 跟踪线路的位置(因为这些线路是静态的)
  • 在不改变颜色的情况下浏览整个图像
  • 保留大小为9 x 9的二维数组
    B
  • 如果您检测到一个数字(非源颜色),则将相应的
    B
    项标记为已获取
  • 在第一次通过后,仅在
    B
    数组中标记为未使用的行之间的颜色空间
如果图像大小和布局是动态的,那么您需要有一个额外的步骤(在上面的逻辑之前)来确定行的位置。这更为复杂,但也不过分:

  • 穿过整个图像,跟踪不同颜色的像素
  • 一旦有了这些,就可以通过比较X和Y值来确定直线。如果X增加,而Y相同,则有水平线。如果Y是静态的,而X在整个图像中递增,则有一条垂直线

  • 请考虑清楚你想要完成的是什么。图像很好,但仍然很难理解哪个部分在工作,哪个部分不工作。我只尝试填充网格或外部框,不填充数字或其他,但我不知道如何填充?我的紫玫瑰色是为了稍后找到线和角,但我必须先解决用其他颜色填充外盒的问题,我想@BC004346对不起,我不明白你的解释。我如何知道构成数字的像素?图像大小是一样的,因为我使用了重缩放,但布局是动态的。你能解释一下如何跟踪像素并用一些伪代码或示例填充网格吗。多谢各位@bc004346@VictorChandra您是否正在寻找一个完整的解决方案或帮助解决一个特定的小问题?上面的代码是您自己的吗?你明白了吗?是的,这是我自己的代码,我试着找到网格,将网格着色为红色,但我的问题是形成数字的像素和其他像素噪声也用红色填充。我的步骤是:首先我用阈值滑块将图像二值化为黑白,然后我跟踪像素,如果找到第一个白色像素,我使用函数floodfill将其填充为红色和邻域像素的递归。你明白我什么意思吗?我希望任何人都能帮我找到只填充网格的逻辑(分割盒子)@bc004346为什么图像会扭曲?你是在扫描页面上工作还是这是你屏幕上的照片?你是指拼图的源图像吗?这就是我在互联网上得到的图像,我尝试任何图像拼图,因为就像我在布局(图像拼图)是动态的之前所说的那样。我试图稍后识别要排列的拼图图像,但我现在的问题是分割长方体(填充网格以获得长方体的第一个像素和像素)@bc004346