python - 如何从绘制在图像上的线中收集像素?
问题描述
我有一个灰度图像,我使用 cv2 绘制了 4 条线:
但是现在我需要沿线收集像素值,创建“线轮廓”,创建四个列表,其中的值从左到右写入或从上到下。
我怎样才能做到这一点?
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()
解决方案
您实际上根本不需要画线。
如果你使用skimage.draw.line它会给你一个在线点列表。
推荐阅读
- c# - 初始化后将配置文件添加到自动映射器
- arrays - 在不使用任何库的情况下反转字符串
- numpy - 使用另一个 numpy 数组索引 numpy 数组
- javascript - 如何在 IE9 的 fetchApi 中请求发布
- php - 在php中生成波斯蛞蝓
- java - CXF Client - unexpected XML tag. expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {null}html
- mysql - Why would long running select queries cause a replication lag in MySQL slave database?
- android - Chain Single independent requests with RxJava
- css - Vuetify 步进器文本溢出
- android - AIR android serversocket 仅适用于 ADL(空中调试启动器)