也如此處所述:Difference Clone CopyTo,在這種情況下,在clone()
和copyTo()
之間沒有區別。
事實上,對於clone()
源代碼如下:
inline Mat Mat::clone() const
{
Mat m;
copyTo(m);
return m;
}
copyTo
然而可以聯合使用用掩模,並且一般將數據複製到另一矩陣,因此可以是例如到有用繪製一個子圖像到另一個圖像。
關於用於watershed
的代碼中,文檔狀態,
- 圖像 - 輸入8位3通道圖像。
- 標記 - 輸入/輸出標記的32位單通道圖像(地圖)。它應該具有與圖像相同的尺寸。
所以image
(您image
)和markers
(您result
)不應該是相同的。
Before passing the image to the function, you have to roughly outline the desired regions in the image markers with positive (>0) indices. So, every region is represented as one or more connected components with the pixel values 1, 2, 3, and so on. Such markers can be retrieved from a binary mask using findContours() and drawContours() (see the watershed.cpp demo). The markers are 「seeds」 of the future image regions. All the other pixels in markers , whose relation to the outlined regions is not known and should be defined by the algorithm, should be set to 0’s. In the function output, each pixel in markers is set to a value of the 「seed」 components or to -1 at boundaries between the regions.
Visual demonstration and usage example of the function can be found in the OpenCV samples directory (see the watershed.cpp demo).
無需克隆()或複製圖像*在所有*,甚至是錯誤的。只需將結果留空,並確保您的輸入img是24位bgr(CV_8UC3)。 – berak