コード例 #1
0
ファイル: PupilsFrame.cpp プロジェクト: lingz/eye-see-you
PupilsFrame::PupilsFrame(const EyesFrame &eyes, const cv::Rect &face, cv::Mat &faceROI) {
  cv::Point leftPupil;
  cv::Point rightPupil;

  hasLeftPupil = eyes.hasLeftEye;
  hasRightPupil = eyes.hasRightEye;
  numPupils = eyes.numEyes;

  if (hasLeftPupil) {
    leftPupil = findEyeCenter(faceROI, eyes.leftEye, "Left Eye");
    leftPupilX = leftPupil.x - eyes.leftEye.width / 2;
    leftPupilAbsX = leftPupil.x + eyes.leftEye.x + face.x;
    leftPupilY = leftPupil.y - eyes.leftEye.height / 2;
    leftPupilAbsY = leftPupil.y + eyes.leftEye.y + face.y;
  }

  if (hasRightPupil) {
    rightPupil = findEyeCenter(faceROI, eyes.rightEye, "Right Eye");
    rightPupilX = rightPupil.x - eyes.rightEye.width / 2;
    rightPupilAbsX = rightPupil.x + eyes.rightEye.x + face.x;
    rightPupilY = rightPupil.y - eyes.rightEye.height / 2;
    rightPupilAbsY = rightPupil.y + eyes.rightEye.y + face.y;
  }

}
コード例 #2
0
ファイル: main.cpp プロジェクト: pellekrogholt/eyeLike
void findEyes(cv::Mat frame_gray, cv::Rect face) {
  cv::Mat faceROI = frame_gray(face);
  
  if (kSmoothFaceImage) {
    double sigma = kSmoothFaceFactor * face.width;
    GaussianBlur( faceROI, faceROI, cv::Size( 0, 0 ), sigma);
  }
  //-- Find eye regions and draw them
  int eye_region_width = face.width * (kEyePercentWidth/100.0);
  int eye_region_height = face.width * (kEyePercentHeight/100.0);
  int eye_region_top = face.height * (kEyePercentTop/100.0);
  cv::Rect leftEyeRegion(face.width*(kEyePercentSide/100.0),
                         eye_region_top,eye_region_width,eye_region_height);
  cv::Rect rightEyeRegion(face.width - eye_region_width - face.width*(kEyePercentSide/100.0),
                          eye_region_top,eye_region_width,eye_region_height);
  
  //-- Find Eye Centers
  cv::Point leftPupil = findEyeCenter(faceROI,leftEyeRegion,"Left Eye");
  cv::Point rightPupil = findEyeCenter(faceROI,rightEyeRegion,"Right Eye");
  // get corner regions
  cv::Rect leftCornerRegion(leftEyeRegion);
  leftCornerRegion.width -= leftPupil.x;
  leftCornerRegion.x += leftPupil.x;
  leftCornerRegion.height /= 2;
  leftCornerRegion.y += leftCornerRegion.height / 2;
  cv::Rect rightCornerRegion(rightEyeRegion);
  rightCornerRegion.width = rightPupil.x;
  rightCornerRegion.height /= 2;
  rightCornerRegion.y += rightCornerRegion.height / 2;
  rectangle(faceROI,leftCornerRegion,200);
  rectangle(faceROI,rightCornerRegion,200);
  // change eye centers to face coordinates
  rightPupil.x += rightEyeRegion.x;
  rightPupil.y += rightEyeRegion.y;
  leftPupil.x += leftEyeRegion.x;
  leftPupil.y += leftEyeRegion.y;
  // draw eye centers
  circle(faceROI, rightPupil, 3, 1234);
  circle(faceROI, leftPupil, 3, 1234);
  
  //-- Find Eye Corners
  if (kEnableEyeCorner) {
    cv::Point leftCorner = findEyeCorner(faceROI(leftCornerRegion), false);
    leftCorner.x += leftCornerRegion.x;
    leftCorner.y += leftCornerRegion.y;
    cv::Point rightCorner = findEyeCorner(faceROI(leftCornerRegion), false);
    rightCorner.x += rightCornerRegion.x;
    rightCorner.y += rightCornerRegion.y;
    circle(faceROI, rightCorner, 3, 200);
    circle(faceROI, leftCorner, 3, 200);
  }
  
  imshow(face_window_name, faceROI);
}
コード例 #3
0
std::vector<float> FeatureVectorBuilder::detectFeatures(const cv::Mat& input) {

	//For saving puropse
	static int imgNumber = 0;

	assert(input.data != NULL);
	
	//Finding face size
	int rightFace, leftFace;
	int size = faceSize(input, leftFace, rightFace);

	//Eyes section
	int eyeLine = findEyesLine(input);

	cv::Mat rEye, lEye;
	cv::Rect rEyeRect, lEyeRect;

	findEyes(input, eyeLine, rEye, lEye, rEyeRect, lEyeRect);

	if(rEye.data == NULL || lEye.data == NULL) {
		return std::vector<float>(7);
	}

	cv::Point rEyeCenter, lEyeCenter;
	int rEyeRadius, lEyeRadius;

	findEyeCenter(rEye, rEyeCenter, rEyeRadius);
	findEyeCenter(lEye, lEyeCenter, lEyeRadius);

	transformPoint(rEyeCenter, rEyeRect);
	transformPoint(lEyeCenter, lEyeRect);

	//nose
	cv::Mat nose;
	cv::Rect noseRect = findNose(input);
 	input(noseRect).copyTo(nose);

	if((noseRect.width <= 0 && noseRect.height <= 0) || nose.data == NULL) {
		return std::vector<float>(7);
	}

	cv::Point noseLeft, noseRight;
	findNosePoints(nose, noseLeft, noseRight);

	transformPoint(noseLeft, noseRect);
	transformPoint(noseRight, noseRect);


	//mouth

	cv::Mat mouth;
	cv::Point left, right, up, down;
	cv::Rect mouthRect = findMouth(input);
	input(mouthRect).copyTo(mouth);

	if((mouthRect.width <= 0 && mouthRect.height <= 0) || mouth.data == NULL) {
		return std::vector<float>(7);
	}

	findMouthPoints(mouth, left, right, up, down);

	transformPoint(left, mouthRect);
	transformPoint(right, mouthRect);
	transformPoint(up, mouthRect);
	transformPoint(down, mouthRect);

#ifdef _DEBUG
	cv::Mat cpy;
	input.copyTo(cpy);

	cv::circle(cpy, lEyeCenter, 4, cv::Scalar(0, 0, 255));
	cv::circle(cpy, rEyeCenter, 4, cv::Scalar(0, 0, 255));
	cv::circle(cpy, noseLeft, 4, cv::Scalar(0, 255, 0));
	cv::circle(cpy, noseRight, 4, cv::Scalar(0, 255, 0));
	cv::circle(cpy, left, 4, cv::Scalar(255, 0, 255));
	cv::circle(cpy, right, 4, cv::Scalar(255, 0, 255));
	cv::circle(cpy, up, 4, cv::Scalar(255, 0, 255));
	cv::circle(cpy, down, 4, cv::Scalar(255, 0, 255));

	std::stringstream ss;
	ss << "debug//img" << imgNumber << ".jpg";
	cv::imwrite(ss.str(), cpy);
	imgNumber++;
#endif

	//wektor cech
	float x1, x2, x3, x4, x5, x6, x7;

	//odlegosc miedzy srodkami oczy
	x1 = distance(lEyeCenter, rEyeCenter);

	//szerokosc nosa
	x2 = distance(noseLeft, noseRight);

	//szerokosc ust
	x3 = distance(left, right);

	//wysokosc ust
	x4 = distance(up, down);

	//szerokosc twarzy
	x5 = (float)size;

	//odgleglosc miedzy linia oczu a lina nosa
	float tmp1, tmp2;
	tmp1 = distance(lEyeCenter, noseLeft);
	tmp2 = distance(rEyeCenter, noseRight);
	x6 = (tmp1 + tmp2) / 2.0f;

	//odleglosc miedzy linia oczu a linia ust
	tmp1 = distance(lEyeCenter, left);
	tmp2 = distance(rEyeCenter, right);
	x7 = (tmp1 + tmp2) / 2.0f;

	std::vector<float> characteristic;
	characteristic.push_back(x1/x2);
	characteristic.push_back(x1/x3);
	characteristic.push_back(x2/x3);
	characteristic.push_back(x1/x5);
	characteristic.push_back(x1/x6);
	characteristic.push_back(x1/x7);
	characteristic.push_back(x4/x5);

	return characteristic;
}
コード例 #4
0
ファイル: blackpixels.cpp プロジェクト: sarmadm/eyeMon
void Blackpixels::eyeCenters(cv::Mat faceROI, cv::Rect leftEyeRegion, cv::Rect rightEyeRegion, cv::Point &leftPupil, cv::Point &rightPupil) {
    leftPupil  = findEyeCenter(faceROI, leftEyeRegion);
    rightPupil = findEyeCenter(faceROI, rightEyeRegion);
}