如何从图像上方绘制的线条中收集像素?

问题描述 投票:0回答:1

我有一个使用cv2绘制了4条线的灰度图像:

Steel microstructure

但是现在我需要沿线收集像素值,创建“线轮廓”,创建四个列表,其值从左到右或从上到下。

我该怎么做?

import cv2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img

#defines a scale factor
escala=0.7
cinza_esc = cv2.resize(cinza,None,fx=escala,fy=escala,interpolation=cv2.INTER_LINEAR)

#collect the dimensions of the image
xdim=cinza_esc.shape[1]
ydim=cinza_esc.shape[0]
se=(0,0);ie=(xdim,0);sd=(0,ydim);id=(xdim,ydim)

#line and text attr
cor = (0,0,0) #define a cor (tons de cinza)
fonte = cv2.FONT_HERSHEY_SIMPLEX
tamanho=int(xdim/500)
tipo_lh=cv2.LINE_4

#create the lines
cv2.line(cinza_esc, sd, ie, cor, 2)
cv2.line(cinza_esc, se, id, cor, 2)
cv2.line(cinza_esc, (0,int(ydim/2)), (xdim,int(ydim/2)), cor, 2)
cv2.line(cinza_esc, (int(xdim/2),0), (int(xdim/2),ydim), cor, 2)

#presents image
cv2.imshow("Imagem com as linhas", cinza_esc)

cv2.waitKey(0)
cv2.destroyAllWindows()
python opencv cv2
1个回答
0
投票

您实际上根本不需要画线。

© www.soinside.com 2019 - 2024. All rights reserved.