简体   繁体   中英

How to lighten a rectangle with opencv for android

I'm using OpenCV for Android and I wonder how to lighten a rectangle surface in a Mat object.

I write this function that add 30 to each RGB component of each pixel in the area., it works the way I expected but very too slowly.

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat frame = inputFrame.rgba();
    int h = 300;
    int w = (int) ((int) ( (float) h ) * 1.5);

    return drawRectangle(frame, h, w);
}

private Mat drawRectangle(Mat frame, int h, int w){
    for( int y = (frame.rows() - h) / 2 ; y < (frame.rows() + h) / 2 ; y++ ) { 
        for( int x = (frame.cols() - w) / 2; x < (frame.cols() + w) / 2; x++ ) {
            for( int c = 0; c < 3; c++ ) {
                double[] color = frame.get(y, x);
                for(int i = 0; i < 3; i++)
                    color[i] += 30;

                frame.put(y, x, color);

            }
        }
    }
    return frame;
}

I'm sure there is a way to do this instantly (I've seen example of b&w, negative effects instantly processed) but I'm not so familiar with OpenCv and Android, I guess I don't know the philosophy yet.

Access area directly with a CvRect and use the overloaded + :

cv::Mat img;
int x,y,w,h,inc;
img(cv::Rect(x, y, w, h))+=cvScalar(inc,inc,inc);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM