Thread: Camera Code
View Single Post
  #1   Spotlight this post!  
Unread 25-01-2011, 20:17
jimmyqwerty jimmyqwerty is offline
Registered User
FRC #0068
 
Join Date: May 2010
Location: Michigan
Posts: 10
jimmyqwerty is an unknown quantity at this point
Camera Code

So I worked out some camera code and it is able to tell me the coordinates of the target when it is present, but when the target isn't present it is supposed to display on the dashboard that their is no target. This does not happen because once it finds the target it will say found target and that field never gets reset on the driverstation. so my question is how can you get the dashboard to say no target present.

Here is my sample code.


Code:
public void Camera()
    {
            cam.freshImage();
         try
            {
              ColorImage image = cam.getImage();
              try
              {
                BinaryImage firstColor = image.thresholdRGB(
                120, 160, 170, 210, 240, 260);
                ParticleAnalysisReport[] firstColorHits = firstColor.getOrderedParticleAnalysisReports(3);
                firstColor.free();

                for (int i = 0; i < firstColorHits.length; i++)
                {
                   ParticleAnalysisReport firstTrackReport = firstColorHits[i];
                   if (firstTrackReport.particleToImagePercent < FRC_PARTICLE_TO_IMAGE_PERCENT)
                   {
                       
                       imagepres = false;
                      
                      
                   }
                   else if(firstTrackReport.particleToImagePercent > FRC_PARTICLE_TO_IMAGE_PERCENT)
                   {
                       imagepres = true;
                       foundhorcenter = firstTrackReport.center_mass_x;
                       foundvertcenter = firstTrackReport.center_mass_y; 
                   }
                   if (imagepres == true)
                   {

                       display.println(DriverStationLCD.Line.kUser2, 1, "X coordinate " + Integer.toString(foundhorcenter));
                       display.println(DriverStationLCD.Line.kUser3, 1, "Y coordinate: " + Integer.toString(foundvertcenter));
                       display.println(DriverStationLCD.Line.kUser4, 1, "Target found");
                       display.updateLCD();
                    }
               else 
               {
                   display.updateLCD();
                   display.println(DriverStationLCD.Line.kUser2, 1, "X coordinate na");
                   display.println(DriverStationLCD.Line.kUser3, 1, "Y coordinate: na");
                   display.println(DriverStationLCD.Line.kUser4, 1, "no image");

               }
                }
              }
              catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (image != null) {
                    image.free();
                }
                image = null;
            }
            }
            catch (AxisCameraException e)
            {
            }
            catch (NIVisionException e)
            {
            }
        }
Thanks for your help
Reply With Quote