gpt4 book ai didi

Python OpenCV : Reading an image along x and y axis

转载 作者:太空宇宙 更新时间:2023-11-03 21:41:50 25 4
gpt4 key购买 nike

目标:我正在尝试读取此图像中的第一个点(非零点)(显示为红色箭头)

enter image description here

from __future__ import division
import numpy as np

import cv2
im1 = cv2.imread('C:/Users/Desktop/Line.png', 0)
for x in range(0, im1.shape[0], 1):
for y in range(0, im1.shape[1], 1):
cpt = im1[x][y]
if 0 < cpt <= 255 :
print("This is the value", x,y)

但是,打印的点是这个(零点):

enter image description here

怎么会这样?

原始图像:

enter image description here

最佳答案

如果你的图像很干净(没有噪点),那么试试这个:

import cv2
import numpy as np
img = cv2.imread("JKNp9.png")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ys,xs = np.nonzero(gray)
idx = np.argsort(xs)[0]

pt = xs[idx], ys[idx]

print(pt)
cv2.line(img, pt, pt, (0,255,0), 3, cv2.LINE_AA)
cv2.imshow("img", img)
cv2.waitKey()

pt 是:(27, 388)

就是这样:

enter image description here

关于Python OpenCV : Reading an image along x and y axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49854608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com