如何在Android的OpenCV的执行图像RGB归? [英] How to perform Image RGB Normalization in Android OpenCV?

查看:240
本文介绍了如何在Android的OpenCV的执行图像RGB归?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行图像归一化,使用的OpenCV 2.4.8为Android。我的测试设备是三星S3。

我已经写了JNI函数如下图所示进行图像归。

我的图像正常化的定义如下:

  R'是255 * R /(R + G + B)
g'为255 *克/(R + G + B)
b为255 * B /(R + G + B)

现在我需要实现这一点。而我写一个函数来执行此。这似乎没有工作。我相信我的我的应用程序的其他部分(即它们是无bug)。只有这部分导致了问题。

我可能没有正确地写入此功能。请帮助。

我还附上我的结果的截图。如果你看一下这个图片,只是半部分看起来规范化(但它实际上不是标准化的,它只是看起来是这样)及另一半则不是。为了解决这个问题,我试图改变在for循环与COLS行,结果是一样的。

在code这也是presented。

期待一些帮助。 (仅供参考 - 我完全陌生的OpenCV)。感谢您的谅解。

 无效NormalizeRGB(JNIEnv的*,jobject,jlong​​ IMG)
{
    垫&安培; IMGM = *(*垫)IMG;
    矢量<&垫GT; RGB;
    INT COLS = imgM.cols;
    诠释行= imgM.rows;
    的for(int i = 0; I<行;我++)
    {
        对于(INT J = 0; J< COLS; J ++)
        {
            Vec3b bgrPixel = imgM.at&所述; Vec3b>(I,J);
            浮总= bgrPixel.val [0] + bgrPixel.val [1] + bgrPixel.val [2] + 0.00001;
            bgrPixel.val [0] =(UCHAR)255 * bgrPixel.val [0] /总;
            bgrPixel.val [1] =(UCHAR)255 * bgrPixel.val [1] /总;
            bgrPixel.val [2] =(UCHAR)255 * bgrPixel.val [2] /总;
            imgM.at&所述; Vec3b>(I,J)= bgrPixel;
        }
    }
}


解决方案

我找到了解决我的问题。

我试图用这个功能来读取一个RGBA矩阵图像。一个RGBA矩阵图像类型Vec4的。

我想读它作为一个VEC3〜这曾经导致上述问题。

有了这个小小的改变,我能得到我预期的结果。

I am trying to perform image normalization, using OpenCV 2.4.8 for Android. My test device is a samsung S3.

I have written a JNI function as shown below to perform Image Normalization.

My definition of Image Normalization is as follows :

r' is 255* r/(r+g+b)
g' is 255* g/(r+g+b)
b' is 255* b/(r+g+b)

Now I need to implement this. And I have written a function to perform this. This doesnt seem to work. I am confident of my other portions of my App (i.e. they are bug free). Only this part causes a problem.

I may have not written this function properly. Pls help.

I have also attached a screenshot of my result. If you look at this image, only half portion looks normalized (but its actually not normalized, it just looks that way) & the other half is not. To fix this, I tried changing the rows with cols in the for-loop, and the result was the same.

The code for this is also presented.

Looking forward to some help. (FYI - I am totally new to openCV). Thanks for understanding.

void NormalizeRGB(JNIEnv*, jobject, jlong img)
{
    Mat& imgM  = *(Mat*)img;
    vector<Mat> rgb;
    int cols = imgM.cols;
    int rows = imgM.rows;
    for(int i = 0; i<rows; i++)
    {
        for(int j = 0; j<cols; j++)
        {
            Vec3b bgrPixel = imgM.at<Vec3b>(i, j);
            float total = bgrPixel.val[0] + bgrPixel.val[1] + bgrPixel.val[2] + 0.00001;
            bgrPixel.val[0] = (uchar) 255*bgrPixel.val[0]/total;
            bgrPixel.val[1] = (uchar) 255*bgrPixel.val[1]/total;
            bgrPixel.val[2] = (uchar) 255*bgrPixel.val[2]/total;
            imgM.at<Vec3b>(i, j) = bgrPixel;
        }
    }
}

解决方案

I found the solution to my problems.

I was trying to use this function to read an RGBA Matrix image. A RGBA Matrix image is of type Vec4.

I was trying to read it as a Vec3 ~ this used to cause the above problem.

With this small change, I was able to get my expected results.

这篇关于如何在Android的OpenCV的执行图像RGB归?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆