我需要用python获得一个矩阵,其中包含下图的轮廓坐标(x,y).
我尝试使用opencv canny探测器并找到轮廓,但我得到了很多轮廓,我不知道如何得到我想要的那个.
import numpy as np
from matplotlib import pyplot as plt
import cv2
#from skimage import measure, feature, io
#from skimage import img_as_ubyte
x1 = 330
xf = 690
y1 = 0
yf = 400
img = cv2.imread('test.tif')
img = img[y1:yf, x1:xf]
edge = cv2.Canny(img, 100, 200)
image, contours, hierarchy = cv2.findContours(edge, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
Run Code Online (Sandbox Code Playgroud)
我只需要一个具有轮廓(x,y)坐标的数组.我认为它是在轮廓输出中,cv2.findContours()但我没有找到我想要的轮廓...
我也尝试过这个matplotlib.pyplot.contour功能:
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('test.tif', 0) # read …Run Code Online (Sandbox Code Playgroud)