Go to Post What's the reason for having a rule if it's not enforced? - jpsaul7usa [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 06-02-2012, 18:56
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Camera Tracking Problems...

With this code we get an image from the camera but we have an issue with trying to get the camera to track and print out the results, any ideas? thanks.
Code:
package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.DriverStationLCD;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.camera.AxisCamera;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.image.*;
import edu.wpi.first.wpilibj.templates.commands.CommandBase;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class RobotTemplate extends IterativeRobot {

    
    AxisCamera camera;
    BinaryImage sensorimage;
    CriteriaCollection cc;
    
    public void robotInit() {
        String camip = "10.29.77.11";
        camera = AxisCamera.getInstance(camip);
        camera.writeResolution(AxisCamera.ResolutionT.k640x480);
        camera.writeRotation(AxisCamera.RotationT.k180);
        cc = new CriteriaCollection();      // create the criteria for the particle filter
        cc.addCriteria(NIVision.MeasurementType.IMAQ_MT_BOUNDING_RECT_WIDTH, 30, 400, false);
        cc.addCriteria(NIVision.MeasurementType.IMAQ_MT_BOUNDING_RECT_HEIGHT, 40, 400, false);
        
        while (true) {
           
           
            try {
                ColorImage image;                           // next 2 lines read image from flash on cRIO
                image =  new RGBImage("/10ft2.jpg");
                BinaryImage thresholdImage = image.thresholdRGB(0, 0, 0, 0, 0, 0);   // keep only black objects
                BinaryImage bigObjectsImage = thresholdImage.removeSmallObjects(false, 2);  // remove small artifacts
                BinaryImage convexHullImage = bigObjectsImage.convexHull(false);          // fill in occluded rectangles
                BinaryImage filteredImage = convexHullImage.particleFilter(cc);           // find filled in rectangles
                
                ParticleAnalysisReport[] reports = filteredImage.getOrderedParticleAnalysisReports();  // get list of results
                for (int i = 0; i < reports.length; i++) {                                // print results
                    ParticleAnalysisReport r = reports[i];
                    System.out.println("Particle: " + i + ":  Center of mass x: " + r.center_mass_x);
                   
                DriverStationLCD.getInstance().println(DriverStationLCD.Line.kMain6, 1, "Particle: " + i + ":  Center of mass x: " + r.center_mass_x);
                DriverStationLCD.getInstance().updateLCD();
                
                }
                System.out.println(filteredImage.getNumberParticles() + "  " + Timer.getFPGATimestamp());

                DriverStationLCD.getInstance().println(DriverStationLCD.Line.kMain6, 1, filteredImage.getNumberParticles() + "  " + Timer.getFPGATimestamp());
                DriverStationLCD.getInstance().updateLCD();
                
                /**
                 * all images in Java must be freed after they are used since they are allocated out
                 * of C data structures. Not calling free() will cause the memory to accumulate over
                 * each pass of this loop.
                 */
                filteredImage.free();
                convexHullImage.free();
                bigObjectsImage.free();
                thresholdImage.free();
                image.free();

                
                } catch (NIVisionException ex) {
                } 
        }
                                
                
   
            // freeing the image. A.K.A. letting the image go so we can have more images
            
        
                //sensorimage = camera.getImage();
         
        
        CommandBase.init();
    }
    
    public void autonomousInit() {
        // schedule the autonomous command (example)
        //autonomousCommand.start();
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
        Scheduler.getInstance().run();
    }

    public void teleopInit() {
		// This makes sure that the autonomous stops running when
		// teleop starts running. If you want the autonomous to 
		// continue until interrupted by another command, remove
		// this line or comment it out.
		//autonomousCommand.cancel();
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        Scheduler.getInstance().run();
    }
}
Reply With Quote
  #2   Spotlight this post!  
Unread 06-02-2012, 20:03
xmendude217 xmendude217 is offline
Registered User
FRC #3851
 
Join Date: Jan 2011
Location: Canoga Park, California 91303
Posts: 7
xmendude217 is an unknown quantity at this point
Re: Camera Tracking Problems...

I think the problem with this code is the threshold. If you have the NI Vision Assistant, put the image in that program and then mess with threshold values. Once you have that down, plug those numbers back into the program and that should do it
Reply With Quote
  #3   Spotlight this post!  
Unread 06-02-2012, 21:52
severhale severhale is offline
Registered User
FRC #4097
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Northampton, MA
Posts: 10
severhale is an unknown quantity at this point
Re: Camera Tracking Problems...

Is this copied directly from the demo program with a few modifications? Also what errors are you getting and where?
Reply With Quote
  #4   Spotlight this post!  
Unread 06-02-2012, 22:06
nonamedude nonamedude is offline
Registered User
FRC #1815
 
Join Date: Nov 2011
Location: Canada
Posts: 10
nonamedude is an unknown quantity at this point
Re: Camera Tracking Problems...

ColorImage image; // next 2 lines read image from flash on cRIO
image = new RGBImage("/10ft2.jpg");

You are reading the image from the crio, so you probably didnt upload the image to it. There were two lines after this code that allowed you to read it from the camera. Try setting the image to the one read from the camera and see what happens.
Reply With Quote
  #5   Spotlight this post!  
Unread 07-02-2012, 16:54
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Re: Camera Tracking Problems...

Quote:
Originally Posted by nonamedude View Post
ColorImage image; // next 2 lines read image from flash on cRIO
image = new RGBImage("/10ft2.jpg");

You are reading the image from the crio, so you probably didnt upload the image to it. There were two lines after this code that allowed you to read it from the camera. Try setting the image to the one read from the camera and see what happens.
Thanks for the heads up, we should have seen this. we just changed code to read from the camera, like you told us to. we're going to go test it as soon as we are able.

@severhale yes we did copy this from the demo program and made some modifications and are not getting any errors accordingly.
@xmendude217 we did check the thresholds, and they are correct for what we need.
Reply With Quote
  #6   Spotlight this post!  
Unread 08-02-2012, 16:25
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Re: Camera Tracking Problems...

Our camera is not taking the code... we get an unfiltered image to the driver station, and the camera doesn't seem to have any problems.. it's imaged correctly apparently, but it's not responding to changes in resolution or rotation code, or anything of the sorts.
Reply With Quote
  #7   Spotlight this post!  
Unread 09-02-2012, 00:04
nickpeq nickpeq is offline
Turing-complete
FRC #1255 (Blarglefish)
Team Role: Programmer
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Baytown, TX
Posts: 60
nickpeq is an unknown quantity at this point
Re: Camera Tracking Problems...

The dashboard image is not affected by certain things like resolution changes. And you will not see the filtered images unless you save them to the cRIO.
Reply With Quote
  #8   Spotlight this post!  
Unread 09-02-2012, 00:19
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Camera Tracking Problems...

I would be inclined to agree with xmendude that your problem most likely lies in your thresholding. Setting 0s for all values would, yes, detect black objects, but only perfectly black objects with absolutely no color at all. My bet is as soon as you have any light at all in the image the values would no longer be 0 for R, G, and B.

Out of curiosity, what's your setup that you find it viable to look for only perfectly black objects?
Reply With Quote
  #9   Spotlight this post!  
Unread 09-02-2012, 01:33
jviolette123 jviolette123 is offline
Registered User
FRC #1318
 
Join Date: Feb 2012
Location: Issaquah, WA
Posts: 10
jviolette123 is on a distinguished road
Re: Camera Tracking Problems...

We have a procedure for determining the distortion for your camera, using JavaCV. See this thread http://chiefdelphi.com/forums/showthread.php?t=101753

Our answer was xc= x*(1 -0.055*r^2 ), and yx = y*(1 - 0.55*r^2), where r is the distance from the center of the image, and x,y is the pixel location from the center of the image. This number is for the Axis 1011 camera.

You may use this value either during photo processing or after you get your points, depending on the image processing load you can support.

Other calibration techniques exist; this is just the one we used.
Reply With Quote
  #10   Spotlight this post!  
Unread 09-02-2012, 17:47
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Re: Camera Tracking Problems...

Quote:
Originally Posted by nickpeq View Post
The dashboard image is not affected by certain things like resolution changes. And you will not see the filtered images unless you save them to the cRIO.
alright, how de we get the image saved to our rio, and then display the image on our dashboard.

@jesusrambo We are setting up for perfectly black objects because of the black tape around our targets because they are black, if we were to compensate for luminosity where would we set that?

@jviolette123 we will take that into account.

thank you for your time, we will post again if we have more problems.
Reply With Quote
  #11   Spotlight this post!  
Unread 10-02-2012, 00:55
jesusrambo jesusrambo is offline
Self-Proclaimed Programmer Messiah
AKA: JD Russo
FRC #2035 (Robo Rockin' Bots)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2010
Location: Carmel, CA
Posts: 114
jesusrambo is an unknown quantity at this point
Re: Camera Tracking Problems...

Yes the tape is black, but with ambient light and all and with the quality of the cameras I'd be somewhat surprised if it was black enough to be all 0s.

A better solution might be to check out HSL for your thresholding.
Reply With Quote
  #12   Spotlight this post!  
Unread 10-02-2012, 21:13
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Camera Tracking Problems...

I'd actually be surprised if the sensor returns zeros even in the dark. Sensors are noisy.

Greg McKaskle
Reply With Quote
  #13   Spotlight this post!  
Unread 11-02-2012, 11:05
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Re: Camera Tracking Problems...

we are still having issues with the code, we have set it with a larger threshold to account luminosity and color gradient. can you give us a direct way to save the image to the rio and then to export it to the dashboard so we can see it? thanks.
Reply With Quote
  #14   Spotlight this post!  
Unread 11-02-2012, 13:28
Patrick Chiang Patrick Chiang is offline
Programming
FRC #3070 (Team Pronto)
Team Role: Mentor
 
Join Date: Feb 2009
Rookie Year: 2009
Location: Seattle
Posts: 162
Patrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to allPatrick Chiang is a name known to all
Re: Camera Tracking Problems...

Quote:
Originally Posted by Bennett View Post
we are still having issues with the code, we have set it with a larger threshold to account luminosity and color gradient. can you give us a direct way to save the image to the rio and then to export it to the dashboard so we can see it? thanks.
Someone else already answered that :

Quote:
Originally Posted by xmendude217 View Post
I think the problem with this code is the threshold. If you have the NI Vision Assistant, put the image in that program and then mess with threshold values. Once you have that down, plug those numbers back into the program and that should do it
Reply With Quote
  #15   Spotlight this post!  
Unread 18-02-2012, 11:24
Bennett Bennett is offline
Registered User
FRC #2977 (Sir Lancer Bots)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Minnesota
Posts: 26
Bennett is an unknown quantity at this point
Re: Camera Tracking Problems...

We have set our code to write the images the camera has retrieved and filtered. After the camera's fresh image is returned, all of them return black, any ideas what caused this? thanks

Last edited by Bennett : 18-02-2012 at 11:28.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:53.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi