Ziad Yasser
Ziad Yasser

Reputation: 3

OpenCV- Convert mat image type from CV_8UC4 to CV_16UC3

I need to convert OpenCV different types like CV_8UC4 to CV_16UC3.

I tried convertTo(mat, CV_16UC3), but this is returns an empty image (when I save it to the storage it's empty).

Upvotes: 0

Views: 1776

Answers (1)

Micka
Micka

Reputation: 20130

convertTo can't change the number of channels.

You'll need two steps:

  1. cv::cvtColor(src, dst, CV_BGRA2BGR)
  2. dst.convertTo(mat, CV_16U)

for example if your 4th channel is an alpha channel and you just want to drop it.

Upvotes: 5

Related Questions