Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

opencv

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.

like image 601
escapecharacter Avatar asked Sep 27 '13 03:09

escapecharacter


People also ask

What type is CV_8UC1?

CV_8UC1 is an unsigned char .

What is CV_8UC3?

CV_8UC3 - 3 channel array with 8 bit unsigned integers. CV_8UC4 - 4 channel array with 8 bit unsigned integers. CV_8UC(n) - n channel array with 8 bit unsigned integers (n can be from 1 to 512) )


1 Answers

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)

like image 126
John Yang Avatar answered Nov 14 '22 22:11

John Yang