Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   Camera Vision Processing (http://www.chiefdelphi.com/forums/showthread.php?t=102242)

2869Robotics 08-02-2012 00:09

Camera Vision Processing
 
Hi,

in my code i have
Code:

public void operatorControl(){
  while(isenabled() && isOperatorControl()){

        ColorImage img = Camera.getImage();
          .....and then i do a bunch of processing after i get the image.

  }
}

How do I get the camera to only take a picture 5 times per second? Doesn't the loop repeat like once every 10ms? So wouldn't that mean that the code I have now would take a picture once every 10ms?

dbeckwith 08-02-2012 09:44

Re: Camera Vision Processing
 
You can't rely on the loop being executed every 10ms, it's bound to change as you put in more code (especially image processing). If you wanted to do something every 200ms, you might do something like this:
Code:

import edu.wpi.first.wpilibj.Timer;

public void operatorControl() {
  double time = Timer.getFPGATimestamp();
 
  while(isEnabled() && isOperatorControl()) {
    if (Timer.getFPGATimestamp() - time >= 0.2) {
      // CAMERA IMAGE PROCESSING HERE
      time = Timer.getFPGATimestamp();
    }
    // OTHER CODE HERE
  }
}


jesusrambo 08-02-2012 19:05

Re: Camera Vision Processing
 
You might try running the image capture in a separate thread. I've had sketchy luck with threads and FRC Java, but your mileage may vary.

IisMathwizard 10-02-2012 07:18

Re: Camera Vision Processing
 
Like what jesusrambo said, running in a seperate thread might actually be a good idea... (Thanks rambo! ill try it). I don't think that overhead would be a problem as long you aren't using a seperate thread for each motor or something unsynchronized as that... If you need help on image tracking ill be more than happy to help. I haven't used the javacv that everyone seems to be raving about but with the image processing functions tat FRC gave us i was able to successfully track imagery.

2869Robotics 10-02-2012 12:19

Re: Camera Vision Processing
 
Im not sure what you guys mean by running it in a seperate thread

Patrick Chiang 10-02-2012 15:18

Re: Camera Vision Processing
 
1 Attachment(s)
Quote:

Originally Posted by 2869Robotics (Post 1123732)
Im not sure what you guys mean by running it in a seperate thread

Having a separate thread makes it so that your code won't be stuck on some piece of code until it finishes running. It makes it so that it can run multiple pieces of code (technically no on the low level, but for all practical purposes yes).

If you don't stick a piece of particularly long running loop in a thread (say, one that deliberately waits for 5 seconds before it finishes executing), the rest of your program will get stuck on it, and your other code, like your drive/shoot code will stop executing until the 5 seconds is done.

Read this piece of documentation on how you can implement this in Java: http://docs.oracle.com/javase/tutori...l/concurrency/


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

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