'Roi'에 해당되는 글 1건

  1. 2013.01.08 ROI, widthStep를 이용하여 영상의 특정부분만 처리

ROI

 #include <cv.h>

#include <highgui.h>

 

int main(int argc, char ** argv) {

        IplImage* src;

 

        if(argc==7 && ((src=cvLoadImage(argv[1], 1))!=0)) {

               int x=atoi(argv[2]);

               int y=atoi(argv[3]);

               int width=atoi(argv[4]);

               int height=atoi(argv[5]);

               int add=atoi(argv[6]);

 

               cvSetImageROI(src, cvRect(x, y, width, height));

               cvAddS(src, cvScalar(add), src);

               cvResetImageROI(src);

 

               cvNamedWindow("Roi_Add", 1);

               cvShowImage("Roi_Add", src);

               cvWaitKey();

 

               cvReleaseImage(&src);

               cvDestroyWindow("Roi_Add");

        }

 

        return 0;

}


widthStep

 #include <cv.h>

#include <highgui.h>

 

int main(void) {

        IplImage *interest_img;

        CvRect interest_rect;

 

        interest_img=cvLoadImage("lueseypid.jpg", 1);

        interest_rect=cvRect(180, 100, 100, 100);

       

        IplImage* sub_img=cvCreateImageHeader(

               cvSize(

                       interest_rect.width,

                       interest_rect.height

               ),

               interest_img->depth,

               interest_img->nChannels

        );

 

        sub_img->origin=interest_img->origin;

        sub_img->widthStep=interest_img->widthStep;

 

        sub_img->imageData=interest_img->imageData +

               interest_rect.y * interest_img->widthStep +

               interest_rect.x * interest_img->nChannels;

 

        cvAddS(sub_img, cvScalar(150), sub_img);

 

        cvReleaseImageHeader(&sub_img);

 

        cvNamedWindow( "WidthStep", CV_WINDOW_AUTOSIZE );

        cvShowImage( "WidthStep", interest_img );

        cvWaitKey();

}


ROI를 설정 또는 해제하여 사용하는 방법이 더 편리하지만, 굳이 widthStep 이용방법을 사용해야하는 이유?

widthStep을 이용하면 관심 영역을 여러개 지정하여 영상 처리를 할 수 있기 때문이다. ROI를 사용하면 관심 영역을 순차적으로 설정 및 해제를 하여 영상 처리를 수행한다.

'Developer > OpenCV' 카테고리의 다른 글

HighGUI  (0) 2013.01.09
행렬과 영상에 관한연산 함수  (0) 2013.01.08
OpenCV의 기본 데이터타입  (0) 2013.01.04
사진에 스무딩효과(가우시안) 주기  (0) 2013.01.03
OpenCV 정지영상, 동영살 출력하기  (1) 2013.01.03
Posted by No names
,