이미지 가운데에 흰색 선긋기 예제



c++)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <opencv/cv.h>
#include <opencv/highgui.h>
 
 
void main() {
    IplImage *image;
 
    image = cvLoadImage("D:/study/testimage.jpg"-1);
 
    int height = image->height;    //영상 높이(단위 : 픽셀)
    int width = image->width;    //영상 너비(단위 : 픽셀)
    int channel = image->nChannels;    //영상 채널
    uchar* data = (uchar*)image->imageData; //영상데이터의 포인터    
 
 
    //가운도에 흰선을 긋는다
    int line = width/2;
 
    //크기 (m x n) , 위치 (i x j) , 채널 k번째 영상의 1차원 배열인덱스 구하는 공식
    //index = j*m*채널수 + i*채널수 + k
    for (int h = 0; h < height; h++) {
        for (int w = 0; w < width; w++) {
            for (int c = 0; c < channel; c++) {
                if (w == line) {
                    data[h*width*channel + w*channel + c] = 255;
                }
            }
        }
    }
 
    cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
    cvShowImage("image", image);    //윈도우에 이미지 출력
 
    cvWaitKey(0);
 
    cvReleaseImage(&image);
}
cs



결과




+ Recent posts