예제 #1
0
  public void draw() {
    if (tone.isPlaying()) {
      background(255);
    } else {
      background(100);
    }

    // Set the volume to a range between 0 and 1.0
    float ratio = (float) mouseX / width;
    tone.setVolume(ratio);

    // Set the rate to a range between 0 and 88,200
    // Changing the rate alters the pitch
    ratio = (float) mouseY / height;

    // The rate is set according to the mouseY position.
    tone.setRate(ratio * 88200);

    // Draw some rectangles to show what is going on
    stroke(0);
    fill(175);
    rect(0, 160, mouseX, 20);
    stroke(0);
    fill(175);
    rect(160, 0, 20, mouseY);
  }
예제 #2
0
 // Pressing the mouse stops and starts the sound
 public void mousePressed() {
   if (tone.isPlaying()) {
     tone.stop(); //   The sound can be stopped with the function stop().
   } else {
     tone.repeat();
   }
 }
예제 #3
0
  public void setup() {
    size(200, 200);
    // Start Sonia engine.
    Sonia.start(this);

    // Create a new sample object.
    tone = new Sample("tone.wav");

    // Loop the sound forever
    // (well, at least until stop() is called)
    tone.repeat();
    smooth();
  }
  public static void main(String[] args) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    //      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
    //      System.out.println( "mat = " + mat.dump() );

    Sample n = new Sample();
    //   n.templateMatching();

    // put text in image
    //      Mat data= Highgui.imread("images/erosion.jpg");

    //      Core.putText(data, "Sample", new Point(50,80), Core.FONT_HERSHEY_SIMPLEX, 1, new
    // Scalar(0,0,0),2);
    //
    //      Highgui.imwrite("images/erosion2.jpg", data);

    // getting dct of an image
    String path = "images/croppedfeature/go (20).jpg";
    path = "images/wordseg/img1.png";
    Mat image = Highgui.imread(path, Highgui.IMREAD_GRAYSCALE);
    ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();

    Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_OTSU);
    Imgproc.threshold(image, image, 220, 128, Imgproc.THRESH_BINARY_INV);
    Mat newImg = new Mat(45, 100, image.type());

    newImg.setTo(new Scalar(0));
    n.copyMat(image, newImg);

    int vgap = 25;
    int hgap = 45 / 3;

    Moments m = Imgproc.moments(image, false);
    Mat hu = new Mat();
    Imgproc.HuMoments(m, hu);
    System.out.println(hu.dump());

    //      //divide the mat into 12 parts then get the features of each part
    //      int count=1;
    //      for(int j=0; j<45; j+=hgap){
    //    	  for(int i=0;i<100;i+=vgap){
    //    		  Mat result = newImg.submat(j, j+hgap, i, i+vgap);
    //
    //
    //    		  Moments m= Imgproc.moments(result, false);
    //    		  double m01= m.get_m01();
    //    		  double m00= m.get_m00();
    //    		  double m10 = m.get_m10();
    //    		  int x= m00!=0? (int)(m10/m00):0;
    //    		  int y= m00!=0? (int)(m01/m00):0;
    //    		  Mat hu= new Mat();
    //    		  Imgproc.HuMoments(m, hu);
    //    		  System.out.println(hu.dump());
    //    		  System.out.println(count+" :"+x+" and "+y);
    //    		  Imgproc.threshold(result, result, 0,254, Imgproc.THRESH_BINARY_INV);
    //    		  Highgui.imwrite("images/submat/"+count+".jpg", result);
    //    		  count++;
    //
    //    	  }
    //      }
    //
    //    for(int i=vgap;i<100;i+=vgap){
    //	  Point pt1= new Point(i, 0);
    //      Point pt2= new Point(i, 99);
    //      Core.line(newImg, pt1, pt2, new Scalar(0,0,0));
    //  }
    //  for(int i=hgap;i<45;i+=hgap){
    //	  Point pt1= new Point(0, i);
    //      Point pt2= new Point(99, i);
    //      Core.line(newImg, pt1, pt2, new Scalar(0,0,0));
    //  }
    //      Highgui.imwrite("images/submat/copyto.jpg", newImg);
  }