Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

working with yml files in python and opencv

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.
like image 823
Inshu Chauhan Avatar asked Nov 13 '22 18:11

Inshu Chauhan


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

like image 112
JonathanV Avatar answered Nov 15 '22 08:11

JonathanV