本文介绍了在Android中使用OpenCV从CameraFrame检测RGB的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测RGB中最大的值.我怎么能发现呢?我想显示哪种颜色出现的次数最多RGB值.例如,在图像中,红色的出现率最高,因此它将显示为红色,其值以百分比表示.

I want to detect which value is maximum from RGB. how can I detect that?I want to display which colour has highest occurrence with theirRGB value. For example, In a image the RED colour has highest occurrence so it will display colour as RED and with their value in percentage.

我已经尝试通过获取图像的行和列来进行尝试,如下所示:

I have tried it by getting rows and cols of image like below:

   public Mat onCameraFrame(CvCameraViewFrame cvf) {
        mRgba = cvf.rgba();

        int rows = mRgba.rows();
        int cols = mRgba.cols();
       // int ch = mRgba.channels();
        double R=0,G=0,B=0;

        for (int i=0; i<rows; i++)
        {
            for (int j=0; j<cols; j++)
            {
                double[] data = mRgba.get(i, j); //Stores element in an array
                R = data[0];
                G= data[1];
                B = data[2];
            }
        }

        Imgproc.putText(mRgba,"R:"+R + "G:"+G +"B:"+B,new Point(10,52),Core.FONT_HERSHEY_COMPLEX,.7,new Scalar(5,255,255), 2,8,false );
return mRgba;
}

,但是要花很多时间,并且屏幕滞后,因为我已经在onCameraFrame中实现了代码.那么如何用这种方法快速检测到它,哪种是最好的方法呢?

but it is taking to much time and screen is lagging because I have implemented code in onCameraFrame. So how can I detect it fast in this method and which is the best way to it?

谢谢.

推荐答案

将图像分为R,G和B通道,并计算每个Mat的总和.

Split the image into its R, G and B channels, and compute the sum of each Mat.

vector<Mat> channels;
split(mRgba, channels);
B = sum(channels[0])[0];
G = sum(channels[1])[0];
R = sum(channels[2])[0];

比较R,G和B的值,以了解帧中哪种颜色出现最多.

Compare the values of R, G and B to know which colour has occurred the most in the frame.

这篇关于在Android中使用OpenCV从CameraFrame检测RGB的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:44
查看更多