pythonを使ってカラートラッキング(最大矩形を追跡)をしようと、以下のコードを書きました
python
1# -*- coding: utf-8 -*- 2import numpy as np 3import cv2 4 5cap = cv2.VideoCapture(0) 6 7while(1): 8 _, frame = cap.read() 9 hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) 10 11 lower_light_pink = np.array([168, 100, 100]) 12 upper_light_pink = np.array([188, 255, 255]) 13 mask = cv2.inRange(hsv, lower_light_pink, upper_light_pink) 14 15 res = cv2.bitwise_and(frame,frame, mask= mask) 16 17 cv2.imshow('frame',frame) 18 cv2.imshow('mask',mask) 19 cv2.imshow('res',res) 20 21 contours = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) 22 rects = [] 23 for contour in contours: 24 approx = cv2.convexHull(contour) 25 rect = cv2.boundingRect(approx) 26 rects.append(np.array(rect)) 27 28 if len(rects) > 0: 29 rect = max(rects, key=(lambda x: x[2] * x[3])) 30 cv2.rectangle(frame, tuple(rect[0:2]), tuple(rect[0:2] + rect[2:4]), (0, 0, 255), thickness=2) 31 k = cv2.waitKey(5) & 0xFF 32 if k == 27: 33 break 34 35cv2.destroyAllWindo
ですが、以下のようなエラーがでます
bash
1Traceback (most recent call last): 2 File "color_track.py", line 24, in <module> 3 approx = cv2.convexHull(contour) 4TypeError: Expected cv::UMat for argument 'points'
どうすればよいでしょうか
何卒、ご教授のほどよろしくお願いします
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/23 15:15