python에서 물체 자동 검출 - 편집 - 크기 조정
10428 단어 Python3selectivesearch물체 검측
해본 일
정지 그림에서 물체를 자동으로 검출하기 위해 selective search라는 pytohon의 프로그램 라이브러리를 사용합니다.
운영 환경: Windows 7-32비트, ptyhon3.6, Anaconda
다음 명령을 사용하여 selective search를 설치할 수 있습니다.pip install selectivesearch
실행 결과
원본 이미지
실행 결과
아무것도 없는 곳(길바닥의 상처입니까?)들켰지만 자전거를 탄 사람과 오토바이도 잘 뽑았어요.
물체 검출 구역의 사이즈와 종횡비를 변경한 뒤 안전모, 타이어, 장갑 등도 검출됐다.이 매개 변수들은 측정하고자 하는 것에 따라 조정해야 한다.
여러가지가 검출되기도 했지만 수량이 많아서 사랑하지 않죠.
코드
selective_search.py# -*- coding: utf-8 -*-
import skimage.data
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import selectivesearch
def main():
# loading image
img = skimage.data.imread('fifth_corner.jpg') # 画像ファイルを指定します。
print("image shape " + str(img.shape))
# perform selective search
img_lbl, regions = selectivesearch.selective_search(img, scale=500, 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 small pixels
if r['size'] < 30000: # 物体検出される領域の大きさを指定します。
continue
# distorted rects
x, y, w, h = r['rect']
if w / h > 2.0 or h / w > 2.0: # 物体検出される領域のアスペクト比を指定します。
continue
candidates.add(r['rect'])
print("number of object " + str(len(candidates)))
for x, y, w, h in candidates:
# draw original image
fig, ax = plt.subplots(ncols=3, nrows=1, figsize=(10, 10))
ax[0].imshow(img)
# draw rectangles on the original image
rect = mpatches.Rectangle(
(x, y), w, h, fill=False, edgecolor='red', linewidth=1)
ax[0].add_patch(rect)
# trim image and draw
img2 = img[y:y+h, x:x+w]
ax[1].imshow(img2)
# reshape trimed image and draw
img3 = skimage.transform.resize(img2, (64, 64))
ax[2].imshow(img3)
plt.show()
if __name__ == "__main__":
main()
Reference
이 문제에 관하여(python에서 물체 자동 검출 - 편집 - 크기 조정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Yu-Nie/items/924cdadf9923d4af78a3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
pip install selectivesearch
원본 이미지

실행 결과






아무것도 없는 곳(길바닥의 상처입니까?)들켰지만 자전거를 탄 사람과 오토바이도 잘 뽑았어요.
물체 검출 구역의 사이즈와 종횡비를 변경한 뒤 안전모, 타이어, 장갑 등도 검출됐다.이 매개 변수들은 측정하고자 하는 것에 따라 조정해야 한다.




여러가지가 검출되기도 했지만 수량이 많아서 사랑하지 않죠.
코드
selective_search.py# -*- coding: utf-8 -*-
import skimage.data
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import selectivesearch
def main():
# loading image
img = skimage.data.imread('fifth_corner.jpg') # 画像ファイルを指定します。
print("image shape " + str(img.shape))
# perform selective search
img_lbl, regions = selectivesearch.selective_search(img, scale=500, 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 small pixels
if r['size'] < 30000: # 物体検出される領域の大きさを指定します。
continue
# distorted rects
x, y, w, h = r['rect']
if w / h > 2.0 or h / w > 2.0: # 物体検出される領域のアスペクト比を指定します。
continue
candidates.add(r['rect'])
print("number of object " + str(len(candidates)))
for x, y, w, h in candidates:
# draw original image
fig, ax = plt.subplots(ncols=3, nrows=1, figsize=(10, 10))
ax[0].imshow(img)
# draw rectangles on the original image
rect = mpatches.Rectangle(
(x, y), w, h, fill=False, edgecolor='red', linewidth=1)
ax[0].add_patch(rect)
# trim image and draw
img2 = img[y:y+h, x:x+w]
ax[1].imshow(img2)
# reshape trimed image and draw
img3 = skimage.transform.resize(img2, (64, 64))
ax[2].imshow(img3)
plt.show()
if __name__ == "__main__":
main()
Reference
이 문제에 관하여(python에서 물체 자동 검출 - 편집 - 크기 조정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Yu-Nie/items/924cdadf9923d4af78a3
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
# -*- coding: utf-8 -*-
import skimage.data
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import selectivesearch
def main():
# loading image
img = skimage.data.imread('fifth_corner.jpg') # 画像ファイルを指定します。
print("image shape " + str(img.shape))
# perform selective search
img_lbl, regions = selectivesearch.selective_search(img, scale=500, 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 small pixels
if r['size'] < 30000: # 物体検出される領域の大きさを指定します。
continue
# distorted rects
x, y, w, h = r['rect']
if w / h > 2.0 or h / w > 2.0: # 物体検出される領域のアスペクト比を指定します。
continue
candidates.add(r['rect'])
print("number of object " + str(len(candidates)))
for x, y, w, h in candidates:
# draw original image
fig, ax = plt.subplots(ncols=3, nrows=1, figsize=(10, 10))
ax[0].imshow(img)
# draw rectangles on the original image
rect = mpatches.Rectangle(
(x, y), w, h, fill=False, edgecolor='red', linewidth=1)
ax[0].add_patch(rect)
# trim image and draw
img2 = img[y:y+h, x:x+w]
ax[1].imshow(img2)
# reshape trimed image and draw
img3 = skimage.transform.resize(img2, (64, 64))
ax[2].imshow(img3)
plt.show()
if __name__ == "__main__":
main()
Reference
이 문제에 관하여(python에서 물체 자동 검출 - 편집 - 크기 조정), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Yu-Nie/items/924cdadf9923d4af78a3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)