如何将CV_8UC3 Mat转换为CV_32FC3? [英] How do I convert CV_8UC3 Mat to CV_32FC3?

查看:511
本文介绍了如何将CV_8UC3 Mat转换为CV_32FC3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不直接访问原始缓冲区的情况下将CV_8UC3 Mat转换为CV_32FC3 Mat?我尝试了Mat::convertTo(newImage, CV_32FC3, 1.0);,但是颜色最终还是错误的.谢谢.

Is there a way to convert from CV_8UC3 Mat to CV_32FC3 Mat without directly accessing the raw buffer? I tried Mat::convertTo(newImage, CV_32FC3, 1.0); but the colors end up wrong. Thanks.

推荐答案

约定是,对于CV_8UC3类型,像素值范围是0到255,对于CV_32FC3类型,像素值范围是0.0到1.0.因此,您需要使用1/255.0的缩放比例,而不是1.0:

The convention is, that for the type CV_8UC3 the pixels values range from 0 to 255, and for type CV_32FC3 from 0.0 to 1.0. Thus you need to use a scaling factor of 1/255.0 instead of 1.0:

Mat::convertTo(newImage, CV_32FC3, 1/255.0);

这篇关于如何将CV_8UC3 Mat转换为CV_32FC3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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