【问题标题】:Reading Content of image or Image processing(Indoor Navigation) [duplicate]读取图像或图像处理的内容(室内导航)[重复]
【发布时间】:2015-09-15 21:20:57
【问题描述】:

我正在为我的项目制作一个小型室内导航应用程序。我的申请背后的主要想法是,我将获得某个区域的 .pdf 文件或 Autocad 文件(平面图)。我必须从该图像中解析或获取数据以找出平面图中的开放路径。 为了从图像中确定开放路径,我还必须在某些数据结构中映射图像内容或数据,以便我可以在其上应用一些寻路算法。 我的问题是我不知道如何将图像分解为像素或任何其他形式,以便在初始阶段从中获取数据。我是否需要使用 Matlab 应用一些图像处理,或者可以通过 Java 或 Python 库来实现?

【问题讨论】:

标签: java python image matlab


【解决方案1】:

这是一个相当广泛的问题,所以我只能就一些相关点给出提示。

  1. 如何在 java 中从图像中读取单个像素:

    BufferedImage bi = ImageIO.read(new File("pathToYourImage"));
    
    bi.getRGB(0 , 0);
    

    这样你可以在java中加载一个图像并获取单个像素的值(示例中为(0,0))。

  2. 数据结构:表示平面图或任何其他类型的路径集合的最常见方式是图形。网上有几个不错的图库,也可以自己实现。

  3. ImageProcessing:由于图像不会是黑白的(我猜),您必须对其进行转换才能将其转换为图形 - 尽管甚至不需要转换为图形。最常见的方法是简单地将图形转换为黑色像素为墙壁的黑白图像。由于代表地板的像素颜色可能不是完全相同的颜色,所以我在比较中添加了一些不精确(delta):

    //comparison function
    boolean isMatch(Color inp , Color toMatch)
    {
        final int delta = 25;
    
        return (Math.abs(inp.getRed() - toMatch.getRed()) <= delta &&
                Math.abs(inp.getBlue() - toMatch.getBlue()) <= delta &&
                Math.abs(inp.getGreen() - toMatch.getGreen()) <= delta);
    }
    
    //color of pixels that don't represent obstacles
    Color floor = getFloorColor();
    
    //create a copy of the image for the transformation
    BufferedImage floorPlan = new BufferedImage(getFloorPlan().getWidth() , 
                                    getFloorPlan().getHeight() , BufferedImage.TYPE_INT_RGB);
    
    floorPlan.getGraphics().drawImage(getFloorPlan() , 
                              floorPlan.getWidth() , floorPlan.getHeight() , null);
    
    //color pixels that aren't walls or other obstacles white and obstacles/walls black
    for(int i = 0 ; i < floorPlan.getWidth() ; i++)
        for(int j = 0 ; j < floorPlan.getHeight() ; j++)
            if(isMatch(new Color(floorPlan.getRGB(i , j)) , floor)
                floorPlan.setRGB(Color.WHITE.getRGB());
            else
                floorPlan.setRGB(Color.BLACK.getRGB());
    

    该图像现在可以很容易地转换为图形,或直接用作图形的表示。

【讨论】:

    猜你喜欢
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-11
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    相关资源
    最近更新 更多