How can I convert just one pixel from from one color space to another? I figured out that cv::cvtColor
does not accept cv::Scalar
neither cv::Vec3f
. Or in other words, it accepts them but raise an error since they are going to be processed as 1-Channel cv::Mat
at the end. Is there a better (cleaner like directly from cv::Scalar
or cv::VecYX
) way than constructing a one element cv::Mat
like this?
cv::Vec3b covert_1_pixel_to_lab(cv::Vec3b const& src){
cv::Vec3b src(b,g,r);
cv::Mat src_mat(1, 1, CV_8UC3);
src_mat.ptr<uchar>(0)[0] = src(0);
src_mat.ptr<uchar>(0)[1] = src(1);
src_mat.ptr<uchar>(0)[2] = src(2);
cv::Mat dst_mat;
cv::cvtColor(src_mat, dst_mat, cv::COLOR_BGR2Lab);
return cv::Vec3b(dst_mat.ptr<uchar>(0)[0],
dst_mat.ptr<uchar>(0)[1],
dst_mat.ptr<uchar>(0)[2]);
}