系统错误:<内置函数putText>在没有设置错误的情况下返回NULL。

问题描述 投票:1回答:1

当我试图用下面的代码检测产品对象和这些名称时。这里我使用了cv2.putText()函数,但得到了下面的错误。谁能帮帮我。

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`

错误。

回溯(最近一次调用)。 文件 "C:UsersGajapatiPycharmProjectsyoloyolo-opencv.py",第59行,在cv2.putText(img, label, (x, y + 30), font, 1, (0, 0, 0), 3, cv2.LINE_AA, True) SystemError: 在没有设置错误的情况下返回NULL。

python cv2
1个回答
0
投票

你没有关闭dude.replace的括号。

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)
© www.soinside.com 2019 - 2024. All rights reserved.