我想找一束不同图像的激光.

Example image:

The Original one:

我找到了不同的方法,但不知何故,它似乎不工作. 我现在还使用了一个阈值:

logicM = image > Threshold
plt.figure()
plt.imshow(logicM, cmap='gray')
plt.axis('image')
plt.title(laserColor + ' band intensity over ' + str(Threshold))

来识别这条线.现在我想用一条虚线标记横梁.然后绘制高度(即像素)上的强度.如何做到这一点呢?我就是想不通.

我发现了这个: Vertical curved line detection with OpenCV 并且 Draw a curve line going through the blobs in OpenCV C++

两者都不起作用.

编辑:理论公式可以在这里找到,但有没有简单的OpenCV解决方案?: https://mv.in.tum.de/_media/members/steger/publications/1996/icpr-96-steger.pdf

EDIT2: 我试着这样做,以获得等高线之间的值.

# Sort the contour points by their y-value
contour_points_by_row = {}
for contour in contours:
    print(contour)
    for point in contour:
        x, y = point[0]  # Zugriff auf die x- und y-Koordinaten
        if y in contour_points_by_row:
            contour_points_by_row[y].append(x)
        else:
            contour_points_by_row[y] = [x]

但是数组太短了.更多的 idea ?

推荐答案

这确实起到了隔离光束的作用--可能有一些工具可以用来获得折线近似,而不是区域轮廓.

import cv2
from matplotlib import pyplot as plt

img = cv2.imread("hQiak.png")

# Mask in HSV space to keep only the vivid red color
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower_red = (0, 100, 20)
upper_red = (10, 255, 255)
mask = cv2.inRange(hsv, lower_red, upper_red)

plt.imshow(mask, cmap="gray")

# Detect contours from mask
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Only keep the largest contour
contours = [max(contours, key=cv2.contourArea)]

cv2.drawContours(img, contours, -1, (0, 255, 0), 3)
plt.figure(dpi=250)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.show()

enter image description here

Python相关问答推荐

如何在Deliveryter笔记本中从同步上下文正确地安排和等待Delivercio代码中的结果?

Pydantic 2.7.0模型接受字符串日期时间或无

比较两个数据帧并并排附加结果(获取性能警告)

使用numpy提取数据块

为什么我的Python代码在if-else声明中的行之前执行if-else声明中的行?

重新匹配{ }中包含的文本,其中文本可能包含{{var}

如何使用matplotlib在Python中使用规范化数据和原始t测试值创建组合热图?

如何删除索引过go 的lexsort深度可能会影响性能?' &>

numpy卷积与有效

Scrapy和Great Expectations(great_expectations)—不合作

计算分布的标准差

让函数调用方程

numpy.unique如何消除重复列?

ruamel.yaml dump:如何阻止map标量值被移动到一个新的缩进行?

30个非DATETIME天内的累计金额

按条件添加小计列

如何在Python中自动创建数字文件夹和正在进行的文件夹?

如果不使用. to_list()[0],我如何从一个pandas DataFrame中获取一个值?

如何从数据框列中提取特定部分并将该值填充到其他列中?

如何将django url参数传递给模板&S url方法?