cpp Mat convertTo is a method used in the OpenCV library for converting one image matrix to another with a different data type. It provides flexibility in terms of scaling, shifting, and other types of operations that can be applied to the image data.
Example 1:
// Convert an image from 8-bit to 32-bit float cv::Mat inputImg = cv::imread("input.jpg"); cv::Mat outputImg; inputImg.convertTo(outputImg, CV_32F);
Example 2:
// Convert an image from 16-bit unsigned integer to 8-bit signed integer cv::Mat inputImg = cv::imread("input.jpg", cv::IMREAD_ANYDEPTH); cv::Mat outputImg; inputImg.convertTo(outputImg, CV_8S, 0.5, -128);
In example 1, the input image is read from a file and then converted to a 32-bit float data type using the convertTo method. The output is then saved to the outputImg variable.
In example 2, the input image is read with the IMREAD_ANYDEPTH flag, which reads the image as a 16-bit unsigned int. The convertTo method is then used to scale the input values by 0.5 and shift the result by -128 before saving it to the outputImg variable.
The package library used for cpp Mat convertTo is the OpenCV library, which is a popular open-source computer vision library that provides a range of image processing functions and algorithms.
C++ (Cpp) Mat::convertTo - 30 examples found. These are the top rated real world C++ (Cpp) examples of Mat::convertTo from package ACM extracted from open source projects. You can rate examples to help us improve the quality of examples.