IntImage* renderTemplateFrame(std::vector<FloatImage*>* tData, int f) { int twidth = (*tData)[0]->width; int theight = (*tData)[0]->height; IntImage* ret = new IntImage(twidth, theight, 3); ret->fill(0); // first, figure out the maximum value float maxval = 0.0f; float* curfdata = ((*tData)[f])->data; for(int p = 0; p < twidth * theight; ++p) if(fabs(curfdata[p]) > maxval) maxval = abs(curfdata[p]); std::cout << "maxval: " << maxval << std::endl; // now, figure out the multiplier float mult = 255.0f / maxval; int* rchan = ret->getChannel(0); int* gchan = ret->getChannel(1); int* bchan = ret->getChannel(2); // now multiply away and stuff for(int p = 0; p < twidth * theight; ++p) { int sval = (int)(curfdata[p] * mult); if(sval > 0) // put into green channel { gchan[p] = sval; } else // sval <= 0 // put into red channel { rchan[p] = -sval; } bchan[p] = 0; } return ret; }
ActionInstance* loadTemplateByName(std::string actionName, int actionType, int id, int count) { std::cout << "loading " << actionName << " " << id << std::endl; //std::string totalPrefix = "data/" + actionName; //std::string totalPrefix = "/Users/admin/GITHUB/MPC/our_templates/" + actionName; //std::string totalPrefix = "/home/ubuntu/project/MPC/temp_subs/ActionRecDemoV3/data/" + actionName; // std::string totalPrefix = "/Users/priyankakulkarni/Documents/Project/MPC/ActionRecDemoV3/palm_fist_templates/" + actionName; std::string totalPrefix = "/Users/priyankakulkarni/Documents/Project/MPC/ActionRecDemoV3/breakout_templates_resized/" + actionName; //std::string totalPrefix = "/home/ubuntu/project/MPC/palm_fist_templates/" + actionName; ActionInstance* ret = new ActionInstance; ret->tData = new std::vector<FloatImage*>; ret->id = id; ret->actionType = actionType; ret->tmass = 0.0f; ret->dist = 0.0f; for(int i = 0; i < count; ++i) { int curNum = 10000 + (100 * id) + i; //std::string fname = totalPrefix + "_" + IntToString(curNum) + ".PNG"; std::string fname = totalPrefix + "_" + IntToString(curNum) + ".png"; std::cout << "Filename: " << fname << std::endl; IntImage* tempII = new IntImage(cvLoadImage(fname.c_str())); int* c0 = tempII->getChannel(0); FloatImage* tempF = new FloatImage(tempII->width(), tempII->height()); for(int p = 0; p < tempF->width * tempF->height; ++p) { if(c0[p] > 127) { tempF->data[p] = -1.0f; ret->tmass += 1.0f; } else tempF->data[p] = 1.0f; } ret->tData->push_back(tempF); delete tempII; } std::cout << "Template had mass of " << ret->tmass << std::endl; return ret; }