简体   繁体   English

如何使用opencv为Android照亮矩形

[英]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. 我正在使用适用于Android的OpenCV,我想知道如何减轻Mat对象中的矩形表面。

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. 我编写了此函数,将30加到区域中每个像素的每个RGB组件中。它按我预期的方式工作,但速度太慢。

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. 我敢肯定有一种方法可以立即执行此操作(我已经看到了黑白的示例,可以立即处理负面影响),但是我对OpenCv和Android不太熟悉,我想我还不知道这种哲学。

Access area directly with a CvRect and use the overloaded + : 使用CvRect直接访问区域并使用重载的+

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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