ยังไงฉันอ่าน qr รหัสโดยใช้ CV2 แก่พวกเขา CV2 กำลังบุกรุกของ tuples?

0

คำถาม

ฉันตามหัดเล่นได้ qr อ่าทำงานในปลั๊กอินสำหรับไพธอน,แต่ฉันวิ่งไปตามข้อผิดพลาดขณะกำลังทำมัน:

ยกเว้นมีเกิดขึ้น:เกิดข้อผิดพลาด OpenCV(4.5.4):-1:เกิดข้อผิดพลาด:(-5:แย่เถียงกัน)อยู่ในกฟังก์ชัน'บรรทัด' โอเวอร์โหลดความละเอียดล้มเหลว:

  • ไม่สามารถวิเคราะห์'pt1'. ลำดับรายการกับดัชนี 0 มีชนิดผิด
  • ไม่สามารถวิเคราะห์'pt1'. ลำดับรายการกับดัชนี 0 มีชนิดผิด แฟ้ม"C:\Users\me\project\qrreader.py"สาย 18 ใน cv2.เส้น(img,tuple(bbox[ฉัน][0]),tuple(bbox[(ฉัน+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

สคริปต์นี้อยู่ทั้งหมดของบทแนะนำการใช้งานแบบนอกนั่น,ตามที่เห็นแต่มันดูเหมือนจะพังกับ opencv 4.5.2 เปลี่ยนแปลงเท่าที่ฉันสามารถบอกแต่ฉันไม่สามารถดูเหมือนจะแก้ไขมัน

ถ้าไม่ใช่ tuple อะไรอสายฟังก์ชันต้องการ?

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

คำตอบที่ดีที่สุด

1

ของคุณ bbox เป็น 3 มิติอาเรย์กับรูปร่าง (1,4,2). ผมขอแนะนำให้คุณ simplify มันโดย reshaping มันจะเป็น 2D อาเรย์. เพื่อแสดงมัน int,numpy arrays มี 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 เอกสาร: reshape, astype.

2021-11-23 13:25:33

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

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

ดังอยู่ในนี้หมวดหมู่

ดังคำถามอยู่ในนี้หมวดหมู่