opencv python:如何绘制图像轮廓
我想在我的图像中找到轮廓,如下所示:opencv python:如何绘制图像轮廓,python,python-2.7,opencv,Python,Python 2.7,Opencv,我想在我的图像中找到轮廓,如下所示: import cv2 import numpy as np import matplotlib.pyplot as plt import os, sys OriginalImage = cv2.imread('test.png',0) # get the a gray-scale image plt.figure(1) plt.subplot(221),plt.imshow(OriginalImage,'gray') GaussianImage =
import cv2
import numpy as np
import matplotlib.pyplot as plt
import os, sys
OriginalImage = cv2.imread('test.png',0) # get the a gray-scale image
plt.figure(1)
plt.subplot(221),plt.imshow(OriginalImage,'gray')
GaussianImage = cv2.GaussianBlur(OriginalImage,(3,3),0)
plt.subplot(222),plt.imshow(GaussianImage,'gray')
ret,thrsh_GaussianImage = cv2.threshold(GaussianImage,50,255,cv2.THRESH_BINARY)
plt.subplot(223),plt.imshow(thrsh_GaussianImage,'gray')
plt.show()
im, contours, hierarchy = cv2.findContours(thrsh_GaussianImage,cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(thrsh_GaussianImage,contours,-1,(0,255,0),3)
cv2.imshow("j", im)
cv2.waitKey()
但问题是最后一张图像,即我的轮廓没有显示出来。 我还删除了plt。显示。。。但它并没有显示任何东西。 我应该怎么做才能显示轮廓 我查看了以前的帖子。。。他们曾建议添加最后两行,但仍然不适合我 还有一件事是在我的pycharm页面上 将numpy作为np导入 没有蓝色和灰色。。。全是灰色的。。。不管它如何工作。但我不知道为什么会这样 这对我很有用:
cv2.drawContours(thrsh_GaussianImage,contours,-1,(128,255,0),3)
如果你知道原因,请把它贴出来。我现在没有时间玩弄它或研究它