2013-12-13 62 views
2

我正在開發opencv眼睛檢測項目,並且通過haar級聯的幫助,我已經成功檢測到兩隻眼睛的矩形區域。現在我想從兩隻眼睛中檢測眼球,問題是我沒有眼球跟蹤的哈爾級聯。請幫助我,如果你有任何人有這個XML並提出其他解決方案。 這裏是我的眼檢測haar cascade for opencv中的眼球android

private Mat get_template(CascadeClassifier clasificator, Rect area,int size) 
{ 
     Mat eye = new Mat(); 
     Mat template = new Mat(); 
     Mat mROI = mGray.submat(area); 
     MatOfRect eyes = new MatOfRect(); 
     Point iris = new Point(); 
     Rect eye_template = new Rect(); 
     clasificator.detectMultiScale(mROI, eyes, 1.15, 2, Objdetect.CASCADE_FIND_BIGGEST_OBJECT|Objdetect.CASCADE_SCALE_IMAGE, new Size(30,30), new Size()); 
    Rect[] eyesArray = eyes.toArray(); 

    for (int i = 0; i < eyesArray.length; i++) 

    { 

     Rect e = eyesArray[i]; 

     e.x = area.x + e.x; 
     e.y = area.y + e.y; 

     Core.rectangle(mROI, e.tl(), e.br(), new Scalar(25, 50, 0, 255)); 

     Rect eye_only_rectangle = new Rect((int)e.tl().x, (int)(e.tl().y + e.height*0.4), (int)e.width, (int)(e.height*0.6)); 
     //reduce ROI 
     mROI = mGray.submat(eye_only_rectangle); 
     Mat vyrez = mRgba.submat(eye_only_rectangle); 
     Core.MinMaxLocResult mmG = Core.minMaxLoc(mROI); 
     //Draw pink circle on eyeball 
     int radius = vyrez.height()/2; 
    // Core.circle(vyrez, mmG.minLoc, 2, new Scalar(0, 255, 0, 1), radius); 
     //Core.circle(vyrez, mmG.minLoc,2, new Scalar(255, 0, 255),1); 
     iris.x = mmG.minLoc.x + eye_only_rectangle.x; 
     iris.y = mmG.minLoc.y + eye_only_rectangle.y; 
     eye_template = new Rect((int)iris.x-size/2,(int)iris.y-size/2 ,size,size); 
     //draw red rectangle around eyeball 
     //Core.rectangle(mRgba,eye_template.tl(),eye_template.br(),new Scalar(255, 0, 0, 255), 2); 
     eye = (mRgba.submat(eye_only_rectangle)); 
     template = (mGray.submat(eye_template)).clone(); 
     //return template; 

     Mat eyeball_HSV = new Mat(); 
     Mat dest = new Mat();  
     //Mat eye = new Mat(); 

     //eye = mRgba.submat(eye_only_rectangle); 

     List<Mat> hsv_channel = new ArrayList<Mat>(); 
     //convert image to HSV 
      Imgproc.cvtColor(eye, eyeball_HSV, Imgproc.COLOR_RGB2HSV, 0); 

      // get HSV channel 
     //hsv_channel[0] is hue 
     //hsv_channel[1] is saturation 
     //hsv_channel[2] is visibility 
     Core.split(eyeball_HSV, hsv_channel); 

     try 
     { 
      hsv_channel.get(0).setTo(new Scalar(145)); 

      Log.v(TAG, "Got the Channel!"); 
     } 
     catch(Exception ex) 
     { 
      ex.printStackTrace(); 
      Log.v(TAG, "Didn't get any channel"); 
     } 

     Core.merge(hsv_channel, eyeball_HSV); 

     Imgproc.cvtColor(eyeball_HSV, dest, Imgproc.COLOR_HSV2RGB); 
     Imgproc.cvtColor(dest, eye, Imgproc.COLOR_RGB2RGBA);  


    } 

    return eye; 
    }`enter code here` 

回答