2013-07-03 30 views
0

這裏是我完全不瞭解的功能,我想完全理解:在C使用無符號的字符數據表示

/** 
* Returns: the label of a vertex in the given image at location (x, y). 
*   0 = unlabeled vertex at location (x, y) 
*   1 = background label at location (x, y) 
*   2 = object/foreground label at location (x, y) 
*/ 
int getLabelAtVertexXY(IplImage* image, int x, int y) { 
uchar* data = (uchar*) image->imageData + y * image->widthStep + 3 * x; 
if (data[2] < 128 && data[1] < 128) 
    return 0; 
else if (data[1] > data[2]) 
    return 1; // TODO: data[1] holds probability in background starting at 128-255? 
else 
    return 2; 
} 

這裏是我得到:圖像的每個像素被標記爲0,1或2.這些信息如何被存儲在unsigned char指針data

我意識到一個unsigned char可以代表從0到255的數字,但unsigned char確實檢索?

+1

像素可以具有0-255的值(這可以方便地適合單個無符號字節) –

+0

您沒有足夠的代碼。在某處,可能在IplImage的定義中,解釋了imageData的字節編碼。 –

回答

1

要理解信息如何存儲,您需要實現IplImage。

data實際上是一個指向unsigned char的指針。沒有人說它只有1個字符。它可能是一些字符。所以data [1]是數組中的第2個元素。

此外,根據我+操作員不做數字的總和,它使和指針地址。

1

看起來像該圖像中的每個像素是3個字節(當設置數據指針時由3 * x表示)。所以數據[0],數據[1],數據[2]都是那3個字節,每個都是0到255之間的無符號整數?

相關問題