内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

python中刪除相似圖片的方法-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

創(chuàng)新互聯(lián)公司是一家以網(wǎng)絡(luò)技術(shù)公司,為中小企業(yè)提供網(wǎng)站維護、成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、網(wǎng)站備案、服務(wù)器租用、申請域名、軟件開發(fā)、小程序制作等企業(yè)互聯(lián)網(wǎng)相關(guān)業(yè)務(wù),是一家有著豐富的互聯(lián)網(wǎng)運營推廣經(jīng)驗的科技公司,有著多年的網(wǎng)站建站經(jīng)驗,致力于幫助中小企業(yè)在互聯(lián)網(wǎng)讓打出自已的品牌和口碑,讓企業(yè)在互聯(lián)網(wǎng)上打開一個面向全國乃至全球的業(yè)務(wù)窗口:建站來電聯(lián)系:18980820575

這篇文章主要介紹python中刪除相似圖片的方法,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

方法一:相鄰兩個文件比較相似度,相似就把第二個加到新列表里,然后進行新列表去重,統(tǒng)一刪除。

例如:有文件1-10,首先1和2相比較,若相似,則把2加入到新列表里,再接著2和3相比較,若不相似,則繼續(xù)進行3和4比較...一直比到最后,然后刪除新列表里的圖片

代碼如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/1/15 9:19
# @Author  : xiaodai
import os
import cv2
from skimage.measure import compare_ssim
# import shutil
# def yidong(filename1,filename2):
#     shutil.move(filename1,filename2)
def delete(filename1):
    os.remove(filename1)
if __name__ == '__main__':
    path = r'D:\camera_pic\test\rec_pic'
    # save_path_img = r'E:\0115_test\rec_pic'
    # os.makedirs(save_path_img, exist_ok=True)
    img_path = path
    imgs_n = []
    num = []
    img_files = [os.path.join(rootdir, file) for rootdir, _, files in os.walk(path) for file in files if
                 (file.endswith('.jpg'))]
    for currIndex, filename in enumerate(img_files):
        if not os.path.exists(img_files[currIndex]):
            print('not exist', img_files[currIndex])
            break
        img = cv2.imread(img_files[currIndex])
        img1 = cv2.imread(img_files[currIndex + 1])
        ssim = compare_ssim(img, img1, multichannel=True)
        if ssim > 0.9:
            imgs_n.append(img_files[currIndex + 1])
            print(img_files[currIndex], img_files[currIndex + 1], ssim)
        else:
            print('small_ssim',img_files[currIndex], img_files[currIndex + 1], ssim)
        currIndex += 1
        if currIndex >= len(img_files)-1:
            break
    for image in imgs_n:
        # yidong(image, save_path_img)
        delete(image)

方法二:逐個去比較,若相似,則從原來列表刪除,添加到新列表里,若不相似,則繼續(xù)

例如:有文件1-10,首先1和2相比較,若相似,則把2在原列表刪除同時加入到新列表里,再接著1和3相比較,若不相似,則繼續(xù)進行1和4比較...一直比,到最后一個,再繼續(xù),正常應(yīng)該再從2開始比較,但2被刪除了,所以從3開始,繼續(xù)之前的操作,最后把新列表里的刪除。

代碼如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/1/16 12:03
# @Author  : xiaodai
import os
import cv2
from skimage.measure import compare_ssim
import shutil
import datetime
def yidong(filename1,filename2):
    shutil.move(filename1,filename2)
def delete(filename1):
    os.remove(filename1)
    print('real_time:',now_now-now)
if __name__ == '__main__':
    path = r'F:\temp\demo'
    # save_path_img = r'F:\temp\demo_save'
    # os.makedirs(save_path_img, exist_ok=True)
    for (root, dirs, files) in os.walk(path):
        for dirc in dirs:
            if dirc == 'rec_pic':
                pic_path = os.path.join(root, dirc)
                img_path = pic_path
                imgs_n = []
                num = []
                del_list = []
                img_files = [os.path.join(rootdir, file) for rootdir, _, files in os.walk(img_path) for file in files if
                             (file.endswith('.jpg'))]
                for currIndex, filename in enumerate(img_files):
                    if not os.path.exists(img_files[currIndex]):
                        print('not exist', img_files[currIndex])
                        break
                    new_cur = 0
                    for i in range(10000000):
                        currIndex1 =new_cur
                        if currIndex1 >= len(img_files) - currIndex - 1:
                            break
                        else:
                            size = os.path.getsize(img_files[currIndex1 + currIndex + 1])
                            if size < 512:
                                # delete(img_files[currIndex + 1])
                                del_list.append(img_files.pop(currIndex1 + currIndex + 1))
                            else:
                                img = cv2.imread(img_files[currIndex])
                                img = cv2.resize(img, (46, 46), interpolation=cv2.INTER_CUBIC)
                                img1 = cv2.imread(img_files[currIndex1 + currIndex + 1])
                                img1 = cv2.resize(img1, (46, 46), interpolation=cv2.INTER_CUBIC)
                                ssim = compare_ssim(img, img1, multichannel=True)
                                if ssim > 0.9:
                                    # imgs_n.append(img_files[currIndex + 1])
                                    print(img_files[currIndex], img_files[currIndex1 + currIndex + 1], ssim)
                                    del_list.append(img_files.pop(currIndex1 + currIndex + 1))
                                    new_cur = currIndex1
                                else:
                                    new_cur = currIndex1 + 1
                                    print('small_ssim',img_files[currIndex], img_files[currIndex1 + currIndex + 1], ssim)
                for image in del_list:
                    # yidong(image, save_path_img)
                    delete(image)
                    print('delete',image)

以上是python中刪除相似圖片的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

新聞名稱:python中刪除相似圖片的方法-創(chuàng)新互聯(lián)
文章起源:http://www.rwnh.cn/article20/dghjjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT手機網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、網(wǎng)站收錄網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)
平南县| 广灵县| 勐海县| 保康县| 康乐县| 博爱县| 晋州市| 徐汇区| 基隆市| 开阳县| 二连浩特市| 安顺市| 揭阳市| 阜康市| 寿光市| 长宁区| 田东县| 咸阳市| 翁牛特旗| 甘肃省| 子洲县| 集安市| 迁西县| 堆龙德庆县| 海伦市| 永济市| 夹江县| 石家庄市| 万州区| 仁布县| 遂昌县| 铁岭县| 平阴县| 阿尔山市| 固阳县| 陵水| 上杭县| 金川县| 临洮县| 苗栗市| 上杭县|