小编Gui*_*Gui的帖子

OpenCV findContours() 只返回一个外部轮廓

我试图隔离验证码中的字母,我设法过滤了验证码,结果得到了这张黑白图像:

在此处输入图片说明

但是当我尝试使用 OpenCV 的 findContours 方法分离字母时,它只是发现了一个包裹我整个图像的外部轮廓,从而产生了这个图像(图像外的黑色轮廓)。

在此处输入图片说明

我将此代码与 Python 3 和 OpenCV 3.4.2.17 一起使用:

img = threshold_image(img)
cv2.imwrite("images/threshold.png", img)

image, contours, _ = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

for i, contour in enumerate(contours):
    area = cv2.contourArea(contour)
    cv2.drawContours(img, contours, i, (0, 0, 0), 3)

cv2.imwrite('images/output3.png', img)
Run Code Online (Sandbox Code Playgroud)

我只希望我的最终结果是每个字符外有 5 个轮廓。

python captcha opencv opencv-contour cv2

2
推荐指数
1
解决办法
7457
查看次数

如何通知用户他在 Django 登录视图中不活跃

我正在为 Django 创建一个自定义身份验证应用程序,一切都很好,用户需要验证电子邮件以设置 is_active True,这就像一个魅力,但是一旦用户发送电子邮件并且令牌过期,用户就会尝试登录并收到用户或通过不正确的消息,我想显示用户必须激活帐户并提供链接以将激活令牌重新发送到他的电子邮件。

我正在使用默认的登录视图:

url(r'^login/$', auth_views.LoginView.as_view(template_name='accounts/login.html'), name='account_login')
Run Code Online (Sandbox Code Playgroud)

如何修改此视图或其他内容以显示用户未处于活动状态?

查看来自 Django auth 的 AuthenticationForm 我可以看到有一个非活动用户错误,但在登录表单中只引发了错误 invalid_login 。

class AuthenticationForm(forms.Form):
    """
    Base class for authenticating users. Extend this to get a form that accepts
    username/password logins.
    """
    username = UsernameField(
        max_length=254,
        widget=forms.TextInput(attrs={'autofocus': True}),
    )
    password = forms.CharField(
        label=_("Password"),
        strip=False,
        widget=forms.PasswordInput,
    )

    error_messages = {
        'invalid_login': _(
            "Please enter a correct %(username)s and password. Note that both "
            "fields may be case-sensitive."
        ),
        'inactive': _("This account is inactive."),
    }

    def __init__(self, …
Run Code Online (Sandbox Code Playgroud)

python authentication django

1
推荐指数
2
解决办法
4751
查看次数

标签 统计

python ×2

authentication ×1

captcha ×1

cv2 ×1

django ×1

opencv ×1

opencv-contour ×1