opencv-压缩图片

使用cvResize函数压缩图片。
//dResizeFactor 缩放比例
//interpolation 插值方式 CV_INTER_NN = 0,CV_INTER_LINEAR = 1,CV_INTER_CUBIC = 2,CV_INTER_AREA = 3,CV_INTER_LANCZOS4 = 4
示例代码如下:

IplImage* m_lpiImage = NULL;
IplImage* ImageResize(IplImage* src, double dResizeFactor, int interpolation /*= CV_INTER_LINEAR*/)
{
    //IplImage *imgResize = 0;
    if (m_lpiImage)
    {
        cvReleaseImage(&m_lpiImage);
        m_lpiImage = NULL;
    }

    if (!src)
    {
        printf("error:image is null\n");
        return m_lpiImage;
    }

    if (dResizeFactor < 1e-7)
    {
        printf("error:dResizeFactor is < 0\n");
        return m_lpiImage;
    }

    m_lpiImage = cvCreateImage(cvSize(src->width*dResizeFactor, src->height*dResizeFactor), IPL_DEPTH_8U, 3);
    printf("resize image\n");
    cvResize(src, m_lpiImage, interpolation);

    return m_lpiImage;
}

你可能感兴趣的:(C++,压缩,图片,opencv)