Guest User

Untitled

a guest
May 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. package edu.wpi.first.wpilibj.templates;
  2.  
  3. import com.sun.cldc.jna.*;
  4. import edu.wpi.first.wpilibj.SimpleRobot;
  5. import edu.wpi.first.wpilibj.camera.*;
  6. import edu.wpi.first.wpilibj.image.*;
  7.  
  8. public class RobotTemplate extends SimpleRobot {
  9.     /**
  10.      * This function is called once each time the robot enters autonomous mode.
  11.      */
  12.    
  13.     AxisCamera camera;
  14.    
  15.     // STUFF FOR IMPORTING MORE IMAGE PROCESSING JUNK //
  16.     private static final TaskExecutor taskExecutor = new TaskExecutor("nivision task");
  17.    
  18.     private static final BlockingFunction imaqConvexHullFn = NativeLibrary.getDefaultInstance().getBlockingFunction("imaqConvexHull");
  19.     static { imaqConvexHullFn.setTaskExecutor(taskExecutor); }
  20.    
  21.     public static void convexHull(Pointer source, Pointer dest, int connectivity8)  throws NIVisionException{
  22.         assertCleanStatus(imaqConvexHullFn.call3(source.address().toUWord().toPrimitive(), dest.address().toUWord().toPrimitive(), connectivity8));
  23.     }
  24.    
  25.     private static final BlockingFunction imaqGetLastErrorFn = NativeLibrary.getDefaultInstance().getBlockingFunction("imaqGetLastError");
  26.     static { imaqGetLastErrorFn.setTaskExecutor(taskExecutor);  }
  27.  
  28.     public static int getLastError(){
  29.         return imaqGetLastErrorFn.call0();
  30.     }
  31.     protected static void assertCleanStatus (int code) throws NIVisionException {
  32.         if (code == 0) {
  33.             throw new NIVisionException(imaqGetLastErrorFn.call0());
  34.         }
  35.     }
  36.     /* ================= */
  37.    
  38.    
  39.    
  40.     public void autonomous() {
  41.         camera = AxisCamera.getInstance();
  42.         camera.writeResolution(AxisCamera.ResolutionT.k640x480);
  43.        
  44.         while(isAutonomous())
  45.         {
  46.             try {
  47.                 ColorImage img = camera.getImage();
  48.                
  49.                 // Do the threshold
  50.                 BinaryImage bImg = img.thresholdHSL(0, 255, 0, 20, 239, 255);
  51.                
  52.                 //Do convex hull (copy generated c++ code?)
  53.                 convexHull(bImg.image, bImg.image, 1);
  54.                
  55.                 for(int i = 0; i < bImg.getNumberParticles(); i++)
  56.                 {
  57.                     ParticleAnalysisReport report = bImg.getParticleAnalysisReport(i);
  58.                 }
  59.             } catch (AxisCameraException ex) {
  60.                 ex.printStackTrace();
  61.             } catch (NIVisionException ex) {
  62.                 ex.printStackTrace();
  63.             }
  64.         }
  65.     }
  66.    
  67.     public void operatorControl() {
  68.  
  69.     }
  70. }
Add Comment
Please, Sign In to add comment