我必须在OpenCV中执行此图像之间的圆形和矩形的检测以及检测:
我正在尝试:
import cv2
import numpy as np
cv2.namedWindow("jan", cv2.WINDOW_AUTOSIZE)
image = cv2.imread("vit.jpg", cv2.IMREAD_ANYCOLOR)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edge = cv2.Canny(gray,500,500)
contours, hierarchy = cv2.findContours(edge,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)[-2:]
print(contours)
cv2.drawContours(image, contours, -1, (0,0,255), 10)
cv2.imshow("jan", image)
cv2.waitKey(0)
cv2.destroyAllWindows()
但是我得到这个结果:如何仅使用圆形和矩形执行此操作?
最佳答案
您可以绘制的圆圈如下:
image = cv2.imread("vit.jpg", cv2.IMREAD_ANYCOLOR)
grayImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edgeImage = cv2.Canny(grayImage, 50, 100)
circles = cv2.HoughCircles(edgeImage,cv2.HOUGH_GRADIENT,1,240,
param1=50,param2=20,minRadius=0,maxRadius=0)
if circles is not None:
for circles in circles[0, :]:
x = circles[0]
y = circles[1]
radius = int(circles[2])
cv2.circle(image, (x,y), radius, (255,0,0), 5)
和您的返回:关于python - 如何从Vitruvian Man OPENCV查找和轮廓化圆形和矩形,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63972565/