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?
To show number of objects for each class:
Add std::vector<int> count_obj(classes); here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L862
add count_obj[class_id]++; here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L885
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
Most helpful comment
To show number of objects for each class:
Add
std::vector<int> count_obj(classes);here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L862add
count_obj[class_id]++;here: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L885add between these 2 lines: https://github.com/AlexeyAB/darknet/blob/1c71f001531a5df0637903117c6568725d7a66b3/src/image_opencv.cpp#L982-L983