Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
777 views
in Technique[技术] by (71.8m points)

read .yml files in matlab

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...