Skip to content

dstChannels does not cover all color codes #20465

@Loganms

Description

@Loganms

Same issue as #18878.

Missing color codes in the dstChannels function leads to less-performant cvtColor implementations being used.

inline int dstChannels(int code)

For example, I'm trying to convert OpenCL UMats and let OpenCV auto detect the number of channels like so:
cvtColor(src, dst, Lab2BGR, 0)

However, dstChannels doesn't recognize that specific color code so it forwards a dcn arg value of 0. This stops the OpenCL implementation because it fails a precondition check inside oclCvtColorLab2BGR when constructing the OclHelper.

CV_Check(dcn, VDcn::contains(dcn), "Invalid number of channels in output image");

when that check fails, cvtColor falls through to a HAL implementation.

I'm specifically raising this issue because Lab2BGR is not currently handled (should return 3), but dstChannels should be audited to verify it covers as many color codes as possible.

The workaround for now is to explicitly set the dcn when calling cvtColor based on the color code's destination format.

https://github.com/opencv/opencv/blob/70d5c88026708319533d2b9981b9f25505cc85bf/modules/imgproc/src/color.hpp

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions