我的通道分离计算是否正确?

时间:2017-02-23 20:11:24

标签: java opencv hsv

我有HSV图像,我对图像的某个区域感兴趣。我已经让图像选择工作并确定我感兴趣的区域,但我不认为我分离我的频道的方式是正确的。我的频道值并没有接近它们的实际值。我看到的图像部分是RGB刻度的白色。我知道在HSV中,白色的饱和度大约为(0..20),值为(230..255),但程序打印的数字并不接近该范围。我得到一个高40低50为S和-93主要是为V.我的频道计算是否正确?

CURLOPT

这是我的形象:

enter image description here

感兴趣的区域是中间的左上方贴纸,但它们都是白色的。

该程序为此打印的HSV是:

public void splitChannels() {

    Mat firstImage = Imgcodecs.imread("firstImage.jpg");
    int width = 20;
    int height = 20;
    Rect roi = new Rect(120, 160, width, height);
    Mat smallImg = new Mat(firstImage, roi);
    int channels = smallImg.channels();
    System.out.println("small pixels:" + smallImg.total());
    System.out.println("channels:" + smallImg.channels());
    int totalBytes = (int)(smallImg.total() * smallImg.channels());
    byte buff[] = new byte[totalBytes];
    smallImg.get(0, 0, buff);

    for (int i=0; i< height; i++) {
        // stride is the number of bytes in a row of smallImg
        int stride = channels * width;
        for (int j=0; j<stride; j+=channels) {
        //I don't know if these channels calculations are correct.
            int h = buff[(i * stride) + j];
            int s = buff[(i * stride) + j + 1]; 
            int v = buff[(i * stride) + j + 2];

            // Do something with the hsv.
            System.out.println("s: "+ s + " v: " + v);

        } 
    }
}

0 个答案:

没有答案