我正在制作一个项目,我需要改变图像的亮度和对比度,亮度不是亮度。 所以我在一开始代码为cvtColor too Slow
for (int y = 0; y < dst.rows; y++) {
for (int x = 0; x < dst.cols; x++) {
int b = dst.data[dst.channels() * (dst.cols * y + x) + 0];
int g = dst.data[dst.channels() * (dst.cols * y + x) + 1];
int r = dst.data[dst.channels() * (dst.cols * y + x) + 2];
... other processing stuff i'm doing
和它的好,做起来非常快,但是当我试图让HSV到HSL的转换设置,我需要它reaaaaaaally得到缓慢的L值;
我HSL到的代码HSL线
cvtColor(dst, dst, CV_BGR2HSV);
Vec3b pixel = dst.at<cv::Vec3b>(y, x); // read pixel (0,0)
double H = pixel.val[0];
double S = pixel.val[1];
double V = pixel.val[2];
h = H;
l = (2 - S) * V;
s = s * V;
s /= (l <= 1) ? (l) : 2 - (l);
l /= 2;
/* i will further make here the calcs to set the l i want */
H = h;
l *= 2;
s *= (l <= 1) ? l : 2 - l;
V = (l + s)/2;
S = (2 * s)/(l + s);
pixel.val[0] = H;
pixel.val[1] = S;
pixel.val[2] = V;
cvtColor(dst, dst, CV_HSV2BGR);
,我跑了,就慢,所以我采取的线路,看看哪一个是使它慢,我弄清楚它是cvtColor(dst, dst, CV_BGR2HSV);
所以有办法让它比使用cvtCOlor更快,或者它的时间问题是可以处理的事情?
遍历整个图像和变化的像素值是不是一个好主意,并会采取大量的时间,所以我建议你使用内置的OpenCV的方法,作为split()将图像分解为组成通道并分别处理每个通道,还有'multiply()'''divide()','add()'等类型的算术运算实时...我使用内置方法打赌后可以获得10倍的速度提升。 – ZdaR
或者,如果您可以精确定义您想要执行的详细步骤,那么我可以准确地告诉您所需处理所需的方法。 – ZdaR