【问题标题】:How do I average two points in python in OpenCV?如何在 OpenCV 中的 python 中平均两分?
【发布时间】:2012-03-29 06:55:28
【问题描述】:

我一直试图弄清楚如何在 OpenCV 中平均 2 分,但每当我尝试某事时,我通常会收到一个错误,涉及不正确使用元组。我试图找到 cv.HoughLines2 返回的线的中心点。我知道 line[0] 存储 (x1, y1) 和 line[1] 存储 (x2, y2) 项,但我不知道如何平均以便可以在 cv2.circle() 中使用它们。

如何在 OpenCV 中平均两分?

lines = cv.HoughLines2(dst, storage, cv.CV_HOUGH_PROBABILISTIC, rho, cv.CV_PI/(theta+1), thresh_1, min_len, max_dist)

i = 0
avr = 0
for line in lines:
         #print line

        cv.Line(image, line[0], line[1], cv.CV_RGB(255, 0, 0), 1, 8)
        i = i+1
        avr = (line[0] + line [1])/2

        cv2.circle(image, avr, 4, cv.CV_RGB(0, 255, 0), 1, 8, 0)

【问题讨论】:

    标签: python syntax opencv


    【解决方案1】:

    你分别平均 x 和 y,然后重新组合成一个元组。

    我忘记了 python 语法,所以伪代码是:

    avg=[ (point1_x+point2_x)/2, (point1_y+point2_y)/2 ]
    

    【讨论】:

      【解决方案2】:

      在 Python 中添加元组似乎将它们连接起来:

      In [1]: (1, 2) + (2, 1)
      Out[1]: (1, 2, 2, 1)
      

      这不是你想要的。试试:

      avr = ((line[0][0] + line[1][0])/2, (line[0][1] + line[1][1])/2)
      

      【讨论】:

        【解决方案3】:

        试试:

        avr = cv.cvPoint((line[0].x + line [1].x)/2, (line[0].y + line [1].y)/2)
        

        【讨论】:

          猜你喜欢
          • 2017-08-23
          • 1970-01-01
          • 1970-01-01
          • 2012-09-03
          • 2015-01-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多