Pythonを学習している初学者です。
足の輪郭を取得したいのですが、どのようにすれば取得できますでしょうか?
ご教示いただけると幸いです。
import cv2 import numpy as np Img = cv2.imread("*******", 1) A4Height,A4Width=29.7,21 height = Img.shape[0] width = Img.shape[1] img1 = cv2.resize(Img , (int(width*0.5), int(height*0.5))) shapeHih,shapeWid=img1.shape[0],img1.shape[1] print(shapeHih,shapeWid) gray = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)#cv2.COLOR_RGB2GRAY cv2.COLOR_BGR2GRAY img_h=cv2.GaussianBlur(gray, (19, 9), 31) threshold = 100 # 二値化(閾値100を超えた画素を255にする。) dd,thresh = cv2.threshold(img_h,110,250 , cv2.THRESH_BINARY) coytu,cnts = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)#cv2.RETR_LIST cv2.RETR_EXTERNAL # 二値化画像の表示 for i in range(0,len(coytu)): if len(coytu[i])>0: if cv2.contourArea(coytu[i]) < 1: continue #eがx座標#fがy座標 gがx座標 hがy座標 rect = coytu[i] e,f,g,h = cv2.boundingRect(rect) #画像 #左上タプル # 右下タプル #色を指定 rect=cv2.rectangle(img1,(e,f),(e+g,f+h),(0,0,255),2) print("e",e,"f",f,"g",g,"h",h) dd=cv2.line(img1,(e,h),(g,h),(0, 255, 0), thickness=2,lineType=cv2.LINE_AA)#640→をgに変更したら e 40 f 0 g 599 h 372 #dd=cv2.line(img1,(40,372),(599,372),(0, 255, 0), thickness=2,lineType=cv2.LINE_AA)#640→をgに変更したら e 40 f 0 g 599 h 372 aca=np.array([e,h]) bcb=np.array([g,h]) df=aca- bcb print(np.linalg.norm(df)*A4Width/shapeWid) cv2.imshow('img1',img1) cv2.waitKey() cv2.destroyAllWindows()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/24 05:37
退会済みユーザー
2021/08/24 21:34