cv2.putText



Cv2 Puttext



import cv2 o = cv2.imread('cs.bmp') cv2.imshow('original',o) #Get convex hull gray = cv2.cvtColor(o,cv2.COLOR_BGR2GRAY) ret,binary = cv2.threshold(gray,127,255,cv2.THRESH_BINARY) contours,hierarchy = cv2.findContours(binary,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)#No hierarchical relationship is established for the detected contours, only a few points are kept hull = cv2.convexHull(contours[0]) image = cv2.cvtColor(binary,cv2.COLOR_GRAY2BGR) cv2.polylines(image,[hull],True,(0,255,0),2) #The distance from the inner point A to the contour distA = cv2.pointPolygonTest(hull,(300,150),True) font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(image,'A',(300,150),font,1,(0,255,0),3)#Write the text on the picture, the parameters are: picture, added text, upper left corner coordinates, font, font size, color, font thickness print('distA = ',distA) cv2.imshow('result1',image) cv2.waitKey() cv2.destoryAllWindows()

結果:
distA = 16.891650862259112

画像