int _tmain(int argc, _TCHAR* argv[])
{
	IplImage* input_img = cvLoadImage("Carol_Niedermayer_0001.jpg",0);
	Mat input_mat=cvarrToMat(input_img,true);
	if (input_mat.cols == 0)
	{
		cout<<"can not load image"<<endl;
		return 1;
	}
	Rect face_box = face_detect(input_mat);
	cout<<"here"<<endl;
	Mat aligned_face(128,128,CV_8UC1);
	int flag = face_align(input_mat,&aligned_face,face_box);
	if(flag == 0)
	{
		cout<<"can not align the face image"<<endl;
		return 1;
	}
	imwrite("aligned_face.bmp",aligned_face);
	char* modelPath = "casia_144_ve_id_model_iter_1210000.bin";
	const int layer_index =14;
	const int len = 320*8*8;
	float* feature = (float*)malloc(320*sizeof(float));
	clock_t start, end;
	double time;
	start = clock();
	cnnFace cnn(modelPath,layer_index,len);
	if (cnn.cnnFaceInit() != 0) {
		return 1;
	}
	cnn.getFeature(aligned_face, feature);
	//cnn.getFeature(imgFace2, feat2);

	//float score = cnn.getScore(feat1, feat2);

	end = clock();
	time = (double)(end -  start) / CLOCKS_PER_SEC;

	cout << "The score is " << "\nTime is " << time << endl;
	cnn.~cnnFace();
	free(feature);
	return 0;
}
示例#2
0
BOOL CSkin::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	CSliderCtrl *pSlidCtrl = (CSliderCtrl*)GetDlgItem(IDC_RUB_SKIN);
	pSlidCtrl->SetRange(0, 100);
	pSlidCtrl->SetPos(0);
	pSlidCtrl = (CSliderCtrl*)GetDlgItem(IDC_WHITE_SKIN);
	pSlidCtrl->SetRange(0, 100);
	pSlidCtrl->SetPos(0);

	CMainFrame* pMain = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	COpenCVPlatDoc *pDoc = (COpenCVPlatDoc*)pMain->GetActiveDocument();
	COpenCVPlatView *pView = (COpenCVPlatView*)pMain->GetActiveView();

	face_detect(pDoc->image);

	if (faces.size() == 0)
	{
		face_info.SetString(_T("没有检测到人脸!"));
	}
	else
	{
		face_info.Format(_T("检测到了%d张人脸!"), faces.size());
	}
	UpdateData(false);

	int window_size = 11;
	int height = pDoc->image.size().height;
	int width = pDoc->image.size().width;

	for (int i = 0; i < faces.size(); i++)
	{
		int sx = faces[i].x;
		int sy = faces[i].y;
		int ex = faces[i].x + faces[i].width;
		int ey = faces[i].y + faces[i].height;
		if (pDoc->image.channels() == 3)
		{
			for (int row = sy; row < ey; row++)
			{
				uchar *data = rub_img.ptr<uchar>(row);
				for (int col = sx; col < ex; col++)
				{
					double r = 0, g = 0, b = 0;
					double wr = 0, wg = 0, wb = 0;
					for (int i = row - window_size / 2; i <= row + window_size / 2; i++)
					for (int j = col - window_size / 2; j <= col + window_size / 2; j++)
					{
						if (i >= 0 && i < height &&
							j >= 0 && j < width)
						{
							uchar *old_data = old_img.ptr<uchar>(i);
							int wind_i = i - row + window_size / 2;
							int wind_j = j - col + window_size / 2;
							double tb = wij(i, j, row, col, old_data[j * 3], data[col * 3]);
							double tg = wij(i, j, row, col, old_data[j * 3 + 1], data[col * 3 + 1]);
							double tr = wij(i, j, row, col, old_data[j * 3 + 2], data[col * 3 + 2]);
							b += old_data[j * 3] * tb;
							g += old_data[j * 3 + 1] * tg;
							r += old_data[j * 3 + 2] * tr;
							wb += tb;
							wg += tg;
							wr += tr;
						}
					}
					data[col * 3] = b / wb;
					data[col * 3 + 1] = g / wg;
					data[col * 3 + 2] = r / wr;
				}
			}
		}
		else
		{
			for (int row = sy; row < ey; row++)
			{
				uchar *data = rub_img.ptr<uchar>(row);
				for (int col = sx; col < ex; col++)
				{
					double r = 0, g = 0, b = 0;
					double w = 0;
					for (int i = row - window_size / 2; i <= row + window_size / 2; i++)
					for (int j = col - window_size / 2; j <= col + window_size / 2; j++)
					{
						if (i >= 0 && i < height &&
							j >= 0 && j < width)
						{
							uchar *old_data = old_img.ptr<uchar>(i);
							int wind_i = i - row + window_size / 2;
							int wind_j = j - col + window_size / 2;
							double t = wij(i, j, row, col, old_data[j], data[col]);
							b += old_data[j] * t;
							w += t;
						}
					}
					data[col] = b / w;
				}
			}
		}
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}
示例#3
0
int main(int argc, char* argv[]) {
	face_detect();
	return 0;
}