Advertisement
Avatarr

object_detection

Mar 11th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. String fileName = "image/wl2.jpg";
  2.         IplImage image = cvLoadImage(fileName);
  3.         IplImage _image = cvCloneImage(image);
  4.  
  5.         image = Guassian.apply(image, 3);
  6.         image = Grayscale.apply(image);
  7.         image = Threshold.apply(image, CV_THRESH_OTSU);
  8.         image = MORPH.apply(image, 7, 3, CV_MOP_ERODE);
  9.         image = MORPH.apply(image, 7, 3, CV_MOP_DILATE);
  10.         image = Canny.apply(image);
  11.  
  12.         int dp = 2;
  13.         // minimum distance between two circles
  14.         int minDist = 50;
  15.         // Canny high threshold
  16.         int highThreshold = 200;
  17.         // minimum number of votes
  18.         int votes = 100;
  19.         int minRadius = 25;
  20.         int maxRadius = 100;
  21.  
  22. //////////// --------- Finding Object ------------------------
  23.         CvMemStorage mem = CvMemStorage.create();
  24.  
  25.         CvSeq eclipse = cvHoughCircles(image, mem, CV_HOUGH_GRADIENT,
  26.                 dp, minDist, highThreshold, votes, minRadius, maxRadius);
  27.  
  28.  
  29.         for (int i = 0; i < eclipse.total(); i++) {
  30.             CvPoint3D32f circle = new CvPoint3D32f(cvGetSeqElem(eclipse, i));
  31.             CvPoint center = cvPointFrom32f(new CvPoint2D32f(circle.x(), circle.y()));
  32.             int radius = Math.round(circle.z());
  33.             //cvCircle(image, center, radius, CV_RGB(200, 200, 200), 2, CV_AA, 0);
  34.             cvCircle(_image, center, radius, CV_RGB(255, 0, 0), 2, CV_AA, 0);
  35.             System.out.println(center);
  36.  
  37.         }
  38.  
  39. ///////// --------------- end ----------------------------------
  40.  
  41.         // Show image on window.
  42.         final CanvasFrame iCanvas = new CanvasFrame("Display Image", 1);
  43.         iCanvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
  44.         iCanvas.showImage(image);
  45.         final CanvasFrame _iCanvas = new CanvasFrame("Display Image", 1);
  46.         _iCanvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
  47.         _iCanvas.showImage(_image);
  48.  
  49.  
  50.  
  51.         // deallocate memory
  52.         // wait windows
  53.         cvWaitKey();
  54.         cvReleaseImage(image);
  55.     }
  56.  
  57.     /**
  58.      * @param args the command line arguments
  59.      */
  60.     public static void main(String[] args) throws Exception {
  61.         JavaImage2D j = new JavaImage2D();
  62.  
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement