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

python查找重復圖片并刪除(圖片去重)

 更新時間:2019年07月16日 10:52:03   作者:eggie1988  
這篇文章主要為大家詳細介紹了python查找重復圖片并刪除,識別不同尺寸大小一致的圖片,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了python查找重復圖片并刪除的具體代碼,供大家參考,具體內(nèi)容如下

和網(wǎng)絡(luò)爬蟲配套的,也可單獨使用,從網(wǎng)上爬下來的圖片重復太多,代碼支持識別不同尺寸大小一致的圖片,并把重復的圖片刪除,只保留第一份。

# -*- coding: utf-8 -*-
import cv2
import numpy as np
import os,sys,types

def cmpandremove2(path):
  dirs = os.listdir(path)
  dirs.sort()
  if len(dirs) <= 0:
    return
  dict={}
  for i in dirs:
    prepath = path + "/" + i
    preimg = cv2.imread(prepath)
    if type(preimg) is types.NoneType:
      continue
    preresize = cv2.resize(preimg, (8,8))
    pregray = cv2.cvtColor(preresize, cv2.COLOR_BGR2GRAY)
    premean = cv2.mean(pregray)[0]
    prearr = np.array(pregray.data)
    for j in range(0,len(prearr)):
      if prearr[j] >= premean:
        prearr[j] = 1
      else:
        prearr[j] = 0
    print "get", prepath
    dict[i] = prearr
  dictkeys = dict.keys()
  dictkeys.sort()
  index = 0
  while True:
    if index >= len(dictkeys):
      break
    curkey = dictkeys[index]
    dellist=[]
    print curkey
    index2 = index
    while True:
      if index2 >= len(dictkeys):
        break
      j = dictkeys[index2]
      if curkey == j:
        index2 = index2 + 1
        continue
      arr1 = dict[curkey]
      arr2 = dict[j]
      diff = 0
      for k in range(0,len(arr2)):
        if arr1[k] != arr2[k]:
          diff = diff + 1
      if diff <= 5:
        dellist.append(j)
      index2 = index2 + 1
    if len(dellist) > 0:
      for j in dellist:
        file = path + "/" + j
        print "remove", file
        os.remove(file)
        dict.pop(j)
      dictkeys = dict.keys()
      dictkeys.sort()
    index = index + 1


def cmpandremove(path):
  index = 0
  flag = 0
  dirs = os.listdir(path)
  dirs.sort()
  if len(dirs) <= 0:
    return 0
  while True:
    if index >= len(dirs):
      break
    prepath = path + dirs[index]
    print prepath
    index2 = 0
    preimg = cv2.imread(prepath)
    if type(preimg) is types.NoneType:
      index = index + 1
      continue
    preresize = cv2.resize(preimg, (8, 8))
    pregray = cv2.cvtColor(preresize, cv2.COLOR_BGR2GRAY)
    premean = cv2.mean(pregray)[0]
    prearr = np.array(pregray.data)
    for i in range(0, len(prearr)):
      if prearr[i] >= premean:
        prearr[i] = 1
      else:
        prearr[i] = 0
    removepath = []
    while True:
      if index2 >= len(dirs):
        break
      if index2 != index:
        curpath = path + dirs[index2]
        # print curpath
        curimg = cv2.imread(curpath)
        if type(curimg) is types.NoneType:
          index2 = index2 + 1
          continue
        curresize = cv2.resize(curimg, (8, 8))
        curgray = cv2.cvtColor(curresize, cv2.COLOR_BGR2GRAY)
        curmean = cv2.mean(curgray)[0]
        curarr = np.array(curgray.data)
        for i in range(0, len(curarr)):
          if curarr[i] >= curmean:
            curarr[i] = 1
          else:
            curarr[i] = 0
        diff = 0
        for i in range(0, len(curarr)):
          if curarr[i] != prearr[i]:
            diff = diff + 1
        if diff <= 5:
          print 'the same'
          removepath.append(curpath)
          flag = 1
      index2 = index2 + 1
    index = index + 1
    if len(removepath) > 0:
      for file in removepath:
        print "remove", file
        os.remove(file)
      dirs = os.listdir(path)
      dirs.sort()
      if len(dirs) <= 0:
        return 0
        # index = 0
  return flag


path = 'pics/'
cmpandremove(path)

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • numpy.random模塊用法總結(jié)

    numpy.random模塊用法總結(jié)

    這篇文章主要介紹了numpy.random模塊用法總結(jié),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-05-05
  • Anaconda虛擬環(huán)境中安裝cudatoolkit和cudnn包并配置tensorflow-gpu的教程

    Anaconda虛擬環(huán)境中安裝cudatoolkit和cudnn包并配置tensorflow-gpu的教程

    這篇文章詳細介紹了如何在Anaconda虛擬環(huán)境中配置PyTorch和TensorFlow-GPU,并提供了詳細的步驟和注意事項,通過圖文講解的非常詳細,需要的朋友可以參考下
    2025-02-02
  • Python處理PPT文件的實用知識點總結(jié)

    Python處理PPT文件的實用知識點總結(jié)

    python是一門很強大的語言,因為有著豐富的第三方庫,所以可以說Python是無所不能的,下面這篇文章主要給大家介紹了關(guān)于用Python提取PPT中圖片的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-01-01
  • python讀取eml文件并用正則表達式匹配郵箱的代碼

    python讀取eml文件并用正則表達式匹配郵箱的代碼

    今天接到一個需求有一個同事離職了,但是留下了非常多的郵件,我需要將他的郵件進行分類,只要郵件中以@xxx.com結(jié)尾的存放在文件夾中,否則放在另一個文件夾中,這篇文章主要介紹了python讀取eml文件并用正則匹配郵箱,需要的朋友可以參考下
    2022-11-11
  • python 專題九 Mysql數(shù)據(jù)庫編程基礎(chǔ)知識

    python 專題九 Mysql數(shù)據(jù)庫編程基礎(chǔ)知識

    在Python網(wǎng)絡(luò)爬蟲中,通常是通過TXT純文本方式存儲,其實也是可以存儲在數(shù)據(jù)庫中的;同時在WAMP(Windows、Apache、MySQL、PHP或Python)開發(fā)網(wǎng)站中,也可以通過Python構(gòu)建網(wǎng)頁的,所以這篇文章主要講述Python調(diào)用MySQL數(shù)據(jù)庫相關(guān)編程知識
    2017-03-03
  • python進行參數(shù)傳遞的方法

    python進行參數(shù)傳遞的方法

    在本篇文章里小編給大家分享的是關(guān)于python進行參數(shù)傳遞的方法以及代碼,需要的朋友們可以學習下。
    2020-05-05
  • Python字典的基本用法實例分析【創(chuàng)建、增加、獲取、修改、刪除】

    Python字典的基本用法實例分析【創(chuàng)建、增加、獲取、修改、刪除】

    這篇文章主要介紹了Python字典的基本用法,結(jié)合具體實例形式分析了Python字典的創(chuàng)建、增加、獲取、修改、刪除等基本操作技巧與注意事項,需要的朋友可以參考下
    2019-03-03
  • Python中的QPixmap用法詳解

    Python中的QPixmap用法詳解

    QPixmap主要用于繪圖,針對圖像顯示而最佳化設(shè)計,這篇文章主要介紹了Python中的QPixmap用法,對QPixmap使相關(guān)知識感興趣的朋友一起看看吧
    2023-03-03
  • Python中函數(shù)相關(guān)的變量作用域

    Python中函數(shù)相關(guān)的變量作用域

    這篇文章主要介紹了Python中函數(shù)相關(guān)的變量作用域,變量的作用域是指程序代碼能夠訪問該變量的區(qū)域,如果超出該區(qū)域,在訪問時就會出現(xiàn)錯誤,需要的朋友可以參考下
    2023-08-08
  • Python+Pandas實現(xiàn)數(shù)據(jù)透視表

    Python+Pandas實現(xiàn)數(shù)據(jù)透視表

    對于數(shù)據(jù)透視表,相信對于Excel比較熟悉的小伙伴都知道如何使用它。本文將利用Python Pandas實現(xiàn)數(shù)據(jù)透視表功能,感興趣的可以學習一下
    2022-06-06

最新評論

玉田县| 芜湖县| 东乡族自治县| 精河县| 赤水市| 依兰县| 平罗县| 长宁区| 辉县市| 宣汉县| 仁寿县| 汉寿县| 巫山县| 衡南县| 舒兰市| 南靖县| 静海县| 澄江县| 临桂县| 婺源县| 邯郸市| 鄄城县| 建阳市| 新宁县| 大竹县| 定陶县| 铜川市| 陈巴尔虎旗| 肇州县| 永德县| 图片| 永城市| 盘锦市| 边坝县| 台东县| 南康市| 汉川市| 凤城市| 浙江省| 常熟市| 乐平市|