当前位置: 首页>>代码示例>>Python>>正文


Python imagehash.phash方法代码示例

本文整理汇总了Python中imagehash.phash方法的典型用法代码示例。如果您正苦于以下问题:Python imagehash.phash方法的具体用法?Python imagehash.phash怎么用?Python imagehash.phash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imagehash的用法示例。


在下文中一共展示了imagehash.phash方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index_image

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def index_image(image, file_name, index_name, metadata):
    preview_image_url, original_image_url, search_term = metadata
    image_hash = imagehash.phash(image, hash_size=16)
    thumbnail_size = 128, 128
    image.thumbnail(thumbnail_size)
    output = BytesIO()
    image.save(output, format="JPEG", quality=66, optimize=True)
    img_base64 = base64.b64encode(output.getvalue())
    output.close()
    uid = generate_guid()
    json_data = json.dumps({
        'hash': str(image_hash),
        'fileName': file_name,
        'imgBase64': img_base64.decode(),
        'metadata': {
            'preview': preview_image_url,
            'original': original_image_url,
            'searchTerm': search_term
        }
    })
    es.index(index=index_name, doc_type='image_info', id=uid, body=json_data) 
开发者ID:scirag,项目名称:selenium-image-crawler,代码行数:23,代码来源:ElasticSearchProcessor.py

示例2: __init__

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def __init__(self,
                 use_hash = 'dhash',
                 hash_size = 15,
                 patch_size = 2,
                 max_patches = 512,
                 ):
        if use_hash == 'dhash':
            self.hash_func = imagehash.dhash
        elif use_hash == 'phash':
            self.hash_func = imagehash.phash
        else:
            self.hash_func = use_hash
        
        self.hash_size = int(hash_size)
        
        self.patch_size = int(patch_size)
        self.max_patches = int(max_patches) 
开发者ID:mediachain,项目名称:mediachain-indexer,代码行数:19,代码来源:mc_models.py

示例3: calc_scores

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def calc_scores(source_image):
    scores = []
    for item in ALG:
        if item[0] == 'crop':
            v, h, fit_image = item[1:]
            name = '%s_%s_%s_%s' % item
            var_img = prepare_image(
                source_image,
                crop_width_perc=v,
                crop_height_perc=h,
                fit_image=fit_image
            )

            # val = imagehash.phash(var_img, hash_size=HASH_SIZE, highfreq_factor=HASH_SIZE)
            val = imagehash.whash(var_img, hash_size=HASH_SIZE)
            scores.append((name, val))
    return scores 
开发者ID:nimnull,项目名称:talkbot,代码行数:19,代码来源:utils.py

示例4: run

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def run(self):
        date_path = self.search['date_path']
        files = sorted(os.listdir('data/%s/media' % date_path))
        hashes = {}
        matches = []
        g = nx.Graph()
        update_block_size = get_block_size(len(files), 5)
        for i in range(len(files)):
            f = files[i]
            fn = 'data/%s/media/%s' % (date_path, f)
            ahash = imagehash.average_hash(Image.open(fn))
            dhash = imagehash.dhash(Image.open(fn))
            phash = imagehash.phash(Image.open(fn))
            hashes[f] = {'ahash': ahash, 'dhash': dhash, 'phash': phash}
            for j in range(0, i):
                f2name = files[j]
                f2 = hashes[f2name]
                sumhash = sum([ahash - f2['ahash'],
                               dhash - f2['dhash'],
                               phash - f2['phash']])
                # FIXME: 40 is a hard-coded arbitrary (eyeballed) threshold
                if sumhash <= 40:
                    matches.append([f, files[j],
                                    ahash - f2['ahash'],
                                    dhash - f2['dhash'],
                                    phash - f2['phash'],
                                    sumhash])
                    g.add_edge(f, f2name)
            if i % update_block_size == 0:
                self.update_job(
                    date_path=self.search['date_path'],
                    status="STARTED: %s - %s/%s" %
                           (self.task_family, i, len(files))
                )
        with self.output().open('w') as fp_graph:
            components = list(nx.connected_components(g))
            # Note: sets are not JSON serializable
            d = []
            for s in components:
                d.append(list(s))
            json.dump(d, fp_graph, indent=2) 
开发者ID:DocNow,项目名称:dnflow,代码行数:43,代码来源:summarize.py

示例5: getImageHash

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def getImageHash(img):
    io = Image.open(img)
    hash1 = imagehash.average_hash(io)
    hash2 = imagehash.phash(io)
    hash3 = imagehash.dhash(io)
    return hash1, hash2, hash3 
开发者ID:ZFTurbo,项目名称:KAGGLE_AVITO_2016,代码行数:8,代码来源:s6_prepare_images.py

示例6: deduplicate_images

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def deduplicate_images(self, userpath, hashfunc=imagehash.average_hash):
        """
        Remove duplicate images from a path
        :userpath: path of the image files
        :hashfunc: type of image hashing method
        """

        def is_image(filename):
            img_ext = [".jpg", ".png", ".gif", ".bmp", ".gif"]
            f = filename.lower()
            return any(f.endswith(ext) for ext in img_ext)

        """
        Available hashs functions:
            ahash:      Average hash
            phash:      Perceptual hash
            dhash:      Difference hash
            whash-haar: Haar wavelet hash
            whash-db4:  Daubechies wavelet hash
        """
        dd_img_set = []

        image_filenames = [os.path.join(userpath, path) for path in os.listdir(userpath) if is_image(path)]
        images = {}
        for img in sorted(image_filenames):
            hash = hashfunc(Image.open(img))
            images[hash] = images.get(hash, []) + [img]
        for k, img_list in six.iteritems(images):
            dd_img_set.append(os.path.basename(img_list[0]))
        dd_img_set.sort()
        return dd_img_set 
开发者ID:ctxis,项目名称:CAPE,代码行数:33,代码来源:deduplication.py

示例7: run

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def run(self):
        """Creates a new key in the report dict for 
        the deuplicated screenshots.
        """
        self.key = "deduplicated_shots"
        shots = []

        hashmethod = "whash-db4"
        if hashmethod == 'ahash':
            hashfunc = imagehash.average_hash
        elif hashmethod == 'phash':
            hashfunc = imagehash.phash
        elif hashmethod == 'dhash':
            hashfunc = imagehash.dhash
        elif hashmethod == 'whash-haar':
            hashfunc = imagehash.whash
        elif hashmethod == 'whash-db4':
            hashfunc = lambda img: imagehash.whash(img, mode='db4')

        shots_path = os.path.join(self.analysis_path, "shots")
        if os.path.exists(shots_path):
            screenshots = self.deduplicate_images(userpath=shots_path, hashfunc=hashfunc)
            for screenshot in screenshots:
                shots.append(screenshot.replace(".jpg",""))

        return shots 
开发者ID:ctxis,项目名称:CAPE,代码行数:28,代码来源:deduplication.py

示例8: findSimilar

# 需要导入模块: import imagehash [as 别名]
# 或者: from imagehash import phash [as 别名]
def findSimilar(imagename):
    #cql = "SELECT * FROM queryresults WHERE targetimagehash='"+str(hashValue) +"' ALLOW FILTERING"
    filepath=os.path.join(app.config['UPLOAD_FOLDER'], imagename)
    hashValue=imagehash.phash(Image.open(filepath))
    image=cv2.imread(filepath)
    hsvImg = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
    histogram_bins = [4, 8, 3]
    hist = cv2.calcHist([hsvImg], [0, 1, 2], None, histogram_bins, [0, 180, 0, 256, 0, 256])
    histflat = cv2.normalize(hist).flatten()
    histstring=pickle.dumps(histflat)
    jsonToShow={"imgName":imagename,"hash":str(hashValue),"time":time.time()}    
    jsonToSend={"imgName":imagename,"hash":str(hashValue),"time":time.time(), "histogramvector":histstring}    
    cql = "SELECT * FROM queryresults WHERE targetimagehash='"+str(hashValue) +"' and imagename='"+imagename+"'"
    print("cql printed: ",cql)    
    cqlresult=0
    cqlresult = session.execute(cql)
    if not cqlresult:
        print("json being sent: ",jsonToSend)
        producer.send('imgSearchRequests', jsonToSend)
    starttime=time.time()
    printcounter=0
    elapsed=0
    while elapsed<600: #allow waiting for 600 seconds for the spark streaming job to finish and write to the database
        elapsed=time.time()-starttime
        printcounter=printcounter+1
        if printcounter==10000: #will print about every 15 seconds
            printcounter=0
            print("querying cassandra for: ",imagename, "time: ", elapsed)
        cqlresult = session.execute(cql)
        if cqlresult:
            print("cqlresult: ", cqlresult)
            print("cqlresult.current_rows: ", cqlresult.current_rows) #note that cqlresult is an iterator, so you can't
            break
    arrayOfMessages=[]
    arrayOfYoutubeIDs=[]
    arrayOfYoutubeTimes=[]
    for row in cqlresult:
        arrayOfMessages.append(row)
        arrayOfYoutubeIDs.append(str(row.youtubelink)[-11:]) #get the youtube video id
        arrayOfYoutubeTimes.append(int(float(str(row.frametime)))-3) #get the youtube video time, 2 seconds before
    arrayOfMessages=arrayOfMessages[:3]
    arrayOfYoutubeIDs=arrayOfYoutubeIDs[:3]
    arrayOfYoutubeTimes=arrayOfYoutubeTimes[:3]
    return render_template('results.html', jsontoshow=jsonToShow, results=zip(arrayOfMessages,arrayOfYoutubeIDs, arrayOfYoutubeTimes), imagename=imagename) 
开发者ID:gylu,项目名称:videoSceneSearch,代码行数:46,代码来源:views.py


注:本文中的imagehash.phash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。