如何识别图片中的钞票?

2023-12-08

我有一些欧元钞票的图片。账单完全在图像内 并且大多是平坦的(例如变形很小)并且透视倾斜很小(例如完全从钞票上方拍摄的图像)。

现在我不是图像识别方面的专家。我想实现以下目标:

  • 找到钞票的边界框(这样我就可以从图像其余部分的噪声中“剪掉”钞票)
  • 弄清楚方向。

我认为这两个步骤是预处理,但也许可以在没有上述两个步骤的情况下执行以下步骤。因此我想读:

  • 票据序列号。
  • 票据的面值。

我认为使用 OpenCV 应该可以做到这一点。我只是不确定如何正确处理它。我会选择像方法或霍夫这样的人脸检测器还是边缘检测器上的轮廓检测器?

对于阅读材料的任何进一步提示,我也将不胜感激。


霍夫很棒,但可能有点贵

这可能有效:

- 使用 Threshold 或 Canny 找到图像的边缘。

-然后cvFindContours识别轮廓,然后尝试检测矩形。 检查 opencv 发行版中的 squares.c 示例。它基本上检查轮廓的多边形近似是否有 4 个点,并且这些点之间的平均角度是否接近 90 度。 这是 squares.py 示例中的代码片段 (是相同的,但是在 python 中:P)。

  ..some pre-processing
  cvThreshold( tgray, gray, (l+1)*255/N, 255, CV_THRESH_BINARY );

        # find contours and store them all as a list
        count, contours = cvFindContours(gray, storage)

        if not contours:
            continue

        # test each contour
        for contour in contours.hrange():
            # approximate contour with accuracy proportional
            # to the contour perimeter
            result = cvApproxPoly( contour, sizeof(CvContour), storage,
                CV_POLY_APPROX_DP, cvContourPerimeter(contour)*0.02, 0 );
            res_arr = result.asarray(CvPoint)
            # square contours should have 4 vertices after approximation
            # relatively large area (to filter out noisy contours)
            # and be convex.
            # Note: absolute value of an area is used because
            # area may be positive or negative - in accordance with the
            # contour orientation
            if( result.total == 4 and 
                abs(cvContourArea(result)) > 1000 and 
                cvCheckContourConvexity(result) ):
                s = 0;
                for i in range(4):
                    # find minimum angle between joint
                    # edges (maximum of cosine)
                    t = abs(angle( res_arr[i], res_arr[i-2], res_arr[i-1]))
                    if s<t:
                        s=t
                # if cosines of all angles are small
                # (all angles are ~90 degree) then write quandrange
                # vertices to resultant sequence
                if( s < 0.3 ):
                    for i in range(4):
                        squares.append( res_arr[i] )

-使用 MinAreaRect2(查找给定 2D 点集的最小面积的外接矩形),获取矩形的边界框。使用边界框点可以轻松计算角度。

您还可以在 opencv 目录中的samples/c/ 下找到C 版本的squares.c。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何识别图片中的钞票? 的相关文章

随机推荐