在 matlab 中读取 .yml 文件 [英] read .yml files in matlab

查看:20
本文介绍了在 matlab 中读取 .yml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Matlab 中阅读 .yml 文件.这些文件包含人脸图像上关键点的坐标 x 和 y.我寻找了不同的工具,但似乎没有找到任何答案.

I would like to read .yml files in Matlab. These files contain coordinates x and y of key points on a face image. I looked for different tools but I don't seem to find any answers.

我的 .yml 文件看起来像这样

My .yml files look like this

YAML:1.0
Image file: "00032009.jpg"
Contours count: 8
Contours:
   -
      Name: FO
      Count: 41
      Closed: 0
      Points:
         -
            x: 682.5947265625000000
            y: 743.1998901367187500
         -
            x: 685.9638061523437500
            y: 771.3800659179687500

......

等等

Note 00032009.jpg 是一张脸的图像x 和 y 是人脸点的坐标 例如:右眼角等

Note 00032009.jpg is an image of a face x and y are coordinates of a point on a face Eg: the right corner of an eye etc

能否请您指出一种读取文件然后在面部图像上显示点的方法?

Could you please point out a way to read the file and then display the points on the face image?

编辑 1:这是我得到的错误

Error: File: ReadYamlRaw.m Line: 14 Column: 11
Expression or statement is incorrect--possibly unbalanced (, {, or [.
Error in ==> ReadYaml at 38
    ry = ReadYamlRaw(filename, 0, nosuchfileaction);

奇怪的是 ReadYamlRaw.m 中的第 14 行

What is weird is line 14 in ReadYamlRaw.m

[pth,~,~]= fileparts(mfilename('fullpath'));

 Parse error at ','(second one) and ']' usage appears to be invalid matlab syntax.

那么里面的~有什么用,为什么会报错呢?

So what is the use of ~ in there and why is there an error?

Edit2:我将上面一行中的 ~ 替换为虚拟变量,然后出现此错误 O_O

Edit2: I replaced the ~ in the line above with dummy variables then I get this errors O_O

 Error using ==> ReadYamlRaw>scan at 81
Unknown data type: logical

Error in ==> ReadYamlRaw>scan_map at 138
            result.(ich) = scan(r.get(java.lang.String(ich)));

Error in ==> ReadYamlRaw>scan at 79
        result = scan_map(r);

Error in ==> ReadYamlRaw>scan_list at 116
        result{ii} = scan(i);

Error in ==> ReadYamlRaw>scan at 77
        result = scan_list(r);

Error in ==> ReadYamlRaw>scan_map at 138
            result.(ich) = scan(r.get(java.lang.String(ich)));

Error in ==> ReadYamlRaw>scan at 79
        result = scan_map(r);

Error in ==> ReadYamlRaw>load_yaml at 48
        result = scan(yaml.load(fileread([filename, fileext])));

Error in ==> ReadYamlRaw at 19
    result = load_yaml(filename, nosuchfileaction);

Error in ==> ReadYaml at 38
    ry = ReadYamlRaw(filename, 0, nosuchfileaction);

我还尝试了一个不同的 yml 文件,看起来像这样

I also tried with a different yml file that looks like this

%YAML:1.0
RE-C:
   x: 919
   y: 580
LE-C:
   x: 1209
   y: 597
N-C:
   x: 1063
   y: 698
FO-B:
   x: 1045
   y: 1114
REL-O:
   x: 852
   y: 597
REL-I:
   x: 986
   y: 600
REL-T:
   x: 918
   y: 564

我收到以下错误

Java exception occurred:
while scanning a directive
 in "<string>", line 1, column 1:
    %YAML:1.0
    ^
expected alphabetic or numeric character, but found :(58)
 in "<string>", line 1, column 6:
    %YAML:1.0
         ^


    at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirectiveName(ScannerImpl.java:1028)

    at org.yaml.snakeyaml.scanner.ScannerImpl.scanDirective(ScannerImpl.java:990)

    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchDirective(ScannerImpl.java:534)

    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:251)

    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:179)

    at
    org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:198)

    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:161)

    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:146)

    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105)

    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:121)

    at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:480)

    at org.yaml.snakeyaml.Yaml.load(Yaml.java:399)


Error in ==> ReadYamlRaw>load_yaml at 48
        result = scan(yaml.load(fileread([filename, fileext])));

Error in ==> ReadYamlRaw at 19
    result = load_yaml(filename, nosuchfileaction);

Error in ==> ReadYaml at 38
    ry = ReadYamlRaw(filename, 0, nosuchfileaction);

也许有人可以从中做出一些东西,或者您可以指出另一组可行的功能?我搜索了但没有找到除了这个之外的任何东西.

Maybe someone can make something out of these or you could point out another set of functions that would work? I searched but didn't find any except this one.

推荐答案

确实是 YAML 文件(正如 @DavidBrown 在他的评论中提到的,扩展名无关紧要).但它有一些问题.不知道是YAML格式不对还是MATLAB实现不对.

It's YAML file indeed (as @DavidBrown mentioned in his comment, the extension does not matter). But it has some problems. Don't know if it's due to wrong YAML format or MATLAB implementation.

我已经安装了 YAMLMATLAB 并使用了您的文件.

I've installed YAMLMATLAB and played a little with your file.

YamlStruct = ReadYaml(yaml_file);

如果文件按原样提供,YAMLMATLAB 会返回错误.仅当我注释第一行并从字段名称中删除空格时,它才有效.所以文件的开头是这样的:

YAMLMATLAB returns error if the files is feed as is. It works only if I comment the first line and remove spaces from field names. So the beginning of the file looks like this:

#YAML:1.0
Imagefile: 00032009.jpg
Contourscount: 8
...skipped the rest...

然后我得到正确的结构.例如,您可以访问第一个点的 x 坐标为

Then I get the correct structure. For example you can access the 1st point's x coordinate as

YamlStruct.Contours{1}.Points{1}.x

ans =

  682.5947

更新

文件名中的空格实际上是 YAMLMATLAB 中的一个已知问题.请在此处查看报告和可能的解决方案.

Space in filed names is actually a known problem in YAMLMATLAB. See the report and possible solution here.

更新 2

根据@Jirka_cigler(YAMLMATLAB 开发者组)的评论:

According to comment from @Jirka_cigler (YAMLMATLAB developers group):

在程序版本 0.4.3 中,我们添加了对字段中空格的支持名字,所以问题应该不会再次出现.

In the program release 0.4.3 we added support for whitespaces in field names, so the problem should not appear again.

太棒了!

我还删除了以前开发人员在第一次更新中对该问题的评论,因为它不再是真的了.

I've also removed previous developers comment on the problem in the first UPDATE since it's not true any more.

这篇关于在 matlab 中读取 .yml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆