Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.43 KB | None | 0 0
  1. package org.firstinspires.ftc.teamcode;
  2.  
  3. import android.graphics.Bitmap;
  4.  
  5. import com.vuforia.Frame;
  6. import com.vuforia.Image;
  7. import com.vuforia.PIXEL_FORMAT;
  8. import com.vuforia.State;
  9. import com.vuforia.Vuforia;
  10.  
  11. import org.firstinspires.ftc.robotcore.external.ClassFactory;
  12. import org.firstinspires.ftc.robotcore.external.navigation.VuforiaLocalizer;
  13.  
  14. public class BrightEyesInterface {
  15.     private static final String VUFORIA_KEY =
  16.          "AXvDB53/////AAABmU7XauHpH0aXjBLQcVVPpfk3omAEtqgcrofu3"
  17.          + "wNrglhxAHt9SK9X3W01Jb58Y7/fCw9JwLN2lflT2pJeMXS7Bakp"
  18.          + "79El2Et+fWdDHgQ5KcGceYIAQEENR6t9l1WkY8j0WVaIlcjOrPA"
  19.          + "zZv4/U/YpUvcB7QFoUO33u1L2iJKoKPuJm5eChTrjR2iacZLH28"
  20.          + "iriFGoRuQOfsBsgKK5InsJH1Xll9e8DZKhDBxBwGkfIlbqyv2LF"
  21.          + "KKe0v2J5azm2W0NRbJ8dnevHf90YbXoXJARxcmu5zCMYvFXhKRK"
  22.          + "6Si0W+Yqr7Gx8+Xd6wSwJ9LijMDBySi8hocf8Vl5ie2qmi22ty7"
  23.          + "J6KPh7CehD8H6qmxmst2r";
  24.  
  25.     private VuforiaLocalizer vuforia;
  26.  
  27.     /** Input image size of the model along x axis. */
  28.     private int imageSizeX;
  29.     /** Input image size of the model along y axis. */
  30.     private int imageSizeY;
  31.  
  32.     Image img = null;
  33.  
  34.     BrightEyesInterface() {
  35.  
  36.     }
  37.  
  38.     void init(int monitorViewId) {
  39.         // Init Vuforia
  40.         VuforiaLocalizer.Parameters parameters = new VuforiaLocalizer.Parameters(monitorViewId);
  41.  
  42.         parameters.vuforiaLicenseKey = VUFORIA_KEY;
  43.         parameters.cameraDirection = VuforiaLocalizer.CameraDirection.BACK;
  44.  
  45.         //  Instantiate the Vuforia engine
  46.         vuforia = ClassFactory.getInstance().createVuforia(parameters);
  47.  
  48.         Vuforia.setFrameFormat(PIXEL_FORMAT.RGB565, true); //enables RGB565 format for the image
  49.         vuforia.setFrameQueueCapacity(1); //tells VuforiaLocalizer to only store one frame at a time
  50.     }
  51.  
  52.     Bitmap getBitmap() throws InterruptedException {
  53.         VuforiaLocalizer.CloseableFrame f = vuforia.getFrameQueue().take(); //takes the frame at the head of the queue
  54.         long num = f.getNumImages();
  55.  
  56.         for (short i = 0; i < num; i++) {
  57.             if (f.getImage(i).getFormat() == PIXEL_FORMAT.RGB565) {
  58.                 img = f.getImage(i);
  59.             }
  60.         }
  61.         if (img != null) {
  62.             Bitmap bmp = Bitmap.createBitmap(img.getWidth(), img.getHeight(), Bitmap.Config.RGB_565);
  63.             bmp.copyPixelsFromBuffer(img.getPixels());
  64.             return bmp;
  65.         }
  66.         return null;
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement