OpenCV - Confusion over the bit depth requirements of various functions

I find that I am making many calls to convertTo () in my opencv c ++ code. This is somewhat confusing, and I'm not sure when I need to convert the image depth until I get an error message.

For example, I have Mat representing an image equal to 16U. Then I try to call matchTemplate () and get an assertion error that it expects 8U or 32F. Why shouldn't the template work on 16U? Similar problems arise when displaying an image (although restrictions on bit depth make more sense when displaying images). I am in a game with convertTo () and scaling factors and trying to display images correctly using imshow (), and I would like to do it more elegantly (maybe I'm ruined by the matlab imagesc function).

Am I missing something fundamental in that OpenCV expects to use bit depth? How to deal with opencv library function requirements for bit depth in a cleaner way?

+4
source share
2 answers

Assuming you are using the C interface :

cvMatchTemplate(const CvArr* image, const CvArr* templ, CvArr* result,int method)

image - the image in which the search is performed; must be 8-bit or 32-bit floating point

Most features in OpenCv will use either 8U (for grayscale images) or 32F (for 3-color color images).

0
source

The most common type of image is 8U (for both color and gray). This is the preferred OpenCV format.
Other formats are supported with more functionality.

0
source

Source: https://habr.com/ru/post/1391501/


All Articles