할 수 있는 방법을 읽는 qr 코드를 사용하여 CV2 주어진 자신의 CV2 의 파괴의 튜플?

0

질문

나는 다음과 같은 튜토리얼을 얻을 수 qr 리더에서 작동하는 파이썬지만,나는 실행으로 다음과 같은 오류가 실행하는 동안 그것은:

은 예외를 정하는 체약국은,예외가 발생했습니다:류 OpenCV(4.5.4):-1:류:(-5:나쁜 인수)함수에서'선' 과부하를 확인에 실패했습니다.:

  • 구문 분석할 수 없습'pt1'. 순서 항목을 가진 인덱스 0 는 잘못 유형
  • 구문 분석할 수 없습'pt1'. 순서 항목을 가진 인덱스 0 는 잘못 유형 파일은"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

이 스크립트에서는 튜토리얼을 모두 밖으로있다,겉으로는,하지만 그것이 나타납 깨 opencv4.5.2 변경 내용까지 말할 수 있지만,나는 수가 없습니다.

하지 않을 경우 튜플는 무엇인 기능이 필요?

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

최고의 응답

1

귀하의 bbox 3 차원 배열을 가진 모양 (1,4,2). 나는 좋은 당신이 그것을 단순화하여 고쳐 만들고 그것을 2D 배열입니다. 를 캐스팅 int,numpy 어레이 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)

Numpy 문서화: 바꿀, astype.

2021-11-23 13:25:33

다른 언어로

이 페이지는 다른 언어로되어 있습니다

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