当我应用cv2.erode()和不同的kernel值时,我一直在观察结果.在下面的代码中,它是(3, 3),但它被更改为(1, 3)(5, 1)等各种方式.这一观察的原因是为了理解kernel.

我在理论上理解.通过实践,我可以看到我得到了什么样的结果.但我想深入一点.

I would like to see what happens every time the pixel targeted by 100 changes.

如果您存储了数千张图像,那也没关系.

如何观察cv2.erode()的中间过程?我要求太多了吗?

image = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
_, thresholded_image = cv2.threshold(image, 127, 255, cv2.THRESH_BINARY)
inverted_image = cv2.bitwise_not(thresholded_image)

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
eroded_image = cv2.erode(inverted_image, kernel, iterations=5)

cv2.imshow('image', eroded_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

推荐答案

当您从Python调用cv2.erode时,最终会归结为一次C++ API调用cv::erode.

正如您在documentation中看到的那样,此API不支持判断流程的中间结果.这意味着它也无法从Python包装器中获得.

The only way you can achieve what you want is to download the C++ source code for opencv (as it is open-source), change it to support inspecting intermediate result (e.g. by adding callbacks, or additional output images), compile it to a library and wrap for Python.
Keep in mind however that doing so is far from being trivial.

Python相关问答推荐

无法在Python中使用Selenium标记正确的元素以抓取网站

用ctype构建指针链

自动编码器和极坐标

想要使用Polars groupby_Dynamic来缩减时间序列收件箱(包括空垃圾箱)

我可以使用极点优化这个面向cpu的pandas代码吗?

Python中使用Delivercio进行多个请求

由于瓶颈,Python代码执行太慢-寻求性能优化

Image Font生成带有条形码Code 128的条形码时出现枕头错误OSErsor:无法打开资源

跟踪我已从数组中 Select 的样本的最有效方法

如何使用pandasDataFrames和scipy高度优化相关性计算

Pystata:从Python并行运行stata实例

通过Selenium从页面获取所有H2元素

Streamlit应用程序中的Plotly条形图中未正确显示Y轴刻度

从spaCy的句子中提取日期

如何在表中添加重复的列?

Pandas Loc Select 到NaN和值列表

提取相关行的最快方法—pandas

多处理队列在与Forking http.server一起使用时随机跳过项目

Pandas Data Wrangling/Dataframe Assignment

将标签移动到matplotlib饼图中楔形块的开始处