简体   繁体   中英

How to convert cv::Mat type from CV_16UC1 to CV_8UC1

I have a cv::Mat image of type CV_16UC1 and I need it in CV_8UC1, so I can run cv::integral on it. I am not worried about overflow during the conversion - essentially I just want to bulk convert the image from unsigned short to unsigned char.

I asked elsewhere and someone suggested cvtColor , but I don't know what conversion code to use.

How about using Mat::convertTo? Documentation

A quick example: (not sure if you need scalefactor though, since I haven't tried)

Your16Image.convertTo(outputImage, CV_8UC1, scalefactor)

您可以使用cv :: convertScaleAbs直接将输出矩阵设置为unsigned char。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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