平均,分散,共分散を求めたいのですが,
xs = [] ys = [] files = glob.glob("./tras/*") for i, f in enumerate(files): img = cv2.imread(f) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) binary = cv2.dilate(binary, kernel) contours, hierarchy = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) target_contour = max(contours, key=lambda x: cv2.contourArea(x)) area = cv2.contourArea(target_contour) retval = cv2.arcLength(target_contour, True) ratio=area/retval xs.append(ratio) hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) h, s, v = cv2.split(hsv) v=v[10 < v ] value = v [ v < 225].mean() ys.append(value) xt = [] yt = [] files = glob.glob("./sisaku-pu/*") for i, f in enumerate(files): img = cv2.imread(f) save_path = './pura/_%d.jpg' % i cv2.imwrite(save_path, img) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) ret, binary = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU) kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)) binary = cv2.dilate(binary, kernel) contours, hierarchy = cv2.findContours(binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) target_contour = max(contours, key=lambda x: cv2.contourArea(x)) area = cv2.contourArea(target_contour) retval = cv2.arcLength(target_contour, True) ratio=area/retval xt.append(ratio) hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) h, s, v = cv2.split(hsv) v=v[10 < v ] value = v [ v < 225].mean() yt.append(value) xst =xt+xs yst =yt+ys s = sum(xt) N = len(xt) mxt = s / N print('平均: {0:.4f}'.format(mxt)) s = sum(yt) N = len(yt) myt = s / N print('平均: {0:.4f}'.format(myt)) s = sum(xs) N = len(xs) mxs= s / N print('平均: {0:.4f}'.format(mxs)) s = sum(ys) N = len(ys) mys = s / N print('平均: {0:.4f}'.format(mys)) mxst = mean(xst) variancexst =np.var(xst, ddof=1) print('平均: {0:.4f}'.format(mxst)) print('分散: {0:.4f}'.format(variancexst)) myst = mean(yst) varianceyst =np.var(yst, ddof=1) print('平均: {0:.4f}'.format(myst)) print('分散: {0:.4f}'.format(varianceyst)) コード
xs,ys,xt,yt,xst,ystの平均値,xst,ystの分散までは求められたのですが,
xst,ystの共分散が求められません。
どなたかよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。