opencv重新调整图片大小

//1.Mat转化,感觉这是个笨方法,通过转IplImage

Mat MyResizeImage(Mat pSrc, double dScale)
{
    IplImage *pImgSrc = &IplImage(pSrc);
    CvSize size;
    size.width = pImgSrc->width*dScale;
    size.height = pImgSrc->height*dScale;
    IplImage *pDes = cvCreateImage(size, pImgSrc->depth, pImgSrc->nChannels);
    cvResize(pImgSrc, pDes, CV_INTER_CUBIC);
    Mat matDes = cvarrToMat(pDes, true);
    cvReleaseImage(&pDes);
    //cvReleaseImage(&pImgSrc);
    return matDes;
}

//2.IplImage调整大小

IplImage* MyResizeImage(IplImage* pSrc, double dScale)
{
    CvSize size;
    size.width = pSrc->width*dScale;
    size.height = pSrc->height*dScale;
    IplImage *pDes = cvCreateImage(size, pSrc->depth, pSrc->nChannels);
    cvResize(pSrc, pDes, CV_INTER_CUBIC);
    return pDes;
}

//3.Mat直接转化

cv::Mat MyResizeImage(double dScale, Mat pSrc)
{
    Size sSize = Size(pSrc.cols*dScale, pSrc.rows*dScale);
    Mat pDes = Mat(sSize, CV_32S);
    resize(pSrc, pDes, sSize);
    return pDes;
}

 

你可能感兴趣的:(C++探究,OpenCV,图片合成,图像识别,opencv,大小调整)