The example of this article tells the Python implementation according to the icon to extract the classification application, share for everyone to reference.
The specific methods are as follows:
#!/usr/bin/python #-*-coding:utf-8-*-import Image import win32ui import Win32gui def make_regalur_image (im G, size = (256, 256)): Return img.resize (Size). CONVERT (' RGB ') def split_image (img, part_size = (): 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 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_regal
Ur_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.his
Togram ()))) # 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,): Draw.line ((0, I, 256, i), fil
L = ' #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) 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 ' r esult:%d '% (Calc_similar_by_path (' save.bmp ', r "Test/test1/backup.bmp") *100) #for I in xrange (1, 7): #print ' Te
st_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 ')
I hope this article will help you with your Python programming.