Opencv如何在曲线上获得更平滑的轮廓?

时间:2016-05-17 15:05:44

标签: opencv curve smooth opencv-contour

我面临一些问题,以便在曲线上获得更平滑的轮廓。 经过图像处理后我得到了这张图片。

enter image description here 我试图用这段代码获得更平滑的曲线:

imgWithBridgesBw = convert_to_bw(imgWithBridges)

# add later this mask upper
ellipsekernel20 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3,3))
enhanceMask = np.ones((InterholesBw.shape[0],InterholesBw.shape[1]) ,dtype="uint8") * 255
enhanceMaskColor = np.ones((InterholesBw.shape[0],InterholesBw.shape[1],3) ,dtype="uint8") * 255

# invert the Layer to get less blank pixels
imgWithBridgesBwInv = 255 - imgWithBridgesBw

imgWithBridgesBwInv_dilate = cv2.dilate(imgWithBridgesBwInv,ellipsekernel20,iterations =1)
imgWithBridgesBwInv_erode = cv2.erode(imgWithBridgesBwInv_dilate, ellipsekernel20, iterations = 1)  

_ ,allCnts, hier = cv2.findContours(imgWithBridgesBwInv_dilate,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

cv2.drawContours(enhanceMask,allCnts,-1,0,2)
cv2.drawContours(enhanceMaskColor,allCnts,-1,(255,0,0),2)

结果如下:

https://dl.dropboxusercontent.com/u/710615/testEhhancBwColor_.jpg

正如您在此图片中看到的那样,"缩放",我没有取得任何成功。

enter image description here

0 个答案:

没有答案