1. 效果图
自己画一张图,原图 VS 骨架效果图如下:
opencv logo原图 VS 骨架化效果图如下:
2. 源码
# 图像骨架化~ import cv2 import imutils import numpy as np img = np.zeros((390, 390, 3), dtype="uint8") cv2.putText(img, "Beautiful Girl.....", (50, 190), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 3) cv2.imshow("img", img) cv2.waitKey(0) cv2.imwrite("j.jpg", img) # 骨架图依赖灰度图 # 灰度图转换法一 img = cv2.imread("opencv_logo.jpg") # 读取为BGR图 cv2.imshow("origin", img) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # BGR图转换灰度图 # 灰度图转换二 gray = cv2.imread("opencv_logo.jpg", 0) # 直接读取为灰度图 cv2.imshow("gray", gray) # 骨架化图像 skeleton = imutils.skeletonize(gray, size=(3, 3)) cv2.imshow("Skeleton", skeleton) cv2.waitKey(0)
参考:
https://www.pyimagesearch.com/2015/02/02/just-open-sourced-personal-imutils-package-series-opencv-convenience-functions/
以上就是基于Python的OpenCV骨架化图像并显示(skeletonize)的详细内容,更多关于Python的OpenCV骨架化图像的资料请关注服务器之家其它相关文章!
原文链接:https://blog.csdn.net/qq_40985985/article/details/118655620