예제 #1
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operand* ConstantFolder::EvaluateMathOneParamFloat(CallInstr* callInstr, 
												   MathOneParamFloat function) {
	double value;
	if(ParametersValid(callInstr, value)) {
		double result = function(value);
		return irGen_->GetDoubleConst(result);
	}
    
    return nullptr;    
}
예제 #2
0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operand* ConstantFolder::EvaluateMathTwoParamsFloat(CallInstr* callInstr, 
													MathTwoParamsFloat function) {
	double value1;
	double value2;

	if(ParametersValid(callInstr, value1, value2)) {
		double result = function(value1, value2);
		return irGen_->GetDoubleConst(result);
	}
	else return nullptr;
}
bool IrisFinderHough::Find(IplImage* image, CvRect eyeROI)
{
	if (!ParametersValid())
		return false;
	if (m_sizeData.SizeChanged(eyeROI))
		PrepareImage(eyeROI);
	// some helper imgs
	IplImage* imgSobelH = cvCreateImage(cvSize(eyeROI.width, eyeROI.height), IPL_DEPTH_16S, 1);
	IplImage* imgSobelV = cvCreateImage(cvSize(eyeROI.width, eyeROI.height), IPL_DEPTH_16S, 1);

	// copy roi to internal image
	ImgLib::CopyRect(image, m_eyeImg, eyeROI, cvPoint(0, 0));
	cvSobel(m_eyeImg, imgSobelH, 1, 0, 3);
	cvSobel(m_eyeImg, imgSobelV, 0, 1, 3);
	
	double angle;
	double dx, dy;
	double thetaRad;
	double xPrim, yPrim;
	double xsi;
	double max_e = 2.2;

	HoughAccumulator acc(m_accPrecision);

	acc.AddParam(0, m_eyeImg->width);	// x0
	acc.AddParam(0, m_eyeImg->height);	// x1
	acc.AddParam(m_thetaMin, m_thetaMax);		// theta
	acc.AddParam(m_aMin, m_aMax);				// a
	acc.AddParam(m_bMin, m_bMax);				// b
	acc.Init();

	DOUBLEVECT indices;
	indices.resize(5);


	cvSmooth(m_eyeImg, m_eyeImg);
	cvCanny(m_eyeImg, m_eyeImg, 250, 100);


	for(int y = 0; y < m_eyeImg->height; y++)
    {
        short* sh_row = (short*)(imgSobelH->imageData + y * imgSobelH->widthStep);
		short* sv_row = (short*)(imgSobelV->imageData + y * imgSobelV->widthStep);
		uchar* canny_row = (uchar *)(m_eyeImg->imageData + y * m_eyeImg->widthStep);
		double x0, y0;
		double a, b, theta=0;

        for (int x = 0; x < m_eyeImg->width; x++)
        {
			if (canny_row[x] == 0)
				continue;
			short dX = sh_row[x];
			short dY = sv_row[x];
			if ( (abs(dX) + abs(dY)) < m_minGradStrength)
			{
				cvLine(m_eyeImg, cvPoint(x,y),cvPoint(x,y),CV_RGB(0,0,0));
				continue;
			}
			
			for (a = m_aMin; a < m_aMax; a+= (1 / m_accPrecision))
				for (b = m_bMin; b < m_bMax; b+= (1 / m_accPrecision))
				{
					double e = a / b;
					if (e < 1)
						e = b / a;
					if (e > max_e)
						continue;
					for (theta = m_thetaMin; theta < m_thetaMax; theta += (1 / m_accPrecision))
					{
						angle = atan2((float)dY, (float)dX);
						thetaRad = 2 * CV_PI * theta / 360.0;
						angle -= (thetaRad + CV_PI / 2.0);
						xsi = tan(angle);
						//xsi = (float) dY / (float) dX;
						dx = -SignX(dX, dY) * a / sqrt(1 + (b * b) / (a * a * xsi * xsi));
						dy = -SignY(dX, dY) * b / sqrt(1 + (a * a * xsi * xsi) / (b * b));
						// rotate by theta
						xPrim = cos(thetaRad) * dx - sin(thetaRad) * dy;
						yPrim = sin(thetaRad) * dx + cos(thetaRad) * dy;
						dx = xPrim; dy = yPrim;
						x0 = x + dx;
						y0 = y + dy;
						indices[0] = x0;
						indices[1] = y0;
						indices[2] = theta;
						indices[3] = a;
						indices[4] = b;
						acc.Increment(indices);
					}
				}
        }
    }

	indices = acc.FindBest();


	if (indices.size() > 0)
	{
		cvEllipse(image,
			cvPoint(indices[0] + eyeROI.x, indices[1] + eyeROI.y),
			cvSize(indices[3], indices[4]),
			-indices[2],
	//		90,
			0,
			360,
			CV_RGB(255, 0, 0));
		m_irisCentre.x = indices[0] + eyeROI.x;
		m_irisCentre.y = indices[1] + eyeROI.y;
		return true;
	}
	return false;
}