Archive

Archive for the ‘OpenCV’ Category

ROI

2011-03-17 1 comment

IplImage* cvGetSubImage(IplImage *image, CvRect roi)
{
    IplImage *result;
    // 设置 ROI
    cvSetImageROI(image,roi);//基于给定的矩形设置感兴趣区域

    // 创建子图像
    result = cvCreateImage( cvSize(roi.width, roi.height), image->depth, image->nChannels );
    cvCopy(image,result);//将图像复制给子图像
    cvResetImageROI(image);//释放图像的ROI

    return result;//返回子图像
}

Advertisements
Categories: OpenCV

For future use —— data structure

typedef struct
{
CvCapture*    capture;
CvSize frame_size;
int start_frame;
int end_frame;
char *trk_file;
}InputInfo;

Categories: OpenCV

Draw text in frames

CvFont font;

cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX, 0.7f, 0.7f, 0, 2, 12);

char s[20] = {0};

sprintf(s,”%d”, ind);

CvScalar line_color = CV_RGB(0, 0, 255);

CvPoint center = cvPoint(x, y);

cvPutText(frame1, s, center, &font, line_color);

Categories: OpenCV

Get elements of IplImage

/* get reference to pixel at (col,row),
   for multi-channel images (col) should be multiplied by number of channels */
#define CV_IMAGE_ELEM( image, elemtype, row, col )       \
    (((elemtype*)((image)->imageData + (image)->widthStep*(row)))[(col)])

Categories: OpenCV