唐山建設(shè)工程造價(jià)信息網(wǎng)站自己創(chuàng)建網(wǎng)站
背景
今天,在使用模板匹配的時(shí)候,突然程序卡死,CPU直接飆到100%。最后排查發(fā)現(xiàn)是模板匹配其中一個(gè)參數(shù) NumLevels?導(dǎo)致的:
NumLevels:
The number of pyramid levels used during the search is determined with numLevels. If necessary, the number of levels is clipped to the range given when the shape model was created with CreateShapeModel. If numLevels is set to 0, the number of pyramid levels specified in CreateShapeModel is used.?
大致意思是:
NumLevels: 搜索期間使用的金字塔級(jí)別數(shù)由 numLevels 確定。
CreateShapeModel 創(chuàng)建形狀模型時(shí)會(huì)有一個(gè)范圍,(我平時(shí)使用的是”auto“)
如果 numLevels 設(shè)置為 0,則使用 CreateShapeModel 中指定的金字塔等級(jí)數(shù)。
什么是金字塔級(jí)數(shù)
現(xiàn)在來理解一下金字塔:
?這樣看,其實(shí)金字塔就是對(duì)圖片做卷積,也就是特征的提取,金字塔級(jí)數(shù)越大,抽取的特征越抽象,判定的速度就越快。
卡死的原因
卡死的原因是我,使用find_scaled_shape_model是我將 NumLevels 設(shè)置為1。
后面,將其設(shè)置為0后,就不卡了,后續(xù)我設(shè)置成2,依舊會(huì)卡但是沒卡死。設(shè)置成3和4,就變得快了。
小結(jié)
- ? ?如果圖片比較大(比如有十幾兆到上百兆),NumLevels 最好不要為1。
- ? ?在創(chuàng)建模板時(shí)(CreateShapeModel),就要規(guī)劃好金字塔層數(shù)??梢允褂胊uto 關(guān)鍵字。
- ? ?模板匹配時(shí)(find_scaled_shape_model),如果 numLevels 設(shè)置為 0,則使用 CreateShapeModel 中指定的金字塔等級(jí)數(shù)。