Example #1
0
/* Use the parameters of this keypoint to sample the gradient images
     at a set of locations within a circular region around the keypoint.
     The (scale,row,col) values are relative to current octave sampling.
     The resulting vector is stored in the key.
*/
void MakeKeypointSample(
	keypoint& key, const flimage& grad,
	float scale, float row, float col,siftPar &par)
{
	/* Produce sample vector. */
	KeySampleVec(key, grad, scale, row, col,par);


	/* Normalize vector.  This should provide illumination invariance
	for planar lambertian surfaces (except for saturation effects).
	Normalization also improves nearest-neighbor metric by
	increasing relative distance for vectors with few features.
	It is also useful to implement a distance threshold and to
	allow conversion to integer format.
	*/
	NormalizeVec(key.vec);

	/* Now that normalization has been done, threshold elements of
	index vector to decrease emphasis on large gradient magnitudes.
	Admittedly, the large magnitude values will have affected the
	normalization, and therefore the threshold, so this is of
	limited value.
	*/
	bool changed = false;
	for (int i = 0; i < VecLength; i++)
		if (key.vec[i] > par.MaxIndexVal) {
			key.vec[i] = par.MaxIndexVal;
			changed = true;
		}

	if (changed) NormalizeVec(key.vec);

	/* Convert float vector to integer. Assume largest value in normalized
	vector is likely to be less than 0.5. */
	/// QUESTION: why is the vector quantized to integer
	int intval;
	for (int i = 0; i < VecLength; i++) {
		intval =  static_cast<int>(512.0 * key.vec[i]);
		key.vec[i] = static_cast<float>(std::min(255, intval));
	}
}
Example #2
0
/* Use the parameters of this keypoint to sample the gradient images
     at a set of locations within a circular region around the keypoint.
     The (scale,row,col) values are relative to current octave sampling.
     The resulting vector is stored in the key.
*/
void MakeKeypointSample(KKeypoint key, Image grad, Image ori, float scale,
			float row, float col)
{
   int i, intval, changed = FALSE;
   float vec[VecLength];
   
   /* Produce sample vector. */
   KeySampleVec(vec, key, grad, ori, scale, row, col);
   
   /* Normalize vector.  This should provide illumination invariance
      for planar lambertian surfaces (except for saturation effects).
      Normalization also improves nearest-neighbor metric by
      increasing relative distance for vectors with few features.
   */
   NormalizeVec(vec, VecLength);

   /* Now that normalization has been done, threshold elements of
      index vector to decrease emphasis on large gradient magnitudes.
      Admittedly, the large magnitude values will have affected the
      normalization, and therefore the threshold, so this is of
      limited value.
   */
   for (i = 0; i < VecLength; i++)
     if (vec[i] > MaxIndexVal) {
       vec[i] = MaxIndexVal;
       changed = TRUE;
     }
   if (changed)
     NormalizeVec(vec, VecLength);

   /* Convert float vector to integer. Assume largest value in normalized
      vector is likely to be less than 0.5.
   */
   key->ivec = (unsigned char*) 
     MallocPool(VecLength * sizeof(unsigned char), KEY_POOL);
   for (i = 0; i < VecLength; i++) {
     intval = (int) (512.0 * vec[i]);
     assert(intval >= 0);
     key->ivec[i] = (unsigned char) MIN_(255, intval);
   }
}
Example #3
0
//頂点の変換。フレームから頂点位置を計算
void XModel::AnimateVertex() {
	float m[4];
	ORIGINAL_VERTEX *ov = oVertex;
	Vector3 pos,nom;
	
	for (int i=0; i<numVertices; i++) {
		// 頂点、法線を初期化。
		pos.x=0.0; pos.y=0.0; pos.z=0.0;
		nom.x=0.0; nom.y=0.0; nom.z=0.0;
		// ウェイト分繰り返し
		for (int j=0; j<4; j++) {
			//頂点
			m[0]=ov[i].pos.x; m[1]=ov[i].pos.y; m[2]=ov[i].pos.z; m[3]=1.0;
			Matrixkakeru(m, m, Frame[ov[i].index[j]]->SkinningMatrix);
			pos.x += m[0] * ov[i].weight[j];
			pos.y += m[1] * ov[i].weight[j];
			pos.z += m[2] * ov[i].weight[j];
			//法線
			m[0]=ov[i].normal.x; m[1]=ov[i].normal.y; m[2]=ov[i].normal.z; m[3]=1.0;
			Matrixkakeru(m, m, Frame[ov[i].index[j]]->SkinningMatrix);
			nom.x += m[0] * ov[i].weight[j];
			nom.y += m[1] * ov[i].weight[j];
			nom.z += m[2] * ov[i].weight[j];
		}
		//正規化
		NormalizeVec(&nom);
		
		//書き込み
		aVertex[i].pos.x = pos.x;
		aVertex[i].pos.y = pos.y;
		aVertex[i].pos.z = pos.z;
		aVertex[i].normal.x = nom.x;
		aVertex[i].normal.y = nom.y;
		aVertex[i].normal.z = nom.z;
	}
}
Example #4
0
Vector3 NormalizeVector(Vector3 v)
{
	NormalizeVec(&v);
	return v;
}