2

I'm using this opencv code on Android for an intensity equalization. The time of execution is around 300ms per frame (720x480). Does anybody have an idea for a possible time optimization ?

Here is the code :

        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);
3
  • have you found out which piece of code consumes most of the time? How much time spent on cvtColor and on the main loop? Commented Oct 9, 2012 at 11:30
  • The last line : CV_HSV2BGR conversion. I think nothing can be done. Commented Oct 10, 2012 at 7:07
  • 1
    Consider using gpu::cvtColor for color conversion, if applicable. Commented Oct 10, 2012 at 7:35

1 Answer 1

2

Have you tried using OpenCV transform ? I guess it is optimised, but I dont know about the saturating cast (that is if > max_color, then = max color)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks but as you see i'm multiplying with an array which depends on the src array, it is not static.
As I see you compute a multiplier for Intensity, Value, Saturation and you use these values to equalize the full data. So you just need to create a 1x3 matrix, fill it with intensity, saturation, value and call cv::transform!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.