簡體   English   中英

系統錯誤:<built-in function puttext> 返回 NULL 沒有設置錯誤</built-in>

[英]SystemError: <built-in function putText> returned NULL without setting an error

當我嘗試使用以下代碼檢測產品對象和那些名稱時。 在這里,我使用的是 cv2.putText() function,但出現以下錯誤。 誰能幫幫我。

from cProfile import label
from tkinter import font

import cv2
import numpy as np

net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
classes = []
with open("coco.names", "r") as f:
    classes = [line.strip() for line in f.readlines()]
#print(classes)
layer_names = net.getLayerNames()
output_layers = [layer_names[i[0] -1] for i in net.getUnconnectedOutLayers()]


img = cv2.imread("amz.jpg")
img = cv2.resize(img, None, fx=0.9, fy=0.9)
height, width, channels = img.shape

blob = cv2.dnn.blobFromImage(img, 0.00392, (416, 416), (0, 0, 0,), True, crop=False)

for b in blob:
    for n, img_blob in enumerate(b):
        cv2.imshow(str(n), img_blob)

net.setInput(blob)
outp = net.forward(output_layers)
print(outp)

class_ids = []
confidences = []
boxes = []

for out in outp:
    for detection in out:
        scores = detection[5:]
        class_id = np.argmax(scores)
        confidence = scores[class_id]
        if confidence > 0.5:

            center_x = int(detection[0] * width)
            center_y = int(detection[1] * height)
            w = int(detection[2] * width)
            h = int(detection[3] * height)
            x = int(center_x - w / 2)
            y = int(center_y - h / 2)
            boxes.append([x, y, w, h])
            confidences.append(float(confidence))
            class_ids.append(class_id)
#print(len(boxes))
number_object_detected = len(boxes)
#font = cv2.FONT_HERSHEY_PLAIN
font = cv2.FONT_HERSHEY_SIMPLEX
for i in range(len(boxes)):
    x, y, w, h = boxes[i]
    lable = classes[class_ids[i]]
    print(lable)
    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
    cv2.putText(img, label, (x, y + 30), font, 1, (0, 0, 0), 3, cv2.LINE_AA, True
 cv2.imshow("Image", img)
 #img = cv2.resize(img, None, fx=0.9, fy=0.9)
 cv2.waitKey(10000)`enter code here`

錯誤:

Traceback(最近一次調用最后):文件“C:/Users/Gajapati/PycharmProjects/yolo/yolo-opencv.py”,第59行,在cv2.putText(img,label,(x,y + 30),字體, 1, (0, 0, 0), 3, cv2.LINE_AA, True) SystemError: returned NULL 沒有設置錯誤

文本應該是字符串:

cv2.putText(img, str(label), (x, y + 30), font, 1, (0, 0, 0), 3, cv2.LINE_AA, True)

你還沒有關閉括號老兄。 代替

cv2.putText(img, label, (x, y + 30), font, 1, (0, 0, 0), 3, cv2.LINE_AA, True

cv2.putText(img, label, (x, y + 30), font, 1, (0, 0, 0), 3, cv2.LINE_AA, True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM