opencvを用いた画像処理を行っています。
内容は、赤色だけを囲う(バウンディングボックス)の様なものを作りたいです。
現在、物体を囲うことはできているのですが、赤色だけでなく青色やその他の色も囲ってしまいます。
11行目〜12行目(以下)の
**lower_red = np.array([33, 68, 33])
upper_red = np.array([2, 230, 250])**
BGRパラメーターの調整がうまくいきません。
赤色だけを縁取る(囲う)にはどんなパラメーターがベストなのでしょうか?
また修正すべき箇所があればご教授下さい。
もしよろしければ教えて頂きたいです。
import cv2 import numpy as np # カメラの読み込み cap = cv2.VideoCapture(0) print(cap.isOpened()) while True: _, frame = cap.read() blurred_flame = cv2.GaussianBlur(frame, (5, 5), 0) hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) lower_red = np.array([33, 68, 33]) upper_red = np.array([2, 230, 250]) mask = cv2.inRange(hsv, lower_red, upper_red) _, contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) for contour in contours: area = cv2.contourArea(contour) # ノイズの値を調べる # print(area) # ノイズの処理 if area > 500: cv2.drawContours(frame, contour, -1, (0, 255, 0), 3) cv2.imshow("Frame", frame) cv2.imshow("Mask", mask) key = cv2.waitKey(1) if key == 27: break cap.release() cv2.destroyALLwindows()
回答1件
あなたの回答
tips
プレビュー