画像があり、交差線が少なくても4つのポリゴンが生成されています。私は各ポリゴンの面積を測定したい。私のスクリプトでは輪郭を作成しようとしており、おそらく間違った方法を使っています。私はあなたの現在のコードを使用して輪郭を抽出するために、任意のアドバイス... source image
OpenCVを使用して画像から輪郭を抽出する
import cv2
import numpy as np
import time
# define range of color in HSV
lower_red = np.array([150,135,160])
upper_red = np.array([180,250,200])
white_line = np.array([255,255,255])
red_line = np.array([0,0,255])
im = cv2.imread('laser.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
cv2.imshow('imgray', im)
ret,thresh = cv2.threshold(imgray,127,255,0)
cv2.imshow('thresh', thresh)
# Remove some small noise if any.
dilate = cv2.dilate(thresh,None)
erode = cv2.erode(dilate,None)
cv2.imshow('erode', erode)
_, contours, hierarchy = cv2.findContours(erode,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
##for contour in contours:
## if (cv2.contourArea(contour) > 50):
## print contours
im2 = np.zeros((500,500,3), np.uint8)
cv2.drawContours(im2,contours,0,(125,125,0),1)
cv2.imshow('contours',im2)
k = cv2.waitKey(0)
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
elif k == ord('s'): # wait for 's' key to save and exit
cv2.imwrite('messigray.png',im2)
cv2.destroyAllWindows()
は私の答えはあなたの問題を解決しました:
あなたはちょうどこのような何かを行うことができ、いくつかの輪郭を選択し、それらを描きたい場合は
? – iamnotgoogle