eos 1.4.0
Loading...
Searching...
No Matches
read_pts_landmarks.hpp
1/*
2 * eos - A 3D Morphable Model fitting library written in modern C++11/14.
3 *
4 * File: include/eos/core/read_pts_landmarks.hpp
5 *
6 * Copyright 2014, 2017 Patrik Huber
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#pragma once
21
22#ifndef EOS_READ_PTS_LANDMARKS_HPP
23#define EOS_READ_PTS_LANDMARKS_HPP
24
25#include "eos/core/Landmark.hpp"
26
27#include "Eigen/Core"
28
29#include <algorithm>
30#include <fstream>
31#include <string>
32#include <vector>
33
34namespace eos {
35namespace core {
36
45{
46 using Eigen::Vector2f;
47 using std::getline;
48 using std::string;
50 landmarks.reserve(68);
51
52 std::ifstream file(filename);
53 if (!file)
54 {
55 throw std::runtime_error(string("Could not open landmark file: " + filename));
56 }
57
58 string line;
59 // Skip the first 3 lines, they're header lines:
60 getline(file, line); // 'version: 1'
61 getline(file, line); // 'n_points : 68'
62 getline(file, line); // '{'
63
64 int ibugId = 1;
65 while (getline(file, line))
66 {
67 if (line == "}")
68 { // end of the file
69 break;
70 }
71 std::stringstream lineStream(line);
72
73 Landmark<Vector2f> landmark;
74 landmark.name = std::to_string(ibugId);
75 if (!(lineStream >> landmark.coordinates[0] >> landmark.coordinates[1]))
76 {
77 throw std::runtime_error(string("Landmark format error while parsing the line: " + line));
78 }
79 // From the iBug website:
80 // "Please note that the re-annotated data for this challenge are saved in the Matlab convention of 1
81 // being the first index, i.e. the coordinates of the top left pixel in an image are x=1, y=1."
82 // ==> So we shift every point by 1:
83 landmark.coordinates[0] -= 1.0f;
84 landmark.coordinates[1] -= 1.0f;
85 landmarks.emplace_back(landmark);
86 ++ibugId;
87 }
88 return landmarks;
89};
90
91} /* namespace core */
92} /* namespace eos */
93
94#endif /* EOS_READ_PTS_LANDMARKS_HPP */
std::vector< Landmark< LandmarkType > > LandmarkCollection
A trivial collection of landmarks that belong together.
Definition: Landmark.hpp:47
LandmarkCollection< Eigen::Vector2f > read_pts_landmarks(std::string filename)
Definition: read_pts_landmarks.hpp:44
Namespace containing all of eos's 3D model fitting functionality.
Representation of a landmark, consisting of a landmark name and coordinates of the given type....
Definition: Landmark.hpp:38
std::string name
Name of the landmark, often used as identifier.
Definition: Landmark.hpp:39
LandmarkType coordinates
The position or coordinates of the landmark.
Definition: Landmark.hpp:40