Преобразование белых пикселей в черный в OpenCV python
Я нашел подходящее решение.
Однако теперь круговая форма в правом верхнем углу не обнаруживается. Все 3 прямоугольника найдены. треш
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (5, 5), 0)
thresh = cv.threshold(blurred, 103, 255, cv.THRESH_BINARY)[1]
cnts = cv.findContours(thresh.copy(), cv.RETR_EXTERNAL,
cv.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# loop over the contours
for c in cnts:
# compute the center of the contour
M = cv.moments(c)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
# draw the contour and center of the shape on the image
cv.drawContours(image, [c], -1, (0, 255, 0), 2)
cv.circle(image, (cX, cY), 7, (255, 255, 255), -1)
cv.putText(image, "center", (cX - 20, cY - 20),
cv.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
# show the image
cv.namedWindow('image', cv.WINDOW_NORMAL)
cv.imshow('image', image)
cv.waitKey(0)