如何在Python中实现色块矩阵的精确检测器?
我先用一个例子来说明这个问题。
下面是一个示例输入图像,该图像可能带有噪声并且处于其他类型的仿射变换中。
输出应该返回一个二维数组/矩阵(使用标准颜色字符来表示每个颜色块)就像
[[w, g, w, b],
[y, o, o, y],
[g, b, g, y],
[b, o, y, b]]
所以这个问题的目的是检测矩阵每个输入图像的颜色块文件,方向并不重要。
解决这个问题的想法给了我直觉,解决方案就像检测和解析二维码,但我不知道具体如何解决。
谁能给我一些建议,比如
- 解决这个问题的想法/程序。
- 我应该探索和使用哪些 Python 包的哪些 API。
- 任何类似的经典问题我都应该深入研究。
- 一些正确的代码。
- ...
Let me illustrate the problem with an example first.
Below is an example input image which might be noised and in other kinds of affine transformation.
The output should return a 2-D array/matrix (Use a standard color character to represent each color block) like
[[w, g, w, b],
[y, o, o, y],
[g, b, g, y],
[b, o, y, b]]
So the aim of this problem is to detect the matrix of color blocks for each input image file, and the orientation doesn't matter.
The idea to solve this problem gives me the intuition that the solution is like detecting and parsing a QR code, but I don't know how to work it out specifically.
Could anyone give me some suggestions like
- The idea/procedure to solve this problem.
- Which APIs of which Python packages should I explore and use.
- Any similar classic problem that I should delve into.
- Some proper code.
- ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们可以从找到黑点并“校正”图像开始
。可以通过阈值处理和寻找“圆形”斑点来找到角点。该指标可以在这里找到:https://learnopencv.com/blob-检测使用-opencv-python-c/
一旦我们有了角点,我们就会“校正”图像(图像可能会旋转和/或根据角的顺序翻转)
转换为 HSV
在“v”通道上再次蒙版以获取各个方块
然后我们计算平均色调和每个方块的饱和度以平滑噪声
(我们需要饱和度来区分白色方块)
我们可以将这些数字与预定义的颜色值进行匹配以打印出字符串:
完整代码
We can start by finding the black dots and "rectifying" the image
The corners can be found by thresholding and looking for "circular" blobs. The metric can be found here: https://learnopencv.com/blob-detection-using-opencv-python-c/
Once we have the corners we "rectify" the image (the image may be rotated and/or flipped depending on the ordering of the corners)
Convert to HSV
Mask again on the "v" channel to get the individual squares
Then we calculate the average hue and saturation of each square to smooth over noise
(we need the saturation to distinguish white squares)
We can match these numbers up against our pre-defined color values to print out a string:
Full Code