C++ C++;eos-加载变形模型时出错:打开给定文件时出错:../share/sfm\u shape\u 3448.bin
我正试着跑。我设法在我的ubuntu机器上编译并安装了所有东西。但是,当尝试运行提供的一个示例(fit model simple.cpp)时,我遇到以下错误:C++ C++;eos-加载变形模型时出错:打开给定文件时出错:../share/sfm\u shape\u 3448.bin,c++,open-source,C++,Open Source,我正试着跑。我设法在我的ubuntu机器上编译并安装了所有东西。但是,当尝试运行提供的一个示例(fit model simple.cpp)时,我遇到以下错误: Error loading the Morphable Model: Error opening given file: ../share/sfm_shape_3448.bin 我也尝试硬编码文件的路径,但结果保持不变 有人知道我可能做错了什么吗 代码如下: /* * eos - A 3D Morphable Model fittin
Error loading the Morphable Model: Error opening given file: ../share/sfm_shape_3448.bin
我也尝试硬编码文件的路径,但结果保持不变
有人知道我可能做错了什么吗
代码如下:
/*
* eos - A 3D Morphable Model fitting library written in modern C++11/14.
*
* File: examples/fit-model-simple.cpp
*
* Copyright 2015 Patrik Huber
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "eos/core/Landmark.hpp"
#include "eos/core/LandmarkMapper.hpp"
#include "eos/fitting/orthographic_camera_estimation_linear.hpp"
#include "eos/fitting/RenderingParameters.hpp"
#include "eos/fitting/linear_shape_fitting.hpp"
#include "eos/render/utils.hpp"
#include "eos/render/texture_extraction.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "boost/program_options.hpp"
#include "boost/filesystem.hpp"
#include <vector>
#include <iostream>
#include <fstream>
using namespace eos;
namespace po = boost::program_options;
namespace fs = boost::filesystem;
using eos::core::Landmark;
using eos::core::LandmarkCollection;
using cv::Mat;
using cv::Vec2f;
using cv::Vec3f;
using cv::Vec4f;
using std::cout;
using std::endl;
using std::vector;
using std::string;
/**
* Reads an ibug .pts landmark file and returns an ordered vector with
* the 68 2D landmark coordinates.
*
* @param[in] filename Path to a .pts file.
* @return An ordered vector with the 68 ibug landmarks.
*/
LandmarkCollection<cv::Vec2f> read_pts_landmarks(std::string filename)
{
using std::getline;
using cv::Vec2f;
using std::string;
LandmarkCollection<Vec2f> landmarks;
landmarks.reserve(68);
std::ifstream file(filename);
if (!file.is_open()) {
throw std::runtime_error(string("Could not open landmark file: " + filename));
}
string line;
// Skip the first 3 lines, they're header lines:
getline(file, line); // 'version: 1'
getline(file, line); // 'n_points : 68'
getline(file, line); // '{'
int ibugId = 1;
while (getline(file, line))
{
if (line == "}") { // end of the file
break;
}
std::stringstream lineStream(line);
Landmark<Vec2f> landmark;
landmark.name = std::to_string(ibugId);
if (!(lineStream >> landmark.coordinates[0] >> landmark.coordinates[1])) {
throw std::runtime_error(string("Landmark format error while parsing the line: " + line));
}
// From the iBug website:
// "Please note that the re-annotated data for this challenge are saved in the Matlab convention of 1 being
// the first index, i.e. the coordinates of the top left pixel in an image are x=1, y=1."
// ==> So we shift every point by 1:
landmark.coordinates[0] -= 1.0f;
landmark.coordinates[1] -= 1.0f;
landmarks.emplace_back(landmark);
++ibugId;
}
return landmarks;
};
/**
* This app demonstrates estimation of the camera and fitting of the shape
* model of a 3D Morphable Model from an ibug LFPW image with its landmarks.
*
* First, the 68 ibug landmarks are loaded from the .pts file and converted
* to vertex indices using the LandmarkMapper. Then, an orthographic camera
* is estimated, and then, using this camera matrix, the shape is fitted
* to the landmarks.
*/
int main(int argc, char *argv[])
{
std::cerr<<"modif 1"<<endl;
fs::path modelfile, isomapfile, imagefile, landmarksfile, mappingsfile, outputfile;
try {
po::options_description desc("Allowed options");
desc.add_options()
("help,h",
"display the help message")
("model,m", po::value<fs::path>(&modelfile)->required()->default_value("/home/yalishanda/Downloads/eos-master/share/sfm_shape_3448.bin"),
"a Morphable Model stored as cereal BinaryArchive")
("image,i", po::value<fs::path>(&imagefile)->required()->default_value("/home/yalishanda/Downloads/eos-master/examples/data/image_0010.png"),
"an input image")
("landmarks,l", po::value<fs::path>(&landmarksfile)->required()->default_value("/home/yalishanda/Downloads/eos-master/examples/data/image_0010.pts"),
"2D landmarks for the image, in ibug .pts format")
("mapping,p", po::value<fs::path>(&mappingsfile)->required()->default_value("/home/yalishanda/Downloads/eos-master/share/ibug_to_sfm.txt"),
"landmark identifier to model vertex number mapping")
("output,o", po::value<fs::path>(&outputfile)->required()->default_value("out"),
"basename for the output rendering and obj files")
;
po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
if (vm.count("help")) {
cout << "Usage: fit-model-simple [options]" << endl;
cout << desc;
return EXIT_SUCCESS;
}
po::notify(vm);
}
catch (const po::error& e) {
cout << "Error while parsing command-line arguments: " << e.what() << endl;
cout << "Use --help to display a list of options." << endl;
return EXIT_FAILURE;
}
// Load the image, landmarks, LandmarkMapper and the Morphable Model:
Mat image = cv::imread(imagefile.string());
LandmarkCollection<cv::Vec2f> landmarks;
try {
landmarks = read_pts_landmarks(landmarksfile.string());
}
catch (const std::runtime_error& e) {
cout << "Error reading the landmarks: " << e.what() << endl;
return EXIT_FAILURE;
}
morphablemodel::MorphableModel morphable_model;
try {
morphable_model = morphablemodel::load_model(modelfile.string());
}
catch (const std::runtime_error& e) {
cout << "Error loading the Morphable Model: " << e.what() << endl;
return EXIT_FAILURE;
}
core::LandmarkMapper landmark_mapper = mappingsfile.empty() ? core::LandmarkMapper() : core::LandmarkMapper(mappingsfile);
// Draw the loaded landmarks:
Mat outimg = image.clone();
for (auto&& lm : landmarks) {
cv::rectangle(outimg, cv::Point2f(lm.coordinates[0] - 2.0f, lm.coordinates[1] - 2.0f), cv::Point2f(lm.coordinates[0] + 2.0f, lm.coordinates[1] + 2.0f), { 255, 0, 0 });
}
// These will be the final 2D and 3D points used for the fitting:
vector<Vec4f> model_points; // the points in the 3D shape model
vector<int> vertex_indices; // their vertex indices
vector<Vec2f> image_points; // the corresponding 2D landmark points
// Sub-select all the landmarks which we have a mapping for (i.e. that are defined in the 3DMM):
for (int i = 0; i < landmarks.size(); ++i) {
auto converted_name = landmark_mapper.convert(landmarks[i].name);
if (!converted_name) { // no mapping defined for the current landmark
continue;
}
int vertex_idx = std::stoi(converted_name.get());
auto vertex = morphable_model.get_shape_model().get_mean_at_point(vertex_idx);
model_points.emplace_back(Vec4f(vertex.x(), vertex.y(), vertex.z(), 1.0f));
vertex_indices.emplace_back(vertex_idx);
image_points.emplace_back(landmarks[i].coordinates);
}
// Estimate the camera (pose) from the 2D - 3D point correspondences
fitting::ScaledOrthoProjectionParameters pose = fitting::estimate_orthographic_projection_linear(image_points, model_points, true, image.rows);
fitting::RenderingParameters rendering_params(pose, image.cols, image.rows);
// The 3D head pose can be recovered as follows:
float yaw_angle = glm::degrees(glm::yaw(rendering_params.get_rotation()));
// and similarly for pitch and roll.
// Estimate the shape coefficients by fitting the shape to the landmarks:
Mat affine_from_ortho = fitting::get_3x4_affine_camera_matrix(rendering_params, image.cols, image.rows);
vector<float> fitted_coeffs = fitting::fit_shape_to_landmarks_linear(morphable_model, affine_from_ortho, image_points, vertex_indices);
// Obtain the full mesh with the estimated coefficients:
core::Mesh mesh = morphable_model.draw_sample(fitted_coeffs, vector<float>());
// Extract the texture from the image using given mesh and camera parameters:
Mat isomap = render::extract_texture(mesh, affine_from_ortho, image);
// Save the mesh as textured obj:
outputfile += fs::path(".obj");
core::write_textured_obj(mesh, outputfile.string());
// And save the isomap:
outputfile.replace_extension(".isomap.png");
cv::imwrite(outputfile.string(), isomap);
cout << "Finished fitting and wrote result mesh and isomap to files with basename " << outputfile.stem().stem() << "." << endl;
return EXIT_SUCCESS;
}
/*
*eos-一个三维变形模型拟合库,用现代C++11/14编写。
*
*文件:examples/fit-model-simple.cpp
*
*版权所有2015帕特里克·休伯
*
*根据Apache许可证2.0版(以下简称“许可证”)获得许可;
*除非遵守许可证,否则不得使用此文件。
*您可以通过以下方式获得许可证副本:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*除非适用法律要求或书面同意,软件
*根据许可证进行的分发是按“原样”进行分发的,
*无任何明示或暗示的保证或条件。
*请参阅许可证以了解管理权限和权限的特定语言
*许可证下的限制。
*/
#包括“eos/core/Landmark.hpp”
#包括“eos/core/LandmarkMapper.hpp”
#包括“eos/fitting/orthographic\u camera\u estimation\u linear.hpp”
#包括“eos/fitting/RenderingParameters.hpp”
#包括“eos/fitting/linear\u shape\u fitting.hpp”
#包括“eos/render/utils.hpp”
#包括“eos/render/texture_extraction.hpp”
#包括“opencv2/core/core.hpp”
#包括“opencv2/highgui/highgui.hpp”
#包括“boost/program_options.hpp”
#包括“boost/filesystem.hpp”
#包括
#包括
#包括
使用名称空间eos;
名称空间po=boost::program\u选项;
名称空间fs=boost::filesystem;
使用eos::core::Landmark;
使用eos::core::LandmarkCollection;
使用cv::Mat;
使用cv::Vec2f;
使用cv::Vec3f;
使用cv::Vec4f;
使用std::cout;
使用std::endl;
使用std::vector;
使用std::string;
/**
*读取ibug.pts landmark文件并返回一个有序向量,其中包含
*68个二维地标坐标。
*
*@param[in]文件名指向.pts文件的路径。
*@返回一个带有68个ibug地标的有序向量。
*/
LandmarkCollection read_pts_landmarks(标准::字符串文件名)
{
使用std::getline;
使用cv::Vec2f;
使用std::string;
地标收集地标;
地标保护区(68);
std::ifstream文件(文件名);
如果(!file.is_open()){
抛出std::runtime_错误(字符串(“无法打开地标文件:+filename”);
}
弦线;
//跳过前3行,它们是标题行:
getline(文件,行);//“版本:1”
getline(文件,行);/“n_点:68”
getline(文件,行);/“{”
int-ibugId=1;
while(getline(文件,行))
{
if(line==“}”){//文件结尾
打破
}
std::stringstream lineStream(行);
地标;
landmark.name=std::to_字符串(ibugId);
if(!(lineStream>>landmark.coordinates[0]>>landmark.coordinates[1])){
抛出std::runtime_错误(字符串(“分析行:“+line”时的Landmark格式错误));
}
//从iBug网站:
//“请注意,此质询的重新注释数据保存在1的Matlab约定中
//第一个索引,即图像中左上像素的坐标为x=1,y=1。”
//=>所以我们将每个点移动1:
地标坐标[0]=1.0f;
地标坐标[1]=1.0f;
地标。向后安放(地标);
++伊布吉德;
}
返回地标;
};
/**
*这个应用程序演示了相机的估计和形状的拟合
*来自ibug LFPW图像及其地标的三维可变形模型的模型。
*
*首先,68个ibug地标从.pts文件加载并转换
*使用LandmarkMapper创建顶点索引。然后,一个正交相机
*然后,使用此摄影机矩阵拟合形状
*去地标。
*/
int main(int argc,char*argv[])
{
标准::cerrdefault_值(“/home/yalishanda/Downloads/eos master/examples/data/image_0010.png”),
“输入图像”)
(“landmarks,l”,po::value(&landmarks文件)->必需()->默认值(“/home/yalishanda/Downloads/eos master/examples/data/image_0010.pts”),
“图像的二维地标,采用ibug.pts格式”)
(“mapping,p”,po::value(&mappingsfile)->required()->默认值(“/home/yalishanda/Downloads/eos master/share/ibug_to_sfm.txt”),
“地标标识符到模型顶点编号映射”)
(“输出,o”,po::值(&outputfile)->必需()->默认值(“输出”),
“输出渲染和obj文件的basename”)
;
变量映射虚拟机;
po::store(po::命令行解析器(argc,argv).options(desc.run(),vm);
if(vm.count(“帮助”)){
cout可能是因为您直接运行它,而没有将其作为项目生成。请查看eos文档:
git clone --recursive https://github.com/patrikhuber/eos.git
mkdir build && cd build # creates a build directory next to the 'eos' folder
cmake -G "<your favourite generator>" ../eos -DCMAKE_INSTALL_PREFIX=../install/
make && make install # or open the project file and build in an IDE like Visual Studio
git克隆——递归https://github.com/patrikhuber/eos.git
mkdir build&&cd build#在“eos”文件夹旁边创建一个生成目录
cmake-G”“../eos-DCMAKE_安装_前缀=../INSTALL/
制作并安装,或打开项目文件并在类似Visual Studio的IDE中生成
或者可能是由于git克隆后未成功加载文件
希望它有帮助!可能是因为您直接运行它,而不将其作为项目生成。请查看eos文档:
git clone --recursive https://github.com/patrikhuber/eos.git
mkdir build && cd build # creates a build directory next to the 'eos' folder
cmake -G "<your favourite generator>" ../eos -DCMAKE_INSTALL_PREFIX=../install/
make && make install # or open the project file and build in an IDE like Visual Studio
git克隆——递归https://github.com/patrikhuber/eos.git
mkdir build&&cd build#在“eos”文件夹旁边创建一个生成目录
cmake-G”“../eos-DCMAKE_安装_前缀=../INSTALL/
制作并安装,或打开项目文件并在类似Visual Studio的IDE中生成
或者可能是由于git克隆后未成功加载文件
希望有帮助