推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
woshichuanqilz
V2EX  ›  Python

opencv 识别表面 指针如何确定线段的长度就是每个指针的长度

  •  
  •   woshichuanqilz · Apr 20, 2021 · 2326 views
    This topic created in 1985 days ago, the information mentioned may be changed or developed.

    我用霍夫变换可以识别出来分针和时针, 但是我需要知道那条线更长, 这样才能知道那个是分针那个是时针。

    现在的问题是, 霍夫变换只是标注直线而不是线段, 所以这边没法知道那个指针更长, 这个应该怎么做?

    我用的测试图片 https://imgtu.com/i/c7ocLQ

    我现在用的代码

    import cv2
    import numpy as np
    
    img = cv2.imread('clock.png')
    h, w = img.shape[:2]
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 50, 150)
    
    lines = cv2.HoughLines(edges, 1, np.pi / 180, 100)
    
    for i in range(len(lines)):
        for rho, theta in lines[i]:
            a = np.cos(theta)
            b = np.sin(theta)
            x0 = a * rho
            y0 = b * rho
            x1 = int(x0 + w * (-b))
            y1 = int(y0 + w * (a))
            x2 = int(x0 - w * (-b))
            y2 = int(y0 - w * (a))
    
            cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 2)
    cv2.imshow("edges", edges)
    cv2.imshow("lines", img)
    cv2.waitKey()
    cv2.destroyAllWindows() 
    
    1 replies  •  2021-04-20 16:30:09 +08:00
    vincentV2
        1
    vincentV2  
       Apr 20, 2021
    HoughLinesP
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1419 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 16:41 · PVG 00:41 · LAX 09:41 · JFK 12:41
    ♥ Do have faith in what you're doing.