编程语言
首页 > 编程语言> > python – 在opencv matchtemplate源代码中使用什么方法来处理彩色图像?

python – 在opencv matchtemplate源代码中使用什么方法来处理彩色图像?

作者:互联网

07c的opencv matchtemplate说明了这一点

In case of a color image, template summation in the numerator and each sum in the denominator is done over all of the channels and separate mean values are used for each channel. That is, the function can take a color template and a color image. The result will still be a single-channel image, which is easier to analyze.

我无法弄清楚这意味着什么.对于颜色模板和彩色图像,单通道图像(结果)是所有通道的平均结果吗?

templmatch.cpp源代码:github

解决方法:

查看matchTemplate中使用的convolve_32F函数的源代码,在应用图像和模板之间的卷积之前,似乎彩色图像上的模板匹配实际上将彩色图像和颜色模板转换为具有三倍列的灰色图像.灰度图像.

为了说明如何转换为灰度图像,请考虑以下2×2图像,其中包含4个颜色像素(使用BGR值编写):

(1, 2, 3) (4, 5, 6)
(7, 8, 9) (10,11,12)

它成为以下2×6灰色图像:

(1)  (2)  (3)  (4)  (5)  (6)
(7)  (8)  (9)  (10) (11) (12)

它们执行卷积,就像它是灰色图像一样,然后通过在结果图像中取三个中的一个值来提取结果(相当于提取彩色图像的第一个通道).

标签:python,image,opencv,colors,matchtemplate
来源: https://codeday.me/bug/20190701/1346692.html