[OpenCV]縮放PNG圖像,保持透明背景

關鍵代碼如下

(主要就是關鍵就是resize(srcImage, destImage, destSize, CV_INTER_LINEAR)這句,要用參數CV_INTER_LINEAR)

#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
using namespace cv;

//以上是從我自己測試demo複製出來的,有些頭文件可以不用


static Mat resizePicture(string filePath, Size destSize) {

	Mat srcImage = imread(filePath, IMREAD_UNCHANGED); 
	Mat destImage = Mat(destSize, srcImage.type());
    //關鍵就是這句,要用參數CV_INTER_LINEAR
	resize(srcImage, destImage, destSize, CV_INTER_LINEAR);
	return destImage;

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章