05-14 00:11
Notice
Recent Posts
Recent Comments
관리 메뉴

Scientific Computing & Data Science

[OpenCV] Image Pointer(ptr)를 이용하여 픽셀 접근하기 본문

Programming/OpenCV

[OpenCV] Image Pointer(ptr)를 이용하여 픽셀 접근하기

cinema4dr12 2015. 3. 1. 23:05

이미지의  row(행) 번호 j에 대한 첫번째 열의 픽셀 데이터 포인터는 다음과 같습니다:


uchar* data= image.ptr<uchar>(j);


이를 이용한 픽셀 처리에 대한 예제 코드는 다음과 같습니다:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// open the image
cv::Mat image = cv::imread( IMAGE_FILE_PATH );
 
// number of lines
int nl = image.rows;
 
// total number of elements per line
int nc = image.cols * image.channels();
 
for ( int j = 0; j < nl; j++ ) {
    // get the address of row j
    uchar* data = image.ptr<uchar>( j );
    
    for ( int i = 0; i < nc ; i++ ) {
        // process each pixel ---------------------
        data[ i ] = ...   ;
        // end of pixel processing ----------------
    } // end of line
}
cs


Comments