Darknet: Count Objects in Video Stream

Created on 13 Sep 2019  路  2Comments  路  Source: AlexeyAB/darknet

if(selected_detections_num > 0) printf(" total objects = %d \n", selected_detections_num);

instead of
printf(" total objects = %d \n", selected_detections_num);

_Originally posted by @AlexeyAB in https://github.com/AlexeyAB/darknet/issues/2109#issuecomment-450002405_

Hello @AlexeyAB,

I want to count objects detected in a frame of video, what do I change in demo.c? I am able to get object count in images by how to get in videostreams?

Most helpful comment

To show number of objects for each class:

  1. Add std::vector<int> count_obj(classes); here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L862

  2. add count_obj[class_id]++; here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L885

  3. add between these 2 lines: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L982-L983

for(size_t i = 0; i < count_obj.size(); i++)
    std::cout << " class_id = " << i << ", objects = " << count_obj[i] << std::endl;

All 2 comments

To show number of objects for each class:

  1. Add std::vector<int> count_obj(classes); here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L862

  2. add count_obj[class_id]++; here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L885

  3. add between these 2 lines: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L982-L983

for(size_t i = 0; i < count_obj.size(); i++)
    std::cout << " class_id = " << i << ", objects = " << count_obj[i] << std::endl;

Great, this works!

@AlexeyAB, can you tell how to get object count in darknet.py and darknet_video.py

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zihaozhang9 picture zihaozhang9  路  3Comments

Greta-A picture Greta-A  路  3Comments

Mididou picture Mididou  路  3Comments

Jacky3213 picture Jacky3213  路  3Comments

siddharth2395 picture siddharth2395  路  3Comments