程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to use python+opencv to extract coordinate positions of rectangular vertices in a picture

編輯:Python

So let's take this picture , How to determine the four vertex coordinates of Eileen Chang's picture and extract its picture ?
I can only get its outline , The coordinates cannot be determined




Take the answer :

First perform edge detection :
hypothesis
CANNY_THRESH_1 = 90
CANNY_THRESH_2 = 120
edges = cv2.Canny(gray, CANNY_THRESH_1, CANNY_THRESH_2)
edges = cv2.dilate(edges, None, iterations=3)
edges = cv2.erode(edges, None, iterations=1)
The edge features are obvious , The coefficients of different pictures have little difference . The current coefficient effect can use . The finer parameters are not adjusted .
In addition, some amplification and corrosion have been done , Filter out some small text areas that you don't need . Easy to filter unwanted contours .

Then extract the contour :

Find the outline

contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

Show all outlines

mask = np.zeros(img.shape)for c in contours:

Filter small area

if (cv2.contourArea(c) < scale ** 2):
continue
cv2.drawContours(mask, [c], 0, (0, 0, 255))cv2.imshow('contours', mask)
About functions findContours The introduction can refer to :https://www.cnblogs.com/yiyi20120822/p/11506970.html

After the contour is extracted, the desired result can be obtained by using the smallest bounding rectangle of a single room .

Finally, extract the rectangle to obtain the vertex :
rect = cv2.minAreaRect(cnt)box = cv2.boxPoints(rect)box = np.int0(box)
You can get the vertex coordinates



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved