我怎么能读维码使用CV2给予他们的CV2的突破组?

0

的问题

我是下一个教程得到一个qr读者的工作在蟒蛇,但我跑到下面的错误,同时运行:

异常已经发生的错误 该版本(4.5.4):-1:错误:(-5:坏参数),在功能'线' 过载决议失败:

  • 不可能分析'pt1'. 序列项目与index0有一个错误的类型
  • 不可能分析'pt1'. 序列项目与index0有一个错误的类型 文件"C:\Users\me\project\qrreader.py"18行, cv2.线(img元组(bbox[i][0]),元组(bbox[(i+1)%len(bbox)][0]),颜色=(255,

剧本如下

import cv2

# set up camera object
cap = cv2.VideoCapture(0)

# QR code detection object
detector = cv2.QRCodeDetector()

while True:
    # get the image
    _, img = cap.read()
    # get bounding box coords and data
    data, bbox, _ = detector.detectAndDecode(img)
    
    # if there is a bounding box, draw one, along with the data
    if(bbox is not None):
        for i in range(len(bbox)):
            cv2.line(img, tuple(bbox[i][0]), tuple(bbox[(i+1) % len(bbox)][0]), color=(255,
                     0, 255), thickness=2)
        cv2.putText(img, data, (int(bbox[0][0][0]), int(bbox[0][0][1]) - 10), cv2.FONT_HERSHEY_SIMPLEX,
                    0.5, (0, 255, 0), 2)
        if data:
            print("data found: ", data)
    # display the image preview
    cv2.imshow("code detector", img)
    if(cv2.waitKey(1) == ord("q")):
        break
# free camera object and exit

这个脚本是在所有的教程,在那里,表面上看起来,但它似乎已经打破了该版本的4.5.2变化作为我可以告诉,但我似乎无法解决它。

如果不元组,什么线的功能要求?

computer-vision cv2 opencv python
2021-11-22 20:07:52
1

最好的答案

1

你的 bbox 3维阵形 (1,4,2). 我建议你简化它通过重塑它2D阵列。 投给 int,顽固阵列有 astype 法。 最后一个 tuple 仍然需要通过 cv2.line,因此,保持这样。

这是一个可能的解决方案块:

    # if there is a bounding box, draw one, along with the data
    if bbox is not None:
        bb_pts = bbox.astype(int).reshape(-1, 2)
        num_bb_pts = len(bb_pts)
        for i in range(num_bb_pts):
            cv2.line(img,
                     tuple(bb_pts[i]),
                     tuple(bb_pts[(i+1) % num_bb_pts]),
                     color=(255, 0, 255), thickness=2)
        cv2.putText(img, data,
                    (bb_pts[0][0], bb_pts[0][1] - 10),
                    cv2.FONT_HERSHEY_SIMPLEX,
                    0.5, (0, 255, 0), 2)

顽固文件: 重塑, astype.

2021-11-23 13:25:33

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................