简体   繁体   English

我有这段代码,试图通过捕获视频来运行社会隔离识别,但我有这个错误。 你可以帮帮我吗?

[英]I have this code, trying to run a social isolation identification by capturing video, but I have this error. Could you help me?

I have this code, trying to run a social isolation identification by capturing video, but I get the following error:我有这段代码,试图通过捕获视频来运行社会隔离识别,但我收到以下错误:

Traceback (most recent call last): File "social_distance_detection.py", line 127, in cv2.rectangle(frame, (startX, startY), (endX, endY), COLOR, 2) TypeError: only integer scalar arrays can be converted to a scalar index回溯(最近一次调用最后一次):文件“social_distance_detection.py”,第 127 行,在 cv2.rectangle(frame, (startX, startY), (endX, endY), COLOR, 2)到标量索引

Could you help me?你可以帮帮我吗?

Here is the code I am running:这是我正在运行的代码:

for i in range(detections.shape[2]):

        confidence = detections[0, 0, i, 2]

        if confidence > args["confidence"]:

            class_id = int(detections[0, 0, i, 1])

            box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
            (startX, startY, endX, endY) = box.astype('int')

            # Filtering only persons detected in the frame. Class Id of 'person' is 15
            if class_id == 15.00:

                # Draw bounding box for the object
                cv2.rectangle(frame, (startX, startY), (endX, endY), bounding_box_color[class_id], 2)

                label = "{}: {:.2f}%".format(labels[class_id], confidence * 100)
                print("{}".format(label))


                coordinates[i] = (startX, startY, endX, endY)



    for i in pos_dict.keys():
        if i in close_objects:
            COLOR = np.array([0,0,255])
        else:
            COLOR = np.array([0,255,0])
        (startX, startY, endX, endY) = coordinates[i]

        cv2.rectangle(frame, (startX, startY), (endX, endY), COLOR, 2)
        y = startY - 15 if startY - 15 > 15 else startY + 15
        # Convert cms to feet
        cv2.putText(frame, 'Depth: {i} ft'.format(i=round(pos_dict[i][2]/30.48,4)), (startX, y),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLOR, 2)

    cv2.namedWindow('Frame',cv2.WINDOW_NORMAL)

Error>错误> https://i.stack.imgur.com/BZSZJ.jpg

You need to cast coordinates to int in rectangle method.您需要在矩形方法中将坐标转换为 int。 Use (int(startX,int(startY)) same for end point.使用 (int(startX,int(startY)) 相同的端点。

Use利用

for i in pos_dict.keys():
        if i in close_objects:
            COLOR = (0,0,255)
        else:
            COLOR = (0,255,0)

instead of代替

for i in pos_dict.keys():
        if i in close_objects:
            COLOR = np.array([0,0,255])
        else:
            COLOR = np.array([0,255,0])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的代码有问题。 我需要解决这个错误。 帮我 - I have a problem with a code. I need to solve this error. Help me 嗨,我尝试用 python 编写这段代码,但是我有一个错误,我希望有人可以帮助我 - Hi, I have tried to write this code in python, but i have a error, i hope that someone could help me 我的表格有问题,但它没有向我发送电子邮件你能帮我吗这是我的第一篇出版物, - I have a problem the form works but it does not send me the emails could you help me It is my first publication, 我有以下代码抛出和错误。 - I have the following code throwing and error. 我有一段代码来运行回归,但我不知道为什么会出现语法错误。 下面的代码 - I have a piece of code to run regression but I have no idea why I get a syntax error. the code below 我正在尝试在 repli 中创建一个基本的 discord 机器人,并且我已经为它编写了一个代码,但是当我运行它时它一直向我显示错误 - I am trying to create a basic discord bot in replit and I have written a code for it but it keeps showing me an error when I run it 我正在尝试为我的项目抓取一个网站,但我遇到了一个错误。 看看,让我知道是否有人对此有建议 - I am trying to scrape a website for my project but I am stuck with an error. Take a look and let me know if anyone have suggestion for this 当我在 Visual Studio Code 中编写编译代码时,我无法得到结果,我运行 python deploy.py,它给了我错误。 我必须在我的代码中编辑的内容 - I couldn't get results when I write compiled code in Visual Studio Code, I run python deploy.py and it gives me error. what I have to edit in my code 嗨,我有一个 python 脚本可以使用 openpyxl 处理 excel 数据,但是在 2500 行之后我收到 Memory 错误。 谁可以帮我这个事? - Hi, I have a python script to work with excel data using openpyxl ,but after 2500 rows i am getting Memory Error. Can anyone help me on this? 我对 pygame 有问题,我试图从 VScode 运行部分 output 但它没有显示它。请帮帮我? - i have a problem with pygame where im trying to run a partial output from VScode but its not displaying it.Please help me?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM