---
讀取影像 - imread
Mat imread(const String& filename, int flags=IMREAD_COLOR )
filename: 檔案名稱flags: 讀取的方法
CV_LOAD_IMAGE_ANYDEPTH
If set, return 16 - bit / 32 - bit image when the input has the corresponding depth,
otherwise convert it to 8 - bit.
如果圖片有相應的深度值,回傳16 - bit / 32 - bit影像
若沒有則轉成8 - bit影像
CV_LOAD_IMAGE_COLOR
If set, always convert image to the color one
讀取彩色影像
CV_LOAD_IMAGE_GRAYSCALE
If set, always convert image to the grayscale one
讀取灰階影像
顯示影像-imshow
void imshow(const String& winname, InputArray mat)
winname:視窗名稱
mat: 欲顯示的影像
儲存影像-imwrite
bool imwrite(const String& filename, InputArray img, const vector<int>& params=vector<int>() )
filename: 檔案名稱img: 欲儲存的影像
範例
使用圖片:---
#include "opencv2\opencv.hpp"
int main()
{
cv::Mat img;
img = cv::imread("rabbit.jpg", CV_LOAD_IMAGE_COLOR); //讀檔(彩色)
cv::imshow("show rabbit", img); //顯示圖片在叫做"show rabbit"的視窗
cv::Mat img_gray;
img_gray = cv::imread("rabbit.jpg", CV_LOAD_IMAGE_GRAYSCALE); //讀檔(灰階)
cv::imshow("show gray rabbit", img_gray); //顯示圖片在叫做"show gray rabbit"的視窗
cv::imwrite("gray_rabbit.jpg", img_gray); //把讀成灰階檔的圖片存起來
cv::waitKey(0); //讓視窗暫停直到下次按下鍵盤任意鍵
}
---
No comments:
Post a Comment