图像中框物体selectivesearch库的使用

来源:互联网 发布:mac照片u盘导入win7 编辑:程序博客网 时间:2024/06/03 15:42

一、Git地址:

https://github.com/AlpacaDB/selectivesearch

二、使用selectivesearch:

进入到example文件中运行脚本 example.py

# -*- coding: utf-8 -*-from __future__ import (    division,    print_function,)import tensorflow as tfimport skimage.dataimport matplotlib.pyplot as pltimport matplotlib.patches as mpatchesimport selectivesearchimport numpy as npimport cv2def main():    #imgCV2 = cv2.imread("mayun.jpg")    # loading astronaut image    img = skimage.data.astronaut()    print("shape2 = "+str(img.shape[2]))    # perform selective search    img_lbl, regions = selectivesearch.selective_search(        img, scale=200, sigma=0.9, min_size=10)    candidates = set()    for r in regions:        # excluding same rectangle (with different segments)        if r['rect'] in candidates:            continue        # excluding regions smaller than 2000 pixels        if r['size'] < 2000:            continue        # distorted rects        x, y, w, h = r['rect']        if w / h > 1.2 or h / w > 1.2:            continue        candidates.add(r['rect'])    # draw rectangles on the original image    fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))    ax.imshow(img)    for x, y, w, h in candidates:        print(x, y, w, h)        rect = mpatches.Rectangle(            (x, y), w, h, fill=False, edgecolor='red', linewidth=1)        ax.add_patch(rect)    plt.show()if __name__ == "__main__":    main()





阅读全文
0 0
原创粉丝点击