Does opencv have a constexpr vector or matrix container

I would like to do something like this for example:

constexpr std::array<cv::Vec3b, 6> COLORS {
cv::Vec3b(0, 255, 0), // green
cv::Vec3b(255, 0, 0), // blue
cv::Vec3b(0, 0, 255), // red
cv::Vec3b(0, 255, 255), // yellow
cv::Vec3b(255, 0, 255), // magenta
cv::Vec3b(255, 255, 0) // cyan
}
However, cv::Vec3b cannot be made constexpr, is there support for constexpr containers in opencv? Or another way around this?

Compiler error:

error: the type ‘const std::vector<cv::Vec<unsigned char, 3> >’ of ‘constexpr’ variable ‘COLORS’ is not literal
};
You know, dude, it might be helpful to not copy'n'paste the same topic already posted elsewhere:
https://stackoverflow.com/questions/72429204/does-opencv-have-a-constexpr-vector-or-matrix-container
(there are other sites spammed with this question)

Maybe try asking this question in an opencv forum where people who know ALL about opencv might know?
Maybe not opencv is the culprit. The constexpr of std::vector constructor depends on the C++ Version. See:

https://en.cppreference.com/w/cpp/container/vector/vector

There might also be a difference between c array and std::array.

So whether the compiler accepts constexpr or not depends on the compiler and settings.
const std::vector<cv::Vec<unsigned char, 3> >

As current, std::vector can't be used with constexpr initialisation outside of a constexpr function as any dynamic memory used is only valid within the constexpr function.
Last edited on
Topic archived. No new replies allowed.