bool
MCFaceBox::init(CCTexture2D *aFaceTexture, CCTexture2D *aBoxTexture)
{
    if (CCSprite::init()) {
        CCRect rect = CCRectZero;
        faceTexture_ = aFaceTexture;
        boxTexture_ = aBoxTexture;
        
        setTexture(aBoxTexture);
        rect.size = aBoxTexture->getContentSize();
        setTextureRect(rect);
        
        face_->setTexture(aFaceTexture);
        rect.size = aFaceTexture->getContentSize();
        face_->setTextureRect(rect);
        if (! face_->getParent()) {
            addChild(face_);
            alignFace();
        }
        
        return true;
    }
    
    return false;
}
示例#2
0
/*"G:\\Picture\\Lighting\\FaceFP_2.txt"*/
void GetFaceFromTxt(const string txtname, vector<Face>& vfaces)
{
	size_t maxSize = 1000;	///vpaths.size()
	string sign;
	int id;
	vector<string> vpaths(maxSize);	//文件路径
	vector<Vec4f> vpoints(maxSize);	//两眼坐标点
	vector<int> vids(maxSize);		//人脸ID号
	vector<string> vsigns(maxSize);	//标记
	vector<Mat> vmfaces(maxSize);		//归一化人脸区域
	ReadTxt(txtname, vpaths, vpoints, ' ');	//读入文件名和两眼坐标
	for (size_t i = 0; i<maxSize; i++)	//分解文件名,得到ID和状态标志
	{
		string path = vpaths[i];
		ReadFilename(path, id, sign);
		vids.push_back(id);
		vsigns.push_back(sign);
	}
	for (size_t j = 0; j<maxSize; j++)
	{
		string long_path = "G:\\Picture\\pose\\" + vpaths[j].substr(0, vpaths[j].size()-1) + ".jpg";	//分割得到的文件名多出一个空格,-1去除
		Mat image = imread(long_path, 0);
		if (!image.empty())
		{
			Point2f pLeft = Point2f(vpoints[j][0],vpoints[j][1]);
			Point2f pRight = Point2f(vpoints[j][2],vpoints[j][3]);
#if 0	//光照时需归一化
			Mat dst = alignFace(image, pRight, pLeft);	//尺寸归一化

#elif 0	//头部姿态标记两眼距离
			Mat dst = image;
			line(dst, pLeft, pRight, Scalar(0, 0, 0), 2, 8);
			circle(dst, pLeft, 2, Scalar(255, 255, 255), 2, 8);
			circle(dst, pRight, 2, Scalar(255, 255, 255), 2, 8);

#else 1	//对称性
			Mat dst = AlignFace(image, pRight, pLeft);	//尺寸归一化

#endif
			vmfaces.push_back(dst);
	/*		imshow("image", dst);
			waitKey(0);*/
		}
	}
	//将人脸各项信息存入Face
	for (size_t m = 0; m<maxSize; m++)
	{
		Face mface;
		mface.filename = vpaths[m];
		mface.id = vids[m];
		mface.sign = vsigns[m];
		mface.eyePoints = vpoints[m];
		mface.face = vmfaces[m];
		mface.value = 0.0;
		vfaces.push_back(mface);
	}
}