This article describes the Python implementation according to the icon to extract the classification application, share to everyone for your reference.
Here's how:
#!/usr/bin/python #-*-coding:utf-8-*-import Image import win32ui import Win32gui def make_regalur_image (img, size = (at ()): Return img.resize (Size). CONVERT (' RGB ') def split_image (img, part_size = (up, UP)): 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_simil AR (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 (Imag E.open (LF)), Make_regalur_image (Image.open (RF)) Li.save (lf + ' _regalur.png ') ri.save (rf + ' _regalur.png ') fd = open (' Stat.csv ', ' W ') Fd.wri Te (' \ 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, p, p): Draw.line ((0, I,, i), fill = ' #ff0000 ') draw.line ((i, 0, I,), 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, +, +) 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.jp G '% (I, 1), ' test/test%d/%d.jpg '% (I, 2)) *100) # make_doc_data (' test/test4/1.jpg ', ' test/test4/2.jpg ')
Hopefully this article will help you with Python programming.