tags: Computer vision opencv python
The original image is

import cv2
import numpy as np
import matplotlib.pyplot as plt
def cv_show(name, img):
cv2.imshow(name, img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Read the image
img = cv2.imread('contours.png')
cv_show('contours', img)
# Gray degree and dual value
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)[1]
cv_show('thresh', thresh)
#
cnt = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]
After outline detection, the value of the output is CNT, the type is list, and the number of elements is 11, which contains 11 contour

C0 is indexed in CNT as 0, which represents the first outline, that is, the triangular outline
c0 = cnt[0]
res = cv2.drawContours(draw, [c0], -1, (0, 0, 255), 2)
cv_show('res', res)


The outline is similar below
epsilon = 0.1 * cv2.arcLength(c0, True)
approx = cv2.approxPolyDP(c0, epsilon, True)
draw_img = img.copy()
res = cv2.drawContours(draw_img, [approx], -1, (0, 0, 255), 2)
cv_show('res', res)
CV2.APAPROXPLOYDP function output APPROX, the number of elements is 3, that is, the three vertices of the triangle

Use python to traverse and output the vertex coordinates of the arcgis line or surface Code first, then detailed explanation operation result: import arcpy Import the module, because arcpy is used, so...
First, the problem and solution The inspiration for this method came from yesterday yesterday, let's talk about implementing the function. There has always been a need for four-to-coordinate extractio...
approxPolyDP method: Function effect: Polygonal approximation curve specified precision parameter: curve: a collection of contour point input approxCurve: output set of contour points. Save the...
Method principle: According to the definition of vector cross product, the cross product of vectors OA and OB is greater than 0, then vector OB is in the counterclockwise direction of vector OA, that ...
Function of CV2.Approxpolydp ():...
The algorithm analysis and the design teacher's placement test assignments, one of which is the approximate calculation of the vertex cover problem, thinks for a long time, thinks of a train of though...
2019 Unicorn Enterprise Heavy Recruitment Python Engineer Standard >>> OpenGL polygon filling function The function GlvertEX is used to enter a vertex coordinate of the polygon, and the compl...
1, approxPolyDP function The function of the function: Fit polygons of image outline points 2. The calling form of the function C++: void approxPolyDP (InputArray curve, OutputArray approxCurve, doubl...
When using non-fixed pipelines for texture rendering, the mapping relationship between texture and vertex coordinates is often used. Here, the two-dimensional texture coordinate mapping is introduced ...