我正在開發一個android應用程序,我需要檢測眼睛的眨眼。到目前爲止,我已經能夠使用OpenCV檢測臉部和眼睛。但現在我需要檢查眼睛是否打開或關閉。我在某處讀到,我可以通過測量像素強度(灰度級)來實現這一點。但沒有正確解釋如何一步一步做到這一點。我實際上是OpenCV的新手。所以任何人都可以請幫助我,我該怎麼做。這真的很重要。檢測眼睛是否打開或關閉
這裏是我的onCameraFrame方法:
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
mGray = inputFrame.gray();
if (mAbsoluteFaceSize == 0) {
int height = mGray.rows();
if (Math.round(height * mRelativeFaceSize) > 0) {
mAbsoluteFaceSize = Math.round(height * mRelativeFaceSize);
}
}
if (mZoomWindow == null || mZoomWindow2 == null)
CreateAuxiliaryMats();
MatOfRect faces = new MatOfRect();
if (mJavaDetector != null)
mJavaDetector.detectMultiScale(mGray, faces, 1.1, 2,
2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(mAbsoluteFaceSize, mAbsoluteFaceSize),
new Size());
Rect[] facesArray = faces.toArray();
for (int i = 0; i < facesArray.length; i++) {
Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(),
FACE_RECT_COLOR, 2);
xCenter = (facesArray[i].x + facesArray[i].width + facesArray[i].x)/2;
yCenter = (facesArray[i].y + facesArray[i].y + facesArray[i].height)/2;
Point center = new Point(xCenter, yCenter);
Rect r = facesArray[i];
// compute the eye area
Rect eyearea = new Rect(r.x + r.width/20,
(int) (r.y + (r.height/20)), r.width - 2 * r.width/20,
(int) (r.height/9.0));
// split it
Rect eyearea_right = new Rect(r.x + r.width/6,
(int) (r.y + (r.height/4)),
(r.width - 2 * r.width/16)/3, (int) (r.height/4.0));
Rect eyearea_left = new Rect(r.x + r.width/11
+ (r.width - 2 * r.width/16)/2,
(int) (r.y + (r.height/4)),
(r.width - 2 * r.width/16)/3, (int) (r.height/4.0));
// draw the area - mGray is working grayscale mat, if you want to
// see area in rgb preview, change mGray to mRgba
Core.rectangle(mRgba, eyearea_left.tl(), eyearea_left.br(),
new Scalar(255, 0, 0, 255), 2);
Core.rectangle(mRgba, eyearea_right.tl(), eyearea_right.br(),
new Scalar(255, 0, 0, 255), 2);
if (learn_frames < 5) {
teplateR = get_template(mJavaDetectorEye, eyearea_right, 24);
teplateL = get_template(mJavaDetectorEye, eyearea_left, 24);
learn_frames++;
} else {
// Learning finished, use the new templates for template
// matching
match_eye(eyearea_right, teplateR, method);
match_eye(eyearea_left, teplateL, method);
}
}
return mRgba;
}
在此先感謝。
非常感謝。我會看看代碼。 –
感謝您一步一步的解釋。所以現在我知道我需要遵循哪些步驟來感謝你。首先,我必須將RGBA圖像轉換爲B&W。我找不到任何Java代碼。你能給我發送到它的java代碼的鏈接嗎? –
CvtColor:http://docs.opencv.org/java/org/opencv/imgproc/Imgproc.html –