示例#1
0
void CorrelateMain::addToImage()
{
    int oldLongImageCount = longImageCount;
    int oldWidth = projWidth * oldLongImageCount;
    longImageCount++;
    int newWidth = projWidth * longImageCount;    
    
    //setup new image
	ofFloatPixels newImage;
	newImage.allocate(projWidth*longImageCount,projHeight, OF_PIXELS_RGB);
    memset(newImage.getPixels(), 0, 3*projWidth*projHeight*longImageCount*sizeof(float));
    
    //copy old contents around
    for (int j = 0; j < projHeight; j++)
        memcpy(newImage.getPixels() + newWidth*3*j*sizeof(float), longImage.getPixels() + oldWidth*3*j*sizeof(float), oldWidth * 3 *sizeof(float));
    
    
    
    //////////////////////////
    // copy new contents in
    //////////////////////////
    //	
    ofPoint& lbf(scanSet.lbf);
    ofPoint& rtb(scanSet.rtb);
    
	int iPP, iLIP;
    float* point;
	
	ofVec3f *it = scanSet.xyz;
	for (int i=0; i<scanSet.size; i++, it++) {
		const ofVec3f& xyz(*it);
		
		iPP = dataset_iPX[i] + projWidth * dataset_iPY[i];
        
		if (iPP < int(projWidth*projHeight) && iPP>=0)
        {
            //put pixels at right of image
            iLIP =  dataset_iPX[i] + newWidth * dataset_iPY[i] + oldWidth;
            
			memcpy(newImage.getPixels() + 3*iLIP, &xyz.x, 3*sizeof(float));
        }
	}
    //
    //////////////////////////
    
    longImage = newImage;
    
    
}
示例#2
0
文件: btcart.cpp 项目: langongjin/JDA
Mat_<int> BoostCart::GenLBF(const Mat& img, const Mat_<double>& shape) const {
  const Config& c = Config::GetInstance();
  Mat_<int> lbf(1, K);
  int* ptr = lbf.ptr<int>(0);
  const int base = carts[0].leafNum;
  int offset = 0;
  Mat img_h, img_q;
  cv::resize(img, img_h, Size(c.img_h_size, c.img_h_size));
  cv::resize(img, img_q, Size(c.img_q_size, c.img_q_size));
  STParameter stp_mc = STParameter::Calc(shape, c.joincascador->mean_shape);
  for (int k = 0; k < K; k++) {
    ptr[k] = offset + carts[k].Forward(img, img_h, img_q, shape, stp_mc);
    offset += base;
  }
  return lbf;
}
示例#3
0
bool JoinCascador::Validate(const Mat& img, double& score, Mat_<double>& shape) const {
  const Config& c = Config::GetInstance();
  Mat img_h, img_q;
  cv::resize(img, img_h, Size(c.img_h_size, c.img_h_size));
  cv::resize(img, img_q, Size(c.img_q_size, c.img_q_size));
  DataSet::RandomShape(mean_shape, shape);
  score = 0;
  Mat_<int> lbf(1, c.K);
  int* lbf_ptr = lbf.ptr<int>(0);
  const int base = 1 << (c.tree_depth - 1);
  int offset = 0;
  // stage [0, current_stage_idx)
  for (int t = 0; t < current_stage_idx; t++) {
    const BoostCart& btcart = btcarts[t];
    offset = 0;
    for (int k = 0; k < c.K; k++) {
      const Cart& cart = btcart.carts[k];
      int idx = cart.Forward(img, img_h, img_q, shape);
      score += cart.scores[idx];
      if (score < cart.th) {
        // not a face
        return false;
      }
      lbf_ptr[k] = offset + idx;
      offset += base;
    }
    // global regression
    shape += btcart.GenDeltaShape(lbf);
  }
  // current stage, cart [0, current_cart_idx]
  for (int k = 0; k <= current_cart_idx; k++) {
    const Cart& cart = btcarts[current_stage_idx].carts[k];
    int idx = cart.Forward(img, img_h, img_q, shape);
    score += cart.scores[idx];
    if (score < cart.th) {
      // not a face
      return false;
    }
  }
  return true;
}
示例#4
0
void CorrelateMain::update()
{
	if (bangLoad->getBang())
		loadData();
	
	if (bangEvaluate->getBang())
		evaluate();
	
	if (bangLoadCalibration->getBang())
	{
		calibration.load();
		bangEvaluate->enabled = true;
	}
	
	if (bangSave3DScan->getBang())
		saveScan();

	if (bangSaveMap->getBang())
		saveMap();
    
    if (bangAddToImage->getBang())
        addToImage();
    
    if (bangSaveImage->getBang())
        saveImage();
    
    if (bangClearImage->getBang())
        clearImage();
	
	ofVec3f& lbf(scanSet.lbf);
    ofVec3f& rtb(scanSet.rtb);
	
	if (rtb.x < lbf.x)
		rtb.x = lbf.x;
	if (rtb.y < lbf.y)
		rtb.y = lbf.y;
	if (rtb.z < lbf.z)
		rtb.z = lbf.z;
	
}
示例#5
0
void CorrelateMain::saveMap() {
	
    //////////////////////////
    // BMP file
    //////////////////////////
    //
	ofPixels imgSave;
	imgSave.allocate(projWidth, projHeight, OF_PIXELS_RGB);
	
	//clear all values out to black
	memset(imgSave.getPixels(), 0, projWidth*projHeight*3);
	
    ofVec3f& lbf(scanSet.lbf);
    ofVec3f& rtb(scanSet.rtb);
    
	int iPP, iPoint;
	iPoint = 0;
	unsigned char col[3];

	ofVec3f *it = scanSet.xyz;
	for (int i=0; i<scanSet.size; i++, it++) {
		const ofVec3f& xyz(*it);
		
        //check if not within selected bounds
        if (xyz[0] < lbf.x || xyz[1] < lbf.y || xyz[2] < lbf.z || xyz[0] > rtb.x || xyz[1] > rtb.y || xyz[2] > rtb.z)
            continue;
		
		//convert position to colour values
		col[0] = ofMap(xyz[0],lbf.x,rtb.x,0,255,true);
		col[1] = ofMap(xyz[1],lbf.y,rtb.y,0,255,true);
		col[2] = ofMap(xyz[2],lbf.z,rtb.z,0,255,true);
		
		iPP = dataset_iPX[iPoint] + projWidth * dataset_iPY[iPoint];
        
		if (iPP<int(projWidth*projHeight) && iPP>=0)
			memcpy(imgSave.getPixels()+3*iPP, col, 3);
		
		++iPoint;
	}
	
	//ofSaveImage(imgSave, lastFilename + ".bmp");
    //
    //////////////////////////
	
	
    //////////////////////////
    // HDR file
    //////////////////////////
    //
	ofFloatPixels hdrSave;
	hdrSave.allocate(projWidth, projHeight, OF_PIXELS_RGB);
	imgSave.allocate(projWidth, projHeight, OF_PIXELS_RGB);
	
	//clear all values out to black
	memset(hdrSave.getPixels(), 0, projWidth*projHeight*3 * sizeof(float));
	memset(imgSave.getPixels(), 0, projWidth*projHeight*3 * sizeof(unsigned char));
	
	for (int i=0; i<scanSet.size; i++, it++) {
		const ofVec3f& xyz(*it);
		
		//convert position to colour values
		col[0] = ofMap(xyz[0],lbf.x,rtb.x,0,255,true);
		col[1] = ofMap(xyz[1],lbf.y,rtb.y,0,255,true);
		col[2] = ofMap(xyz[2],lbf.z,rtb.z,0,255,true);
		
		iPP = dataset_iPX[i] + projWidth * dataset_iPY[i];
        
		if (iPP<int(projWidth*projHeight) && iPP>=0)
			memcpy(hdrSave.getPixels()+3*iPP, &xyz.x, 3 * sizeof(float));
		
		if (iPP<int(projWidth*projHeight) && iPP>=0)
			memcpy(imgSave.getPixels()+3*iPP, col, 3);
	}
	
	ofSaveImage(hdrSave, lastFilename + ".hdr");
	ofSaveImage(hdrSave, lastFilename + ".dds");
	ofSaveImage(imgSave, lastFilename + ".png");
    //
    //////////////////////////

}