
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
2.3.2 案例10:图像解码应用
对于接收到的图像数据流,需要使用图像解码功能解码为图像数据。
在OpenCV中,用于图像解码的函数为imdecode。imdecode函数的C++语言函数定义如下:

imdecode函数的Python语言函数定义如下:

imdecode函数的参数说明如下。
● buf:bytes类型的输入数据流。
● flags:解码标志,由cv:ImreadModes定义。
● retval:解码的图像结果(返回值)。
本案例从txt中读取已保存的图像数据流,然后将数据流解码为图像并显示。本案例的代码如下:

解码后的图像显示如图2.7所示。

图2.7