gpt4 book ai didi

python - 将图像从 CV_64F 转换为 CV_8U

转载 作者:太空狗 更新时间:2023-10-29 20:41:29 41 4
gpt4 key购买 nike

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

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

image.convertTo(image, CV_8UC1);

我在 Internet 上搜索过,但无法找到任何没有错误的解决方案。 Python OpenCV 中有任何函数可以转换它吗?

最佳答案

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

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 数组。我还没有测试过。请测试一下,然后告诉我结果。

关于python - 将图像从 CV_64F 转换为 CV_8U,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46260601/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com