将图像从CV_64F转换为CV_8U [英] convert image from CV_64F to CV_8U

查看:1526
本文介绍了将图像从CV_64F转换为CV_8U的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OpenCV在Python中将类型CV_64FC1的图像转换为CV_8UC1.

I want to convert an image of type CV_64FC1 to CV_8UC1 in Python using OpenCV.

在C ++中,使用convertTo函数,我们可以使用以下代码段轻松转换图像类型:

In C++, using convertTo function, we can easily convert image type using following code snippet:

image.convertTo(image, CV_8UC1);

我在Internet上进行了搜索,但找不到错误的任何解决方案. Python OpenCV中有任何函数可以将其转换吗?

I have searched on Internet but unable to find any solution without errors. Any function in Python OpenCV to convert this?

推荐答案

您可以将其转换为Numpy数组.

You can convert it to a Numpy array.

import numpy as np

# Convert source image to unsigned 8 bit integer Numpy array
arr = np.uint8(image)

# Width and height
h, w = arr.shape

似乎OpenCV Python API也接受Numpy数组.我还没有测试过.请测试一下,让我知道结果.

It seems OpenCV Python APIs accept Numpy arrays as well. I've not tested it though. Please test it and let me know the result.

这篇关于将图像从CV_64F转换为CV_8U的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆