如何在java中测量肩膀,手臂的长度?

时间:2012-06-22 13:35:48

标签: java bluej

这是我的图片链接:

http://compsci.ca/v3/download.php?id=9165&sid=8b1ef1788c32286c495e956bc6cd2df3

我已经检测到身体上的白色绳子,并获得长度。我的问题是如何检测肩膀,然后测量肩膀和长度或手臂..请帮助我:(

这是我的工作。如果有任何更正,请这样做并建议我如何改进我的计划..

import java.io.*;

import java.awt.*;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;

import javax.swing.*;

import javax.swing.JOptionPane;


public class GetPixelColor
{
    private static int maxCnt;

    public static void main(String args[]) throws IOException
    {

        File file= new File("image.jpg");
        BufferedImage image = ImageIO.read(file);
        int array[][] = new int [300][400];


           for(int i=0; i<300; i++)
           {
               for(int j=0; j<400; j++)
               {
                   // Getting pixel color by position x=j and y=j
                   int clr=  image.getRGB(j,i); 
                   int  red   = (clr & 0x00ff0000) >> 16;
                   int  green = (clr & 0x0000ff00) >> 8;
                   int  blue  =  clr & 0x000000ff;

                  //System.out.println("..................................");
                  //System.out.println("Red Color value = "+ red);
                  //System.out.println("Green Color value = "+ green);
                  //System.out.println("Blue Color value = "+ blue);
                  //System.out.println("..................................");

                  if((red >= 160 && red <= 200) && (green >= 160 && green <= 190) && (blue >= 160 && blue <= 180))//cari kaler
                  {
                      //if(red > 160 && green > 160 && blue > 180)
                      // System.out.print("{"+j+"||"+i+"[0]}");
                          array[i][j] = 0;
                          System.out.print("0");
                        }
                        else
                        {
                            array[i][j] = 1;
                            System.out.print("-");
                        }
               }
               System.out.println();
            }

            System.out.println(array[0].length);
            System.out.println(array.length);
            int x2 = 0;
            int y2 = 0;
            for (int i = (400-1); i >= 0; i--)//
            {
                for(int j = (300-1); j >= 0; j--)
                {
                    System.out.print(array[j][i]);
                    if(array[j][i] == 0)
                    {
                        //System.out.print("position2 : x="+i+" y="+j);
                        x2 = i;
                        y2 = j;
                        i = -1;
                        break;

                    }
                }
                System.out.println();
            }
            JOptionPane.showMessageDialog(null,"coordinate : \n" + "x : " + x2 +"\n y : "+ y2);
            int x = 0;
            int y = 0;
            for (int i = 0; i <400; i++)
            {
                for(int j = 0; j < 300; j++)
                {
                    System.out.print(array[j][i]);
                    if(array[j][i] == 0)
                    {
                        //System.out.print("position1 : x="+i+" y="+j);
                        x = i;
                        y = j;
                        i = 400;
                        break;
                    }
                }
                System.out.println();
            }
            JOptionPane.showMessageDialog(null,"coordinate : \n" + "x : " +x+"\n y : "+y);

            double m = 0.0;

            m = Math.sqrt(Math.pow(y-y2,2) + Math.pow(x-x2,2));
            JOptionPane.showMessageDialog(null,"length of the string : "+m);
            double ratio = 0;
            ratio = m/10;
            JOptionPane.showMessageDialog(null,"ratio per inch : " + ratio);
        }

    }

1 个答案:

答案 0 :(得分:0)

您可以在肩膀上使用类似的标记作为正面的白色字符串。可能使用不同的颜色 - 这样可以更容易区分前面的白色标记。 一旦检测到肩部标记,就应该很容易计算出长度(类似于你对白色字符串所做的那样)。