0
私は与えられた矩形の各コーナーの座標を見つけようとしています。 これまで輪郭関数を使って2つのコーナーを得ることができましたが、輪郭配列全体を見渡すと豊富な点があります。私は私が私とすべてであるように思わポイントの巨大な配列に何contours
戻りふるいにかけ輪郭の座標を見つける
import cv2
import numpy as np
#open image
img = cv2.imread('cnt-coords.jpg')
#convert to black and white
bw = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#threshold image
ret, thresh = cv2.threshold(bw,127,255,0)
#find contours
im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
#obtain the first 2 points of contours
cntx1 = contours[0][0]
cntx = contours[0][1]
#convert coords to points
pt1 = (cntx1[0][0],cntx1[0][1])
pt2 = (cntx[0][0],cntx[0][1])
#draw circles on coordinates
cv2.circle(img,pt1,5,(0,255,0),-1)
cv2.circle(img,pt2, 5, (0,255,0),-1)
#display the image
cv2.imshow('f',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
最も極端な値(最大値と最小x軸とyの値)を探しています私のイメージの対角線に沿ってポイント。私が受け取っている点、この場合はこの矩形/平行四辺形の角を単純化する方法はありますか?
ありがとうございます - 約10%の円弧長を使用していただきありがとうございます。私は平行四辺形の長方形の四隅をすべて見つけることができました –