working with yml files in python and opencv

Question!

How can I load a yml file in Python and work with it ?

I used :

import cv
data = cv.Load("Z:/data/xyz_00000_300.yml")

But when I print data, it just gives the detail of the image like number of rows and columns etc.

I want to read what is there in the pixel of the image.

I tried to use the following code, but it gives me only the pixel values not the information contained in pixel?

def AccessPixels(img):
    for y in range(0, img.height):
        for x in range(0, img.width):
            cv.Get2D(img, y, x) # Slow get pixel value.
            cv.Set2D(img, y, x, (0, 0, 0, 0)) # Slow set pixel value.


Answers

To load and interact with yml files you need to first:

import yaml

Now you can read in a yaml file as a dictionary by doing something like this:

with codecs.open('your.yml', 'r', encoding='utf8') as f:
     yml_dict = yaml.safe_load(f)

Now the contents of the yaml file are available to you as a dictionary within yml_dict.

By : JonathanV


This video can help you solving your question :)
By: admin