Advertisement
Guest User

OpenCvYellow

a guest
Jul 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. public void colorMask(View view)
  2.     {
  3.         Log.v("message","Start of function call");
  4.         ImageView imageViewMy = findViewById(R.id.imageViewMatches);
  5.         TextView textViewMy = findViewById(R.id.textViewDist);
  6.         textViewMy.setMovementMethod(new ScrollingMovementMethod());
  7.  
  8.         //Image Input :
  9.         Bitmap one =
  10.                 drawableToBitmap(getResources().getDrawable(R.drawable.dsc_1247, this.getTheme()));
  11.         Mat img1 = new Mat();
  12.         Utils.bitmapToMat(one, img1, true);// moving one to img1 Mat structure.
  13.         //one.recycle(); //Undefined behaviour ..
  14.         System.gc();
  15.  
  16.  
  17.  
  18.         // downsize the image.
  19.         Mat pyrDown = new Mat();
  20.         Imgproc.resize(img1, pyrDown, new Size(img1.cols() / 4, img1.rows() / 4));
  21.         //Imgproc.pyrDown(img1, pyrDown, new Size(img1.cols() / 2, img1.rows() / 2));
  22.         img1.release();
  23.  
  24.         Mat img2 = new Mat();
  25.         cvtColor(pyrDown, img2, COLOR_BGR2HSV);
  26.  
  27.  
  28.  
  29.         Mat yellow = new Mat();
  30.         //Scalar yellowRGB = new Scalar();
  31.         inRange(img2, new Scalar(15, 0, 0), new Scalar(36, 255, 255), yellow);
  32.         //inRange(img2, new Scalar(229, 255, 204), new Scalar(51, 51, 0), yellow);
  33.         //inRange(img2, new Scalar(51, 51, 0), new Scalar(229, 255, 204), yellow);
  34.         //inRange(img2, new Scalar(229, 255, 204), new Scalar(51, 51, 0), yellow);
  35.         pyrDown.release();
  36.  
  37.         line(yellow, new Point(0,0), new Point(100, 100), new Scalar(51, 51, 0));
  38.         circle(yellow, new Point(25, 25), 5, new Scalar(229, 255, 204));
  39.         circle(yellow, new Point(75, 75), 5, new Scalar(51, 51, 0));
  40.  
  41.  
  42.  
  43.  
  44.         Bitmap imageMatched = Bitmap.createBitmap(yellow.cols(), yellow.rows(), Bitmap.Config.RGB_565);
  45.         Utils.matToBitmap(yellow, imageMatched);
  46.         imageViewMy.setImageBitmap(imageMatched);
  47.  
  48.  
  49.         Log.v("message","End of function call");
  50.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement