我在 Android 上使用这个 opencv 代码进行强度均衡。执行时间约为每帧 300 毫秒 (720x480)。有人对可能的时间优化有想法吗?
这是代码:
cvtColor(image, hsvImage, CV_BGR2HSV);
// Get intensity
intensity = hsvImage.at<Vec3b>((int)reference.Point_::y, (int)reference.Point_::x);
float value = (float)REGULAR_INTENSITY / intensity[2];
float saturation = (float)REGULAR_SATURATION / intensity[1];
if (counter == 15 && (int)intensity[2] < REGULAR_INTENSITY) {
equalization = false;
}
// Modify intensity
float transformedSaturation, transformedValue;
for(int i = 0; i < hsvImage.rows; i++) {
unsigned char *data = hsvImage.ptr(i);
for(int j = 0; j < hsvImage.cols; j++) {
transformedSaturation = (uchar)*++data * saturation;
if (transformedSaturation > MAX_COLOR) {
transformedSaturation = MAX_COLOR;
}
*data++ = transformedSaturation;
transformedValue = (uchar)*data * value;
if (transformedValue > MAX_COLOR) {
transformedValue = MAX_COLOR;
}
*data++ = transformedValue;
}
}
cvtColor(hsvImage, image, CV_HSV2BGR);