简体   繁体   English

使用python将Opencv Mat转储到YAML文件中

[英]Dumping Opencv Mat into a YAML file using python

Does anyone know how to write a cv2 mat into a YAML file using python ( I am not looking for any loading... just to create a YAML file ). 有谁知道如何使用python将cv2 mat写入YAML文件( 我不寻找任何加载...只是为了创建YAML文件 )。 I used the serializer given here , but after many trials I don't know how to dump the image (I'm very new in Python, so that's why I don't get some of the things explained there) 我使用了此处提供的序列化程序,但是经过多次试验,我不知道如何转储映像(我在Python中是一个非常新的人,所以这就是为什么我在这里没有得到一些解释的原因)

I tried with 我尝试过

img = cv2.imread('Example.jpg',1)
text_file = open('document.yaml', "w")
text_file.write(yaml.dump(img))

and also with the Dumper function from here 以及这里的自卸车功能

img = cv2.imread('seastar.jpg',1)
text_file = open('document.yaml', "w")
text_file.write(dump(img,Dumper=Dumper))

both give me the result: "TypeError: data type not understood" 两者都给我结果:“ TypeError:数据类型无法理解”

and (this one tells me that the object is not callable) 和(这告诉我该对象不可调用)

img = cv2.imread('seastar.jpg',1)
text_file = file('document.yaml', "w")
yaml.dump(img,text_file)
print yaml.dump(img_text)

Until now I just used numpy, omitting the serialization stuff... 直到现在,我只是使用numpy,省略了序列化的东西...

with open(out, 'w') as f:
    yaml.dump(img_d.tolist(), f) 

...But if there was a better way to do it, then I would be very thankful to you guys ...但是如果有更好的方法,那我将非常感谢你们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM