zoukankan      html  css  js  c++  java
  • 将Mat类型坐标数据生成pts文件

    前言

    获取人脸特征点的坐标信息之后,想要将坐标信息shape保存为pts/asf/txt等文件格式,本文就对此进行实现。

    实现过程

    1.确定pts文件的书写格式;

    以要生成的文件为例,书写格式如下:

    version: 1
    n_points:  68
    {
    185.345840 248.114906
    184.628280 274.246696
    185.794968 298.584355
    191.135878 323.166268
    198.841220 345.995681
    ...
    ...
    }

    分析:

    由*.pts文件可以看出,前三行和最后一行为字符串信息,中间部分的数据为shape坐标信息,横纵坐标之间用空格隔开;

    当然,你也可以定制自己需要的数据书写格式,也可以生成多行字符串信息便于理解;

    2.将数据shape信息写入,生成你需要的文件;

    function write_shape( shape68, filename)
    % function: 
    % Writes a pts file from a point matrix shape68 and a host image - 
    % i.e. the image that the shape belongs to.
    %{
    version: 1
    n_points:  68
    {
    115.167660 220.807529
    ...
    }
    %}
    [nbpoints d] = size( shape68 );
    eval(sprintf('fid=fopen(''%s'', ''wt'');', filename));
    fprintf(fid, 'version: 1
    ');
    fprintf(fid, 'n_points:  68
    ');
    fprintf(fid, '{
    ');
    %
    for j = 1 : nbpoints
        fprintf(fid,'%.6f %.6f
    ', shape68(j,1), shape68(j,2) );                  
    end
    fprintf(fid, '}
    ');
    fclose(fid);
    
    end
    

    其中,输入参数shape表示的是坐标信息,包含68个点,大小是68*2;

              输入参数filename表示的是你要生成文件的路径及文件名;

    3.应用实例;

    image_path = '.dataset30427236_1.jpg';
    ptsfilename = strcat(image_path(1:end-3), 'pts');
    %获取shape68数据
    %TODO
    %写入pts文件
    write_shape( shape68, ptsfilename); 

    参考

    1.百度经验

    做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。

  • 相关阅读:
    使用CSVDE批量导入命令/出口AD用户
    Everything You Wanted to Know About Machine Learning
    android Vibrator 用法
    oc-25- @property @synthesize
    oc-24-点语法
    oc-23-static
    oc-22-sel
    oc-21-class对象
    oc-20-多态
    oc-19-成员变量修饰符
  • 原文地址:https://www.cnblogs.com/happyamyhope/p/7574011.html
Copyright © 2011-2022 走看看