阅读背景:

封装了opencv的旋转图像函数

来源:互联网 
void ljb_cv_rotate_buf_size(IplImage *imgSrc, double degree, int *w_dst, int *h_dst)
{    
    double angle, a, b;
    int    w_src, h_src;

    angle = degree  * CV_PI / 180.;
    a = sin(angle), b = cos(angle); 

    w_src = imgSrc->width;
    h_src = imgSrc->height;

    *w_dst = (int)(h_src * fabs(a) + w_src * fabs(b));
    *h_dst = (int)(w_src * fabs(a) + h_src * fabs(b));
}

void ljb_cv_rotate(IplImage *imgSrc, IplImage *imgDst, double degree)
{    
    double angle, a, b;
    int    w_src, h_src, w_dst, h_dst;
    double map[6];
    CvMat  map_matrix = cvMat(2, 3, CV_64FC1, map);
    CvPoint2D32f pt = {0};

    angle = degree  * CV_PI / 180.; 
    a = sin(angle), b = cos(angle); 

    w_src = imgSrc->width;
    h_src = imgSrc->height;

    w_dst = imgDst->width;
    h_dst = imgDst->height;

    pt = cvPoint2D32f(w_src / 2, h_src / 2);
    cv2DRotationMatrix(pt, degree, 1.0, &map_matrix);//旋转中心,角度,尺度,生成2*3旋转矩阵

    // Adjust rotation center to dst's center,
    // otherwise you will get only part of the result
    map[2] += (w_dst - w_src) / 2;
    map[5] += (h_dst - h_src) / 2;

    cvWarpAffine(
        imgSrc, 
        imgDst,
        &map_matrix,
        CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS,
        cvScalarAll(0)
        );  
}
void ljb_cv_rotate_buf_size(IplImage *imgSr



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: