python中,有些函數輸入需要是array類型的,如cv2.boundingRect(),需要把list格式轉爲array。 如已知手部21個關節點的(x,y)座標,求這些關節點的最小外接矩形 all_points = [] for hand_pt in hand_pts_all: x = float(hand_pt[0]) y = float(hand_pt[1]) points = [x, y] all_points.append(points) a = np.array(all_points, dtype = np.float32)#list轉爲array #外接矩形框,沒有方向角 x, y, w, h = cv2.boundingRect(a)
注意,在a = np.array(all_points, dtype = np.float32),一定要寫dtype = np.float32,否則默認是double型,執行函數 cv2.boundingRect(a)會報錯。