简体   繁体   English

用 Python 中的 OpenCV 检测掌纹

[英]Detecting palm lines with OpenCV in Python

I'm studying OpenCV with python by working on a project which aims to detect the palm lines.我正在通过一个旨在检测手掌线的项目来研究 OpenCV 和 python。

在此处输入图像描述

What I have done is basically use Canny edge detection and then apply Hough line detection on the edges but the outcome is not so good.我所做的基本上是使用Canny 边缘检测,然后在边缘上应用霍夫线检测,但结果不是很好。

在此处输入图像描述

Here is the source code I am using:这是我正在使用的源代码:

original = cv2.imread(file)
img = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
save_image_file(img, "gray")

img = cv2.equalizeHist(img)
save_image_file(img, "equalize")

img = cv2.GaussianBlur(img, (9, 9), 0)
save_image_file(img, "blur")

img = cv2.Canny(img, 40, 80)
save_image_file(img, "canny")

lined = np.copy(original) * 0
lines = cv2.HoughLinesP(img, 1, np.pi / 180, 15, np.array([]), 50, 20)
for line in lines:
    for x1, y1, x2, y2 in line:
        cv2.line(lined, (x1, y1), (x2, y2), (0, 0, 255))
save_image_file(lined, "lined")

output = cv2.addWeighted(original, 0.8, lined, 1, 0)
save_image_file(output, "output")

I tried different parameter sets of Gaussian kernel size and Canny low/high thresholds, but the outcome is either having too much noises, or missing (part of) major lines.我尝试了高斯 kernel 大小和 Canny 低/高阈值的不同参数集,但结果要么噪音太大,要么缺少(部分)主要线。 Above picture is already the best I get, so far..到目前为止,上图已经是我得到的最好的了..

Is there anything I should do to get result improved, or any other approach would get better result?我应该做些什么来改善结果,或者任何其他方法会得到更好的结果?

Any help would be appreciated!任何帮助,将不胜感激!

What you are looking for is really experimental.您正在寻找的是真正的实验性。 You have already done the most important function.你已经完成了最重要的 function。 I suggest that you tune your parameters to get a reasonable and a noisy number of lines, then you can make some filtering:我建议您调整参数以获得合理且嘈杂的行数,然后您可以进行一些过滤:

  • using morphological filters,使用形态过滤器,

  • classification of lines (according to their lengths, fits on contrasted area...etc)线的分类(根据它们的长度,适合对比区域......等)

  • improving your categories by dividing the area of palm (without fingers) into a grid (4x4.. where 4 vertical fingers corners can define the configs of the grid).通过将手掌区域(没有手指)划分为网格(4x4 .. 其中 4 个垂直手指角可以定义网格的配置)来改进您的类别。

  • calculate the gradient image, orientation of lines may help as well计算梯度图像,线的方向也可能有帮助
  • Make a search about the algorithm "cumulative level lines detection", it can help for the certainty of detected lines搜索“累积水平线检测”算法,有助于检测线的确定性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM