現在、ディレクトリ内にある画像に対して処理を行い、カレントディレクトリに別のdataと呼ばれるディレクトリを作り、そこに保存したいと考えています。
具体的に、サーモグラフィー画像をバウンディングボックスで囲ったものを新たな画像とし、dataフォルダに保存したいです。
私が書いたコードではどうしても、全てに処理を行い、保存することができません。
また、以下に載せるコードで実行すると永久ループになってしまいます。
私が思い描いている様な処理を教えてください。初心者の私では難しすぎます。
import cv2 import numpy as np import cv2 import glob def contour_extraction(image): hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) binary = cv2.inRange(hsv, (20, 0, 0), (50, 255, 255)) # 輪郭抽出 contours = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1] # 面積が一定以上の輪郭のみ残す。 area_thresh = 10000 contours = list(filter(lambda x: cv2.contourArea(x) > area_thresh, contours)) create_box(contours) def create_box(contours): for cnt in contours: # 輪郭に外接する長方形を取得する。 x, y, width, height = cv2.boundingRect(cnt) print(x, y, width, height) # 描画する。 cv2.rectangle(image, (x, y), (x + width, y + height), color=(0, 255, 0), thickness=2) for images in image: cv2.imwrite('Users/XXXX/Desktop/サーモ/data/hogehoge.jpg', images) path = './*.jpg' files = glob.glob(path) for f in files: print(f) image = cv2.imread(f) contour_extraction(image) print('end')
どうかよろしくお願い致しましす。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。