LandmarkCollection BobotLandmarkSource::getLandmarks() const { LandmarkCollection collection; if (index >= 0 && index < static_cast<int>(positions.size())) { const cv::Mat& image = imageSource->getImage(); const Rect_<float>& relativePosition = positions[index]; if (relativePosition.x == 0 && relativePosition.y == 0 && relativePosition.width == 0 && relativePosition.height == 0) { collection.insert(make_shared<RectLandmark>(landmarkName)); // invisible landmark } else { cv::Rect_<float> rect(relativePosition.x * image.cols, relativePosition.y * image.rows, relativePosition.width * image.cols, relativePosition.height * image.rows); collection.insert(make_shared<RectLandmark>(landmarkName, rect)); } } // Note: else { throw... } ? This should never happen in regular operation, now that we removed get() ? return collection; }
pair<path, LandmarkCollection> LfpwLandmarkFormatParser::readLine(const vector<string>& line, const string header) { path imageName = path(line[0]).filename(); LandmarkCollection landmarks; vector<string> headerTokens; // split the header boost::split(headerTokens, header, boost::is_any_of("\t")); unsigned int offset = -1; // The offset to go from the landmark number to the corresponding entry in the vector or line for (unsigned int i = 1; i <= 35; ++i) { // i corresponds to the landmark number of LFPW (see their picture) string landmarkName = headerTokens[3*i+offset].substr(0, headerTokens[3*i+offset].length()-2); // cuts off the last two characters ('_x') string tlmsName = lfpwToTlmsName(landmarkName); bool visible = true; // Todo: Could add "obscured" to Landmark class if (boost::lexical_cast<int>(line[3*i+offset+2]) == 2 || boost::lexical_cast<int>(line[3*i+offset+2]) == 3) { visible = false; } cv::Vec3f position(boost::lexical_cast<float>(line[3*i+offset]), boost::lexical_cast<float>(line[3*i+offset+1]), 0.0f); shared_ptr<Landmark> lm = make_shared<ModelLandmark>(tlmsName, position, visible); if (lm->getName().length() != 0) { // Todo: Find better solution landmarks.insert(lm); } } return make_pair(imageName, landmarks); }