Python OpenCV : Reading an image along x and y axis

标签 python image opencv

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

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/

相关文章:

Python Button 绑定(bind)两个函数并使用绑定(bind)发送参数

c++ - 为什么有这么多符号链接(symbolic link)?

python - 如何在python中动态创建类变量

python - 如何阻止 python 程序可执行文件打开 cmd shell?

python - 如何通过超时的 if 语句提出问题

python - Django静态图像不显示

image - Flutter图像内存未得到gc

ios - 动态改变图形资源颜色的策略

python - 如何在 TrackerCSRT 上使用 setInitialMask?

opencv - 内存中 libvlc 流图像时的主要输入错误和延迟