LKY 只有原創內容的 Blog

今之能者,謂能轉貼,至於魯蛇,皆能轉貼。不原創,何以別乎?

Open CV 2.0 四種複製 cv::Mat 型別影像的方法(How to copy cv::Mat)

Lin, Kao-Yuan's Avatar 2013-05-18

這次要談複製 cv::Mat 型別影像的方式,方法有好幾種,用以下這段程式碼當作例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
Theme: How to copy cv::Mat
Compiler: MSVC 2010 Pro
Library: OpenCV 2.0
Date: 2013/05/19
Author: Lin Kao-Yuan
Blog: https://mosdeo.wordpress.com/
*/
cv::Mat RawImg,AssignImg,AssignToImg,CloneImg,copyToImg;

void main(void)
{
//載入原影像
RawImg=cv::imread("YangEMail.jpg");
cv::resize(RawImg,RawImg,cv::Size(RawImg.cols/2,RawImg.rows/2));
cv::imshow("RawImg",RawImg);
cv::moveWindow("RawImg",0,0);

//四種複製RawImg的方法
AssignImg=RawImg;
cv::imshow("AssignImg",AssignImg);
cv::moveWindow("AssignImg",RawImg.cols,0);

RawImg.assignTo(AssignToImg);
cv::imshow("AssignToImg",AssignToImg);
cv::moveWindow("AssignToImg",RawImg.cols*2,0);

CloneImg=RawImg.clone();
cv::imshow("CloneImg",CloneImg);
cv::moveWindow("CloneImg",RawImg.cols*3,0);

RawImg.copyTo(copyToImg);
cv::imshow("copyToImg",copyToImg);
cv::moveWindow("copyToImg",RawImg.cols*4,0);

cv::waitKey(0);
}

不知道這四種複製方法有什麼不同呢?

This article was last updated on days ago, and the information described in the article may have changed.