Add Java and Python code for ML tutorials.
This commit is contained in:
+2
-2
@@ -25,8 +25,8 @@ def thresh_callback(val):
|
||||
boundRect = [None]*len(contours)
|
||||
centers = [None]*len(contours)
|
||||
radius = [None]*len(contours)
|
||||
for i in range(len(contours)):
|
||||
contours_poly[i] = cv.approxPolyDP(contours[i], 3, True)
|
||||
for i, c in enumerate(contours):
|
||||
contours_poly[i] = cv.approxPolyDP(c, 3, True)
|
||||
boundRect[i] = cv.boundingRect(contours_poly[i])
|
||||
centers[i], radius[i] = cv.minEnclosingCircle(contours_poly[i])
|
||||
## [allthework]
|
||||
|
||||
+6
-6
@@ -22,22 +22,22 @@ def thresh_callback(val):
|
||||
# Find the rotated rectangles and ellipses for each contour
|
||||
minRect = [None]*len(contours)
|
||||
minEllipse = [None]*len(contours)
|
||||
for i in range(len(contours)):
|
||||
minRect[i] = cv.minAreaRect(contours[i])
|
||||
if contours[i].shape[0] > 5:
|
||||
minEllipse[i] = cv.fitEllipse(contours[i])
|
||||
for i, c in enumerate(contours):
|
||||
minRect[i] = cv.minAreaRect(c)
|
||||
if c.shape[0] > 5:
|
||||
minEllipse[i] = cv.fitEllipse(c)
|
||||
|
||||
# Draw contours + rotated rects + ellipses
|
||||
## [zeroMat]
|
||||
drawing = np.zeros((canny_output.shape[0], canny_output.shape[1], 3), dtype=np.uint8)
|
||||
## [zeroMat]
|
||||
## [forContour]
|
||||
for i in range(len(contours)):
|
||||
for i, c in enumerate(contours):
|
||||
color = (rng.randint(0,256), rng.randint(0,256), rng.randint(0,256))
|
||||
# contour
|
||||
cv.drawContours(drawing, contours, i, color)
|
||||
# ellipse
|
||||
if contours[i].shape[0] > 5:
|
||||
if c.shape[0] > 5:
|
||||
cv.ellipse(drawing, minEllipse[i], color, 2)
|
||||
# rotated rectangle
|
||||
box = cv.boxPoints(minRect[i])
|
||||
|
||||
Reference in New Issue
Block a user