最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python2比較當(dāng)前圖片跟圖庫哪個(gè)圖片相似的方法示例

 更新時(shí)間:2019年09月28日 11:09:38   作者:lbxx  
這篇文章主要介紹了Python2比較當(dāng)前圖片跟圖庫哪個(gè)圖片相似的方法,結(jié)合實(shí)例形式分析了Python文件目錄操作及圖形運(yùn)算相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了Python2比較當(dāng)前圖片跟圖庫哪個(gè)圖片相似的方法。分享給大家供大家參考,具體如下:

# -*- coding: utf-8 -*-
'''
Created on 2019年7月22日
'''
from selenium import webdriver
from time import sleep
from PIL import Image
import random
import os
import cv2
import numpy as np
url ="URL"
driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.maximize_window()
driver.get(url)
sleep(2)
driver.save_screenshot("E:/test/das.png")
p1=r'E:/test/das1.png'
p2=r'E:/test/das2.png'
p3=r'E:/test/das3.png'
p4=r'E:/test/das4.png'
element = driver.find_element_by_id("imgcode")
left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']
im1 = Image.open(r'E:/test/das.png')
im1 = im1.crop((left, top, right, bottom))
im1.save(r"E:/test/dascode.png")
img = Image.open("E:/test/dascode.png")
cropped = img.crop((0, 0, 25, 30)) # (left, upper, right, lower)
cropped.save(p1)
cropped = img.crop((25, 0, 50, 30)) # (left, upper, right, lower)
cropped.save(p2)
cropped = img.crop((50, 0, 75, 30)) # (left, upper, right, lower)
cropped.save(p3)
cropped = img.crop((75, 0, 96, 30)) # (left, upper, right, lower)
cropped.save(p4)
def getGray(image_file):
  tmpls=[]
  for h in range(0, image_file.size[1]):#h
    for w in range(0, image_file.size[0]):#w
      tmpls.append( image_file.getpixel((w,h)) )
  return tmpls
def getAvg(ls):#獲取平均灰度值
  return sum(ls)/len(ls)
def aHash(fne):
  image_file = Image.open(fne) # 打開
  image_file=image_file.resize((35,35))#重置圖片大小我12px X 12px
  image_file=image_file.convert("L")#轉(zhuǎn)256灰度圖
  Grayls=getGray(image_file)#灰度集合
  avg=getAvg(Grayls)#灰度平均值
  bitls=''#接收獲取0或1
  for h in range(1, image_file.size[1]-1):#h
    for w in range(1, image_file.size[0]-1):#w
      if image_file.getpixel((w,h))>=avg:#像素的值比較平均值 大于記為1 小于記為0
        bitls=bitls+'1'
      else:
        bitls=bitls+'0'
  return bitls
def getMH(i1,i2):
  a=aHash(i1)
  b=aHash(i2)
  dist = 0;
  for i in range(0,len(a)):
    if a[i]==b[i]:
      dist=dist+1
  return dist
def match(a,rootdir):
  list = os.listdir(rootdir) 
  li=[]
  for i in list:
    re=getMH(a,rootdir+"/"+i)
    li.append(re)
  b=str(li.index(max(li))+1)  
  a=li.index(max(li))
  return b,list[a].split(".")[0]
a=match('E:/test/das4.png',"E:/test/pic4")
print a

另附參考的

# -*- coding: utf-8 -*-
'''
Created on 2018年5月17日
'''
from selenium import webdriver
from PIL import Image
import requests
import time
import base64
import base64
import requests
from urllib import urlencode
import json
# requests.packages.urllib3.disable_warnings()
import datetime
from time import strftime
from time import sleep
from PIL import Image
# import pytesseract
from PIL import Image
import os
import cv2
from numpy import average, dot, linalg
import heapq
import collections
from lib.readConfig import Readconfig
conf=Readconfig()
filedir=conf.getConfigValue("filedir")
def getGray(image_file):
  tmpls=[]
  for h in range(0, image_file.size[1]):#h
    for w in range(0, image_file.size[0]):#w
      tmpls.append( image_file.getpixel((w,h)) )
  return tmpls
def getAvg(ls):#獲取平均灰度值
  return sum(ls)/len(ls)
def getMH(i1,i2):
  a=getImgHash(i1)
  b=getImgHash(i2)
  dist = 0;
  for i in range(0,len(a)):
    if a[i]==b[i]:
      dist=dist+1
  return dist
def getImgHash(fne):
  image_file = Image.open(fne) # 打開
  image_file=image_file.resize((35,35))#重置圖片大小我12px X 12px
  image_file=image_file.convert("L")#轉(zhuǎn)256灰度圖
  Grayls=getGray(image_file)#灰度集合
  avg=getAvg(Grayls)#灰度平均值
  bitls=''#接收獲取0或1
  for h in range(1, image_file.size[1]-1):#h
    for w in range(1, image_file.size[0]-1):#w
      if image_file.getpixel((w,h))>=avg:#像素的值比較平均值 大于記為1 小于記為0
        bitls=bitls+'1'
      else:
        bitls=bitls+'0'
  return bitls
def match1(a,rootdir):
  list = os.listdir(rootdir) 
  li=[]
  for i in list:
#     print rootdir+"/"+i
    re=getMH(a,rootdir+"/"+i)
    li.append(re)
#   print li
#   print max(li)
  b=str(li.index(max(li))+1)  
  return b
def g_code(pic):
  dic={"1":"2","2":"3","3":"4","4":"5","5":"6","6":"7","7":"8","8":"9",
"9":"a","10":"b","11":"c","12":"d","13":"e","14":"f","15":"g","16":"h",
"17":"i","18":"j","19":"k","20":"m","21":"n","22":"p","23":"q","24":"r",
"25":"s","26":"t","27":"u","28":"v","29":"w","30":"x","31":"y","32":"z"}
  img = Image.open(pic)
  a=img.size[0]
  b=img.size[1]
  p1=filedir+r'eos_tdym/lib/pic/das1.png'
  p2=filedir+r'eos_tdym/lib/pic/das2.png'
  p3=filedir+r'eos_tdym/lib/pic/das3.png'
  p4=filedir+r'eos_tdym/lib/pic/das4.png'
  dir1=filedir+r'eos_tdym/lib/pic/pic1'
  dir2=filedir+r'eos_tdym/lib/pic/pic2'
  dir3=filedir+r'eos_tdym/lib/pic/pic3'
  dir4=filedir+r'eos_tdym/lib/pic/pic4'
  cropped = img.crop((0, 0, 25, 30)) # (left, upper, right, lower)
  cropped.save(p1)
  cropped = img.crop((25, 0, 50, 30)) # (left, upper, right, lower)
  cropped.save(p2)
  cropped = img.crop((50, 0, 75, 30)) # (left, upper, right, lower)
  cropped.save(p3)
  cropped = img.crop((75, 0, 96, 30)) # (left, upper, right, lower)
  cropped.save(p4)
  re1=str(match1(p1,dir1))
  re2=str(match1(p2,dir2))
  re3=str(match1(p3,dir3))
  re4=str(match1(p4,dir4))
  print u"獲取到驗(yàn)證碼:"+dic[re1]+dic[re2]+dic[re3]+dic[re4]
  return dic[re1],dic[re2],dic[re3],dic[re4]
def g_code1(pic):
  dic={"1":"2","2":"3","3":"4","4":"5","5":"6","6":"7","7":"8","8":"9",
"9":"a","10":"b","11":"c","12":"d","13":"e","14":"f","15":"g","16":"h",
"17":"i","18":"j","19":"k","20":"m","21":"n","22":"p","23":"q","24":"r",
"25":"s","26":"t","27":"u","28":"v","29":"w","30":"x","31":"y","32":"z"}
  img = Image.open(pic)
  a=img.size[0]
  b=img.size[1]
  p1="pic5/das1.png"
  p2="pic5/das2.png"
  p3="pic5/das3.png"
  p4="pic5/das4.png"
  dir1="pic1"
  dir2="pic2"
  dir3="pic3"
  dir4="pic4"
  cropped = img.crop((0, 0, 25, 30)) # (left, upper, right, lower)
  cropped.save(p1)
  cropped = img.crop((25, 0, 50, 30)) # (left, upper, right, lower)
  cropped.save(p2)
  cropped = img.crop((50, 0, 75, 30)) # (left, upper, right, lower)
  cropped.save(p3)
  cropped = img.crop((75, 0, 96, 30)) # (left, upper, right, lower)
  cropped.save(p4)
  re1=match1(p1,dir1)
  re2=match1(p2,dir2)
  re3=match1(p3,dir3)
  re4=match1(p4,dir4)
  print dic[re1]
  print dic[re2]
  print dic[re3]
  print dic[re4]
  return dic[re1],dic[re2],dic[re3],dic[re4]

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總

希望本文所述對大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • Python bisect_left 函數(shù)使用場景詳解

    Python bisect_left 函數(shù)使用場景詳解

    在Python的編程世界中,數(shù)據(jù)處理和搜索操作是非常常見的任務(wù),bisect_left函數(shù)是Python標(biāo)準(zhǔn)庫bisect模塊中的一個(gè)強(qiáng)大工具,接下來,我們將詳細(xì)探討bisect_left函數(shù)的使用場景,需要的朋友可以參考下
    2024-11-11
  • Pythonr基于selenium如何實(shí)現(xiàn)不同商城的商品價(jià)格差異分析系統(tǒng)

    Pythonr基于selenium如何實(shí)現(xiàn)不同商城的商品價(jià)格差異分析系統(tǒng)

    這篇文章主要給大家介紹了關(guān)于Pythonr基于selenium如何實(shí)現(xiàn)不同商城的商品價(jià)格差異分析系統(tǒng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2022-03-03
  • 使用Python進(jìn)行中文繁簡轉(zhuǎn)換的實(shí)現(xiàn)代碼

    使用Python進(jìn)行中文繁簡轉(zhuǎn)換的實(shí)現(xiàn)代碼

    這篇文章主要介紹了使用Python進(jìn)行中文繁簡轉(zhuǎn)換的實(shí)現(xiàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • python返回?cái)?shù)組的索引實(shí)例

    python返回?cái)?shù)組的索引實(shí)例

    今天小編就為大家分享一篇python返回?cái)?shù)組的索引實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • 淺析python內(nèi)置模塊collections

    淺析python內(nèi)置模塊collections

    collections是Python內(nèi)建的一個(gè)集合模塊,提供了許多有用的集合類。這篇文章主要介紹了python內(nèi)置模塊collections的相關(guān)知識(shí),非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Python 列表排序詳解

    Python 列表排序詳解

    這篇文章主要介紹了Python中對列表排序?qū)嵗?本文給出了9個(gè)List的排序?qū)嵗?需要的朋友可以參考下,希望能夠給你帶來幫助
    2021-10-10
  • pygame 精靈的行走及二段跳的實(shí)現(xiàn)方法(必看篇)

    pygame 精靈的行走及二段跳的實(shí)現(xiàn)方法(必看篇)

    下面小編就為大家?guī)硪黄猵ygame 精靈的行走及二段跳的實(shí)現(xiàn)方法(必看篇)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • Pytorch的mean和std調(diào)查實(shí)例

    Pytorch的mean和std調(diào)查實(shí)例

    今天小編就為大家分享一篇Pytorch的mean和std調(diào)查實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Web服務(wù)器框架 Tornado簡介

    Web服務(wù)器框架 Tornado簡介

    Tornado Web Server 是使用Python編寫出來的一個(gè)極輕量級、高可伸縮性和非阻塞IO的Web服務(wù)器軟件,著名的 Friendfeed 網(wǎng)站就是使用它搭建的。
    2014-07-07
  • pytorch實(shí)現(xiàn)mnist分類的示例講解

    pytorch實(shí)現(xiàn)mnist分類的示例講解

    今天小編就為大家分享一篇pytorch實(shí)現(xiàn)mnist分類的示例講解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01

最新評論

天等县| 石棉县| 河曲县| 深州市| 清镇市| 基隆市| 兴业县| 莱芜市| 凉城县| 宁波市| 桃江县| 湄潭县| 前郭尔| 阳高县| 景谷| 驻马店市| 馆陶县| 晋中市| 策勒县| 吉林市| 惠安县| 元氏县| 富锦市| 齐河县| 新郑市| 黄龙县| 万州区| 吉首市| 南郑县| 承德市| 古蔺县| 溧阳市| 临澧县| 商南县| 漠河县| 东平县| 霍山县| 庄浪县| 正阳县| 苍山县| 叙永县|