如何识别/计算重叠图像中有多少个对象

时间:2019-07-08 07:33:59

标签: java eclipse image-processing computer-vision detection

问题是我正在尝试从无人机图像中识别植物。图像中的植物包含重叠,并且具有不同的形状/大小。我不确定该在哪里寻找或使用哪种类型的方法,并正在寻找建议。

我从完整的字段图像中提取了一些片段,并尝试:使用Convolusion神经网络训练Java程序中使用的xml文件,使用3x3惊厥矩阵,例如锐化和边缘检测(特别针对Sobel)和Laplace),通过获取其RGB值并变灰其他所有植物来识别每棵植物。我将精力集中在识别它们各自的RGB值的第三种方法上,但是由于所有这些RGB值都不同,因此这很困难。

这是我用来扫描和删除不相关的RGB值的当前代码: 我只存储红色和蓝色是因为有趣的是,植物的绿色值和背景的绿色值实际上几乎相同。
以下是该字段的图像: enter image description here

我还有其他一些到目前为止我尝试过的方法的图片: The result of using sobel operator

//important data

int pixX = 330; //resolution of image
int pixY = 370;
int pixT = pixX * pixY; //total amount of pixels

int xloc = 0;//used to locate pixels to remove
int yloc = 0;
File test = new File("FILE.png)
int x = 0, y = 0; //Current XY values
int colorsplit[][] = new int[2][pixT];//obtaining red and blue will be stored in this 2d array

try {
        for (int c = 0; c < pixT - 1; c=c+2) { //I use C+2 to jump 2 pixels to make the process faster

BufferedImage image = ImageIO.read(test);//buffered image read

int clr = image.getRGB(x, y); //getting values as binary(? i think)
int red = (clr & 0x00ff0000) >> 16; //bit shifting for red values
    int blue = clr & 0x000000ff; //Blue values

for (int n = 0; n < 4; n++) { // this is used to store values so that a single run will store the same value twice for 2 pixels side by side (efficiency measures)

switch (n) {//switch to store Red Blue codes
case 0:
            colorsplit[0][c] = red;//store
    break;
case 1:
        colorsplit[1][c] = blue;//store
    break;

case 2:
    colorsplit[0][c + 1] = red;//store
    break;
case 3:
    colorsplit[1][c + 1] = blue;//store
        }

}//END switch
    x = x + 2;
if (x == pixX) {//Going up in XY values to cover all values
    x = 0;
    y++;
    }//end if
}//end for

     ...//end of try, catch IOException

for (int c = 0; c < pixT; c++) { //Starting to identify redundant pixels

    if (colorsplit[0][c] > 200 || colorsplit[1][c] > 100) { //parameters of redundant pixels

xloc = c % pixX;
yloc = c / pixX;//locating XY pixels

image.setRGB(xloc, yloc, 0); //Setting redundant pixels to black
System.out.println(xloc + "," + yloc + " setted"); //confirmation text

    }//end for
//end

我没有收到很多错误,但是问题更多出在程序无法按预期运行。

编辑:事实证明,大多数事情都很好,但是我没有做的一件事就是结合了多个识别程序。最终进行了RGB缩减,仅得到R值,然后进行Sobel运算符,然后使用逐像素分析来过滤出多余像素。

0 个答案:

没有答案