Notifications
Clear all

'list' object has no attribute 'point_within_zone'

6 Posts
2 Users
1 Likes
517 Views
(@markv)
Active Member Member
Joined: 10 months ago
Posts: 7
Topic starter  

Hello everyone

 

I was trying to create a human recognition script only in specific zones of the image as described here https://peekingduck.readthedocs.io/en/stable/use_cases/zone_counting.html

 

Unfortunately I get the error 'list' object has no attribute 'point_within_zone' when my zone count node gets initialized on line 22 of the attached python script. Any ideas why?

 

Thanks a lot in advance

import cv2

from peekingduck.pipeline.nodes.draw import bbox, btm_midpoint, zones, legend
from peekingduck.pipeline.nodes.model import yolo
from peekingduck.pipeline.nodes.dabble import bbox_to_btm_midpoint, zone_count
from peekingduck.pipeline.nodes.output import screen

try:


    def humanDetection(frame):
        yolo_input = {"img": frame}
        yolo_output = yolo_node.run(yolo_input)

        if len(yolo_output["bboxes"]) > 0:

            midpoint_bbox_input = {
                "img": frame,
                "bboxes": yolo_output["bboxes"],
            }
            midpoint_bbox_output = midpoint_bbox_node.run(midpoint_bbox_input)
            zone_count_output = zone_count_node.run({"btm_midpoint": midpoint_bbox_output["btm_midpoint"]})

            bbox_input = {
                "img": frame,
                "bboxes": yolo_output["bboxes"],
                "bbox_labels": yolo_output["bbox_labels"],
            }
            bbox_node.run(bbox_input)

            midpoint_draw_node.run({"img": frame, "btm_midpoint": midpoint_bbox_output["btm_midpoint"]})
            zones_draw_node.run({"img": frame, "zones": zone_count_output["zones"]})
            legent_output = legend_draw_node.run({"all": zone_count_output["zone_count"]})
            screen_node.run({"img": legent_output["img"]})

    yolo_node = yolo.Node(score_threshold=0.25)
    bbox_node = bbox.Node(show_labels=True)
    midpoint_bbox_node = bbox_to_btm_midpoint.Node()
    zone_count_node = zone_count.Node()
    midpoint_draw_node = btm_midpoint.Node()
    zones_draw_node = zones.Node(resolution=[1280, 720], zones=[
        [[0, 0], [640, 0], [640, 720], [0, 720]],
        [[0.5, 0], [1, 0], [1, 1], [0.5, 1]]
    ])
    legend_draw_node = legend.Node(show=["Zone-1", "Zone-2"])
    screen_node = screen.Node()

    camera = cv2.VideoCapture(0)

    if __name__ == '__main__':
        while True:
            result, frame = camera.read()
            humanDetection(frame)


except Exception as e:
    print("Exception occurred")
    print(e)

 


   
Quote
Gao Hongnan
(@gao-hongnan)
Eminent Member Moderator
Joined: 1 year ago
Posts: 28
 

Hi there, thanks for the question!

Try to upgrade the PeekingDuck version first by doing the following:

pip install -U peekingduck

 

and update us on whether it resolves the attribute error you are facing.


   
ReplyQuote
(@markv)
Active Member Member
Joined: 10 months ago
Posts: 7
Topic starter  

Yes you were right, I had an older version, what a dumb ass. Thank you very much!


   
ReplyQuote
(@markv)
Active Member Member
Joined: 10 months ago
Posts: 7
Topic starter  

Also here is a working version of that code in case anyone needs it

 

import cv2

from peekingduck.pipeline.nodes.draw import bbox, btm_midpoint, zones, legend
from peekingduck.pipeline.nodes.model import yolo
from peekingduck.pipeline.nodes.dabble import bbox_to_btm_midpoint, zone_count
from peekingduck.pipeline.nodes.output import screen

DEFAULT_FILENAME = "temp.mp4"

try:

def humanDetection(frame):
yolo_input = {"img": frame}
yolo_output = yolo_node.run(yolo_input)

if len(yolo_output["bboxes"]) > 0:

midpoint_bbox_input = {
"img": frame,
"bboxes": yolo_output["bboxes"],
}
midpoint_bbox_output = midpoint_bbox_node.run(midpoint_bbox_input)
zone_count_output = zone_count_node.run(
{"btm_midpoint": midpoint_bbox_output["btm_midpoint"]}
)

bbox_input = {
"img": frame,
"bboxes": yolo_output["bboxes"],
"bbox_labels": yolo_output["bbox_labels"],
}
bbox_node.run(bbox_input)

midpoint_draw_node.run(
{"img": frame, "btm_midpoint": midpoint_bbox_output["btm_midpoint"]}
)

zones = zone_count_output["zones"]
zone_count = zone_count_output["zone_count"]

zones_draw_node.run({"img": frame, "zones": zones})

legend_output = legend_draw_node.run(
{"img": frame, "filename": DEFAULT_FILENAME, "zone_count": zone_count}
)

screen_node.run({"img": legend_output["img"], "filename": DEFAULT_FILENAME})

yolo_node = yolo.Node(score_threshold=0.25)
bbox_node = bbox.Node(show_labels=True)
midpoint_bbox_node = bbox_to_btm_midpoint.Node()
midpoint_draw_node = btm_midpoint.Node()
zone_count_node = zone_count.Node()
zones_draw_node = zones.Node(
resolution=[1280, 720],
zones=[
[[0, 0], [640, 0], [640, 720], [0, 720]],
[[0.5, 0], [1, 0], [1, 1], [0.5, 1]],
],
)
legend_draw_node = legend.Node(show=["zone_count"])
screen_node = screen.Node()

camera = cv2.VideoCapture(0)

if __name__ == "__main__":
while True:
result, frame = camera.read()
humanDetection(frame)


except Exception as e:
print("Exception occurred")
print(e)

   
Gao Hongnan reacted
ReplyQuote
Gao Hongnan
(@gao-hongnan)
Eminent Member Moderator
Joined: 1 year ago
Posts: 28
 

Thanks for the reply! Much appreciated for the active engagement and interest shown 😊 


   
ReplyQuote
(@markv)
Active Member Member
Joined: 10 months ago
Posts: 7
Topic starter  

Just a correction regarding my above code. The resolution and zones should have been declared on the zone_count_node not on the zones_draw_node. Like this

 

    zone_count_node = zone_count.Node(
        resolution=[1280, 720],
        zones=[
            [[0, 0], [0.2, 0], [0.2, 1], [0, 1]],
            [[0.8, 0], [1, 0], [1, 1], [0.8, 1]],
        ],
    )
    zones_draw_node = zones.Node()

   
ReplyQuote
Share: