@Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {

                // OPENCV ACTIONS here:
                // setting image resource from drawable via bitmap
                Bitmap b_input = BitmapFactory.decodeResource(resources, R_drawable_left07);
                Bitmap b_output = BitmapFactory.decodeResource(resources, R_drawable_left08);

                b_output = imgtrafo(b_input, b_output, 216, 70, 421, 108, 305, 447, 120, 354);
                // b_output = canny(b_input);

                // saveImageToInternalStorage(b_output, "bild1.png");

                Bitmap b_read = readImageFromInternalStorage("bild1.png");

                ImageView imageView = (ImageView) findViewById(R_id_imageView1);
                imageView.setImageBitmap(b_read);
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                if (D) Log.i(TAG, "OpenCV loaded successfully");

                mOpenCvCameraView.enableView();

                Handler postHandler = new Handler();
                postHandler.postDelayed(
                    new Runnable() {
                      @Override
                      public void run() {
                        // TODO Auto-generated method stub
                        mMatchImageUtil.loadCachedFiles();
                        mProgressDialog.dismiss();
                      }
                    },
                    50);
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
 @Override
 public void onManagerConnected(int status) {
   switch (status) {
     case LoaderCallbackInterface.SUCCESS:
       {
         Log.i("loading opCV", "OpenCV loaded successfully");
       }
       break;
     default:
       {
         super.onManagerConnected(status);
       }
       break;
   }
 }
 @Override
 public void onManagerConnected(int status) {
   switch (status) {
     case LoaderCallbackInterface.SUCCESS:
       {
         //          mOpenCvCameraView.enableView();
       }
       break;
     default:
       {
         super.onManagerConnected(status);
       }
       break;
   }
 }
Esempio n. 5
0
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                Log.i(TAG, "OpenCV loaded successfully");
                /*
                //Ce qui suit concerne la reconnaissance d'objet, à commenter si non souhaité
                try {
                    // On charge le fichier XML contenant les données du classifieur (on l'a ajouté au dossier res/raw)
                    InputStream is = getResources().openRawResource(R.raw.banana);
                    File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
                    mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
                    FileOutputStream os = new FileOutputStream(mCascadeFile);

                    byte[] buffer = new byte[4096];
                    int bytesRead;
                    while ((bytesRead = is.read(buffer)) != -1) {
                        os.write(buffer, 0, bytesRead);
                    }
                    is.close();
                    os.close();

                    mCascadeClassifier = new CascadeClassifier(mCascadeFile.getAbsolutePath());
                    if (mCascadeClassifier.empty()) {
                        Log.e(TAG, "Failed to load cascade classifier");
                        mCascadeClassifier = null;
                    } else
                        Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());

                    cascadeDir.delete();

                } catch (IOException e) {
                    e.printStackTrace();
                    Log.e(TAG, "Failed to load cascade. Exception thrown: " + e);
                }
                //Fin de la partie sur la reconnaissance d'image
                 */
                mOpenCvCameraView.enableView();
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
 @Override
 public void onManagerConnected(int status) {
   switch (status) {
     case LoaderCallbackInterface.SUCCESS:
       {
         Log.i(TAG, "OpenCV loaded successfully");
         mOpenCvCameraView.enableView();
       }
       break;
     default:
       {
         super.onManagerConnected(status);
       }
       break;
   }
 }
 @Override
 public void onManagerConnected(int status) {
   switch (status) {
     case LoaderCallbackInterface.SUCCESS:
       {
         mOpenCVInitiated = true;
         CameraGestureSensor.loadLibrary();
         mGestureSensor.start();
       }
       break;
     default:
       {
         super.onManagerConnected(status);
       }
       break;
   }
 }
 @Override
 public void onManagerConnected(int status) {
   switch (status) {
     case LoaderCallbackInterface.SUCCESS:
       {
         Log.i(TAG, "OpenCV loaded successfully");
         mOpenCvCameraView.enableView();
         mOpenCvCameraView.setOnTouchListener(ColorBlobDetectionActivity.this);
       }
       break;
     default:
       {
         super.onManagerConnected(status);
       }
       break;
   }
 }
Esempio n. 9
0
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                init_sd_imgs();

                // mat_share = new Mat();
                Bitmap bitmap_share = null;

                Intent intent = getIntent();
                String action = intent.getAction();
                String type = intent.getType();

                if (Intent.ACTION_SEND.equals(action) && type != null) {
                  if ("text/plain".equals(type)) {
                    handleSendText(intent);
                  } else if (type.startsWith("image/")) {
                    bitmap_share = handleSendImage(intent);
                  }
                }

                Fragment fragment = new GalleryFragment();

                if (mat_share == null && bitmap_share != null) {
                  mat_share = new Mat();
                  Utils.bitmapToMat(bitmap_share, mat_share);
                }

                if (mat_share != null) {
                  fragment = new RcvGridFragment(MainActivity.this);
                }

                getFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                Log.i(TAG, "OpenCV loaded successfully");

                /* Now enable camera view to start receiving frames */
                mOpenCvCameraView.setOnTouchListener(PuzzleActivity.this);
                mOpenCvCameraView.enableView();
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
 @Override
 public void onManagerConnected(int status) {
   switch (status) {
     case LoaderCallbackInterface.SUCCESS:
       {
         Log.i(TAG, "OpenCV loaded successfully");
         // Create and set View
         // setContentView(R.layout.main);
         setContentView(R.layout.markercamera);
         initTWSurfaceViewListener();
         startMarkerDetectionProcess();
       }
       break;
     default:
       {
         super.onManagerConnected(status);
       }
       break;
   }
 }
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                // OpenCV loaded successfully!
                // Load native library AFTER OpenCV initialization

                initialize();

                mOpenCvCameraView.enableView();
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
Esempio n. 13
0
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                mOpenCvCameraView.enableView();
                outputFrame = new Mat();
                marker = new Mat();
                logo = new Mat();
                Bitmap logoBmp = BitmapFactory.decodeResource(getResources(), R.drawable.logo);
                Utils.bitmapToMat(logoBmp, logo);
                Imgproc.resize(logo, logo, new Size(512, 512));
                outputLogo = logo.clone();
                timer = new Timer();

                // Detection Task (runs in background)
                timer.schedule(
                    new TimerTask() {

                      // Hamming codes
                      private final int[][] hamming_matrix = {
                        {0, 0, 1, 1, 1},
                        {0, 1, 0, 1, 1},
                        {0, 1, 1, 0, 1},
                        {0, 1, 1, 1, 0},
                        {1, 0, 0, 1, 1},
                        {1, 0, 1, 0, 1},
                        {1, 0, 1, 1, 0},
                        {1, 1, 0, 0, 1},
                        {1, 1, 0, 1, 0},
                        {1, 1, 1, 0, 0},
                        {1, 1, 1, 1, 1},
                        {1, 1, 1, 1, 0},
                        {1, 1, 1, 0, 1},
                        {1, 1, 0, 1, 1},
                        {1, 1, 0, 0, 0},
                        {1, 0, 1, 1, 1}
                      };

                      // Marker Detector object
                      private MarkerDetector detector = new MarkerDetector();

                      /* Decodes a marker
                       * Uses the planar marker image to try to read it's value
                       * Returns -1 if the value was incorrect
                       */
                      public int decodeMarker() {
                        if (frame == null) {
                          return -1;
                        } else {
                          // Inverse homography to get the planar marker image
                          Imgproc.warpPerspective(
                              frame,
                              marker,
                              homography,
                              new Size(512, 512),
                              Imgproc.WARP_INVERSE_MAP);
                          int accum = 0; // Accumulator (marker value)
                          int check = 0; // Check (Hamming codes of the image)
                          int correctCheck = 0; // Hamming codes og the Accumulator
                          int counter = 0; // Bit counter (Current bit being read)
                          for (int y = 0; y < 6; ++y) {
                            for (int x = 0; x < 6; ++x) {
                              // Ignore the colored corners
                              if (!(y <= 1 && (x <= 1 || x >= 4))
                                  && !(y >= 4 && (x <= 1 || x >= 4))) {
                                // Read the value from the middle of the square
                                double[] val = marker.get(41 + 470 * y / 5, 41 + 470 * x / 5);
                                if (val != null) {
                                  if (val[0] < 64 && val[1] < 64 && val[2] < 64) {
                                    if (counter < 15) {
                                      accum |= (1 << counter);
                                      for (int i = 0; i < 5; ++i) {
                                        correctCheck ^= (hamming_matrix[counter][i]) << i;
                                      }
                                    } else {
                                      check |= (1 << counter - 15);
                                    }
                                  }
                                  counter++;
                                }
                              }
                            }
                          }
                          if (check == correctCheck) {
                            return accum;
                          } else {
                            return -1;
                          }
                        }
                      }

                      @Override
                      public void run() {
                        // If there's a frame, try to find the marker and get the homography
                        if (frame != null && frame.cols() > 0 && frame.rows() > 0) {
                          Mat newHomography = detector.getHomography(frame);
                          homography = newHomography;
                          // If the marker was found, decode it's value
                          if (homography != null) {
                            int newMarkerValue = decodeMarker();
                            // If a valid value was found, update the current value
                            if (newMarkerValue != -1) {
                              markerValue = newMarkerValue;
                            }
                          }
                        }
                      }
                    },
                    1000,
                    20);
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }
Esempio n. 14
0
        @Override
        public void onManagerConnected(int status) {
          switch (status) {
            case LoaderCallbackInterface.SUCCESS:
              {
                Log.i(TAG, "OpenCV loaded successfully");

                try {
                  // load cascade file from application resources
                  InputStream is = getResources().openRawResource(R.raw.lbpcascade_frontalface);
                  File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
                  mCascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
                  FileOutputStream os = new FileOutputStream(mCascadeFile);

                  byte[] buffer = new byte[4096];
                  int bytesRead;
                  while ((bytesRead = is.read(buffer)) != -1) {
                    os.write(buffer, 0, bytesRead);
                  }
                  is.close();
                  os.close();

                  // --------------------------------- load left eye
                  // classificator -----------------------------------
                  InputStream iser =
                      getResources().openRawResource(R.raw.haarcascade_lefteye_2splits);
                  File cascadeDirER = getDir("cascadeER", Context.MODE_PRIVATE);
                  File cascadeFileER = new File(cascadeDirER, "haarcascade_eye_right.xml");
                  FileOutputStream oser = new FileOutputStream(cascadeFileER);

                  byte[] bufferER = new byte[4096];
                  int bytesReadER;
                  while ((bytesReadER = iser.read(bufferER)) != -1) {
                    oser.write(bufferER, 0, bytesReadER);
                  }
                  iser.close();
                  oser.close();

                  mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
                  if (mJavaDetector.empty()) {
                    Log.e(TAG, "Failed to load cascade classifier");
                    mJavaDetector = null;
                  } else
                    Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());

                  mJavaDetectorEye = new CascadeClassifier(cascadeFileER.getAbsolutePath());
                  if (mJavaDetectorEye.empty()) {
                    Log.e(TAG, "Failed to load cascade classifier");
                    mJavaDetectorEye = null;
                  } else
                    Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());

                  cascadeDir.delete();

                } catch (IOException e) {
                  e.printStackTrace();
                  Log.e(TAG, "Failed to load cascade. Exception thrown: " + e);
                }
                mOpenCvCameraView.setCameraIndex(1);
                mOpenCvCameraView.enableFpsMeter();
                mOpenCvCameraView.enableView();
              }
              break;
            default:
              {
                super.onManagerConnected(status);
              }
              break;
          }
        }