本文实例讲述了python实现根据图标提取分类应用程序,分享给大家供大家参考。
具体方法如下:
#!/usr/bin/python # -*- coding: utf-8 -*- import Image import win32ui import win32gui def make_regalur_image(img, size = (256, 256)): return img.resize(size).convert('RGB') def split_image(img, part_size = (64, 64)): w, h = img.size pw, ph = part_size assert w % pw == h % ph == 0 return [img.crop((i, j, i+pw, j+ph)).copy() \ for i in xrange(0, w, pw) \ for j in xrange(0, h, ph)] def hist_similar(lh, rh): assert len(lh) == len(rh) return sum(1 - (0 if l == r else float(abs(l - r))/max(l, r)) for l, r in zip(lh, rh))/len(lh) def calc_similar(li, ri): # return hist_similar(li.histogram(), ri.histogram()) return sum(hist_similar(l.histogram(), r.histogram()) for l, r in zip(split_image(li), split_image(ri))) / 16.0 def calc_similar_by_path(lf, rf): li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf)) return calc_similar(li, ri) def make_doc_data(lf, rf): li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf)) li.save(lf + '_regalur.png') ri.save(rf + '_regalur.png') fd = open('stat.csv', 'w') fd.write('\n'.join(l + ',' + r for l, r in zip(map(str, li.histogram()), map(str, ri.histogram())))) # print >>fd, '\n' # fd.write(','.join(map(str, ri.histogram()))) fd.close() import ImageDraw li = li.convert('RGB') draw = ImageDraw.Draw(li) for i in xrange(0, 256, 64): draw.line((0, i, 256, i), fill = '#ff0000') draw.line((i, 0, i, 256), fill = '#ff0000') li.save(lf + '_lines.png') def getIcon(filename): large, small = win32gui.ExtractIconEx(filename,0)# win32gui.DestroyIcon(small[0]) hdc = win32ui.CreateDCFromHandle( win32gui.GetDC(0) ) hbmp = win32ui.CreateBitmap() hbmp.CreateCompatibleBitmap( hdc, 32, 32 ) hdc = hdc.CreateCompatibleDC() hdc.SelectObject( hbmp ) hdc.DrawIcon( (0,0), large[0] ) hbmp.SaveBitmapFile( hdc, "save.bmp" ) if __name__ == '__main__': #path = r'test/TEST%d/%d.JPG' for i in range(1,4): getIcon(r'test/TEST1/%d.exe' % i) print 'RESULT:%d' % (calc_similar_by_path('save.bmp',r"test/TEST1/backup.bmp")*100) #for i in xrange(1, 7): #print 'test_case_%d: %.3f%%'%(i, \ #calc_similar_by_path('test/TEST%d/%d.JPG'%(i, 1), 'test/TEST%d/%d.JPG'%(i, 2))*100) # make_doc_data('test/TEST4/1.JPG', 'test/TEST4/2.JPG')
希望本文所述对大家的Python程序设计有所帮助。

Pythonarrayssupportvariousoperations:1)Slicingextractssubsets,2)Appending/Extendingaddselements,3)Insertingplaceselementsatspecificpositions,4)Removingdeleteselements,5)Sorting/Reversingchangesorder,and6)Listcomprehensionscreatenewlistsbasedonexistin

NumPyarraysareessentialforapplicationsrequiringefficientnumericalcomputationsanddatamanipulation.Theyarecrucialindatascience,machinelearning,physics,engineering,andfinanceduetotheirabilitytohandlelarge-scaledataefficiently.Forexample,infinancialanaly

useanArray.ArarayoveralistinpythonwhendeAlingwithHomoGeneData,performance-Caliticalcode,orinterfacingwithccode.1)同質性data:arraysSaveMemorywithTypedElements.2)績效code-performance-calitialcode-calliginal-clitical-clitical-calligation-Critical-Code:Arraysofferferbetterperbetterperperformanceformanceformancefornallancefornalumericalical.3)

不,notalllistoperationsareSupportedByArrays,andviceversa.1)arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing,wheremactsperformance.2)listssdonotguaranteeconecontanttanttanttanttanttanttanttanttanttimecomplecomecomplecomecomecomecomecomecomplecomectacccesslectaccesslecrectaccesslerikearraysodo。

toAccesselementsInapythonlist,useIndIndexing,負索引,切片,口頭化。 1)indexingStartSat0.2)否定indexingAccessesessessessesfomtheend.3)slicingextractsportions.4)iterationerationUsistorationUsisturessoreTionsforloopsoreNumeratorseforeporloopsorenumerate.alwaysCheckListListListListlentePtotoVoidToavoIndexIndexIndexIndexIndexIndExerror。

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

Dreamweaver Mac版
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具