Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
66 views
in Technique[技术] by (71.8m points)

python - Vertex become rounder after use canny

I'm using canny to try to find the edges on an image, the problem I have is canny make my vertex rounder. In the 4° image you can see the result of Canny where the vertex are curve. Result of operation

I try one more complex code from here https://www.geeksforgeeks.org/implement-canny-edge-detector-in-python-using-opencv but the result was worse.For that reason, I ask here.

import cv2
import numpy as np
from stack import*
path=r"C:UsersmPycharmProjectsopencvshapes.png"
img=cv2.imread(path)

imgGray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
imgBlur=cv2.GaussianBlur(imgGray,(5,5),1)#promedia pixeles en gurpos de x,x  suavisando la imagen
imgCanny= auto_canny(imgBlur,0.33)

imgContours=imgCanny.copy()
getContours(imgContours)
imgBlank=np.zeros_like(img)

imgStack=stackImages(1,([img,imgGray,imgBlur],[imgCanny,imgContours,imgBlank]))

cv2.imshow("Image",imgStack)
cv2.waitKey(0)

def auto_canny(image, sigma=0.33):
    # compute the median of the single channel pixel intensities
    v = np.median(image)
    # apply automatic Canny edge detection using the computed median
    lower = int(max(0, (1.0 - sigma) * v))
    upper = int(min(255, (1.0 + sigma) * v))
    edged = cv2.Canny(image, lower, upper)
    # return the edged image
    return edged
def getContours(img):
    contours,hierarchy = cv2.findContours(img,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
    for cnt in contours:
        area=cv2.contourArea(cnt)
        #print(area)
        if area>500:
            cv2.drawContours(img, cnt, -1, (255, 0, 0), 1)
            perimetro=cv2.arcLength(cnt,True)
            print(perimetro)
            approx=cv2.approxPolyDP(cnt,0.02*perimetro,True)
            print(approx)
question from:https://stackoverflow.com/questions/65836750/vertex-become-rounder-after-use-canny

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...