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

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

问题描述

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



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

  YAML:1.0 
图像文件:00032009.jpg
轮廓数:8
轮廓:
-
名称:FO
计数:41
关闭: 0
积分:
-
x:682.5947265625000000
y:743.1998901367187500
-
x:685.9638061523437500
y:771.3800659179687500

......



等等



注意00032009.jpg是脸部的图像
x,y是脸部的一个点的坐标例如:眼睛的右角等

您可以指出一种方法来阅读文件,然后在脸部图像上显示点吗?

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

pre $ 错误:File:ReadYamlRaw.m Line:14 Column:11
表达式或语句不正确 - 可能不平衡(,{,或[。
Erro r in ==> ReadYaml at 38
ry = ReadYamlRaw(filename,0,nosuchfileaction);

ReadYamlRaw.m中的第14行有什么奇怪的

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

在','(第二个)和']'用法解析错误似乎是无效的matlab语法。

那么在那里使用〜为什么会有错误呢?

Edit2 :我把上面的行替换成了虚拟变量,然后我得到这个错误O_O

 错误使用==> ReadyamlRaw>扫描81 
未知数据类型:逻辑

错误==> ReadYamlRaw> scan_map at 138
result。(ich)= scan(r.get(java.lang.String(ich)));

错误==>在79
处读取YamlRaw>扫描结果= scan_map(r);

错误==> ReadYamlRaw> scan_list at 116
result {ii} = scan(i);

错误==>在77
结果=扫描列表(r)的ReadYamlRaw>扫描。

错误==> ReadYamlRaw> scan_map at 138
result。(ich)= scan(r.get(java.lang.String(ich)));

错误==>在79
处读取YamlRaw>扫描结果= scan_map(r);

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

错误==> ReadYamlRaw at 19
result = load_yaml(filename,nosuchfileaction);

错误==> ReadYaml at 38
ry = ReadYamlRaw(filename,0,nosuchfileaction);

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

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

我得到以下错误:

 发生Java异常:
在< string>第1行第1列中扫描指令

%YAML:1.0
^
预期的字母或数字字符,但在< string>第1行第6列中找到:(58)

%YAML: 1.0
^


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

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

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

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


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)


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

错误==> ReadYamlRaw at 19
result = load_yaml(filename,nosuchfileaction);

错误==> ReadYaml at 38
ry = ReadYamlRaw(filename,0,nosuchfileaction);

也许有人可以从中得到某些东西,或者您可以指出另一组可行的功能。我搜查,但没有发现任何除了这一个。

解决方案

这确实是YAML文件(就像@DavidBrown在他的评论中提到的,扩展名无所谓)。但是它有一些问题。不知道这是由于错误的YAML格式或MATLAB实现。



我已经安装了 YAMLMATLAB ,并与你的文件玩了一下。


$ b

  YamlStruct = ReadYaml (yaml_file); 

如果文件按原样提供,则YAMLMATLAB将返回错误。它只有在注释第一行并从字段名称中删除空格时才有效。所以这个文件的开始是这样的:

$ p $ #YAML:1.0
Imagefile:00032009.jpg
Contourscount:8
...跳过了其余的...

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

  YamlStruct。轮廓{1} .Points {1} .x 

ans =

682.5947

更新

空格在YAMLMATLAB中实际上是已知的问题。请参阅此处的报告和可能的解决方案。根据来自@Jirka_cigler(YAMLMATLAB开发者小组)的评论, :b
$ b


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


太好了!



我也删除了以前的开发者在第一个UPDATE中对这个问题的评论,因为它不再是真的。


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.

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

......

and so on

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?

Edit 1: Here is the error I get

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);

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: 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);

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

And I get the following errors

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.

解决方案

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.

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

YamlStruct = ReadYaml(yaml_file);

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...

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

UPDATE

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

UPDATE 2

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

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

Great!

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天全站免登陆