How to resize an image to a specific size in OpenCV?

前端 未结 5 1403
北荒
北荒 2020-12-05 13:19
IplImage* img = cvLoadImage(\"something.jpg\");
IplImage* src = cvLoadImage(\"src.jpg\");
cvSub(src, img, img);

But the size of the source image is

相关标签:
5条回答
  • 2020-12-05 13:57

    You can use CvInvoke.Resize for Emgu.CV 3.0

    e.g

    CvInvoke.Resize(inputImage, outputImage, new System.Drawing.Size(100, 100), 0, 0, Inter.Cubic);
    

    Details are here

    0 讨论(0)
  • 2020-12-05 14:02

    Make a useful function like this:

    IplImage* img_resize(IplImage* src_img, int new_width,int new_height)
    {
        IplImage* des_img;
        des_img=cvCreateImage(cvSize(new_width,new_height),src_img->depth,src_img->nChannels);
        cvResize(src_img,des_img,CV_INTER_LINEAR);
        return des_img;
    } 
    
    0 讨论(0)
  • 2020-12-05 14:06

    The two functions you need are documented here:

    1. imread: read an image from disk.
    2. Image resizing: resize to just any size.

    In short:

    // Load images in the C++ format
    cv::Mat img = cv::imread("something.jpg");
    cv::Mat src = cv::imread("src.jpg");
    
    // Resize src so that is has the same size as img
    cv::resize(src, src, img.size());
    

    And please, please, stop using the old and completely deprecated IplImage* classes

    0 讨论(0)
  • 2020-12-05 14:06

    For your information, the python equivalent is:

    imageBuffer = cv.LoadImage( strSrc )
    nW = new X size
    nH = new Y size
    smallerImage = cv.CreateImage( (nH, nW), imageBuffer.depth, imageBuffer.nChannels )
    cv.Resize( imageBuffer, smallerImage , interpolation=cv.CV_INTER_CUBIC )
    cv.SaveImage( strDst, smallerImage )
    
    0 讨论(0)
  • 2020-12-05 14:07

    You can use cvResize. Or better use c++ interface (eg cv::Mat instead of IplImage and cv::imread instead of cvLoadImage) and then use cv::resize which handles memory allocation and deallocation itself.

    0 讨论(0)
提交回复
热议问题