⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mask.cpp

📁 tracciatore di mani con webcam
💻 CPP
字号:
#include "Common.h"#include "Mask.h"#include "Exceptions.h"#include <fstream>Mask::Mask(): m_width(-1),  m_height(-1),  m_image_area_ratio(-1),  m_name(""){}Mask::~Mask(){}void Mask::ParseFrom(string filename){  ifstream mask_file(filename.c_str());  if (!mask_file.is_open()) {    throw HVEFileNotFound(filename);  }  string line;  do {    getline(mask_file, line);  } while (line=="" || line[0]=='#');  m_probs.clear();  if (line==HV_MASK_VERSION_1_0_STRING) {	  // version 1.0    do {      getline(mask_file, line);    } while (line=="" || line[0]=='#');    float ratio;    char name[1024];    int scanned = sscanf(line.c_str(), "Mask %s %dx%d, ratio %f",                          name, &m_width, &m_height, &ratio);    if (scanned!=4) {      throw HVEFile(filename, string("expected mask metadata, found: ")+line);    }    if (name[strlen(name)-1]==',') name[strlen(name)-1] = 0;    if (name[strlen(name)-1]=='"') name[strlen(name)-1] = 0;    if (name[0]=='"') {      m_name = string(&name[1]);    } else {      m_name = string(name);    }    m_image_area_ratio = ratio;    m_probs.resize(m_width*m_height);    for (int row=0; row<m_height; row++) {      do {        getline(mask_file, line);      } while (line=="" || line[0]=='#');      char* cline = (char*) alloca(line.size()*sizeof(char));      strcpy(cline, line.c_str());      char* ctok = strtok(cline, " ");      for (int col=0; col<m_width; col++) {        double val = atof(ctok);        m_probs[row*m_width+col] = val;        ctok = strtok(NULL, " ");        if (ctok==NULL && col<m_width-1) {          throw HVEFile(filename, string("expected probabilities, found: ")+line);        }      }    }  } else {    // wrong version    throw HVEFile(filename, string("missing or wrong version: ")+line);  }  mask_file.close();}double Mask::GetProb(int x, int y) const{  ASSERT(0<=x && x<m_width);  ASSERT(0<=y && y<m_height);  return m_probs[y*m_width+x];}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -