Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count identified object #5

Open
zdavatz opened this issue Apr 15, 2021 · 4 comments
Open

Count identified object #5

zdavatz opened this issue Apr 15, 2021 · 4 comments

Comments

@zdavatz
Copy link

zdavatz commented Apr 15, 2021

  1. Thank you for all your great work on the coral.ai Board and the github samples!
  2. Can you recommend an solution how to count identified objects?
  3. For exmaple the following output:
    0: Object(id=2, score=0.58203125, bbox=BBox(xmin=241, ymin=165, xmax=283, ymax=185)), area=840.00
    1: Object(id=0, score=0.41796875, bbox=BBox(xmin=20, ymin=154, xmax=66, ymax=205)), area=2346.00
    2: Object(id=2, score=0.26953125, bbox=BBox(xmin=244, ymin=165, xmax=280, ymax=179)), area=504.00
    3: Object(id=2, score=0.26953125, bbox=BBox(xmin=235, ymin=167, xmax=258, ymax=183)), area=368.00
    4: Object(id=0, score=0.2109375, bbox=BBox(xmin=11, ymin=151, xmax=151, ymax=258)), area=14980.00
    5: Object(id=2, score=0.2109375, bbox=BBox(xmin=265, ymin=163, xmax=283, ymax=178)), area=270.00
    6: Object(id=0, score=0.16015625, bbox=BBox(xmin=26, ymin=166, xmax=60, ymax=201)), area=1190.00
    7: Object(id=0, score=0.16015625, bbox=BBox(xmin=35, ymin=163, xmax=68, ymax=200)), area=1221.00
  1. Do you have a recommend way, for example how to count the passing cars?
  2. Object ID 1 is a person, 2 is a car.
@Namburger
Copy link
Owner

@zdavatz no problems!
You can do this quite easily using a std::map<std::string, int> where the key is the id of the object and the count is how many time you've seen that object. So the pseudo code looks something like this:

std::map<std::string, int> count;
for (const auto& candidate : candidates) {
  if (count.find(candidate.candidate) == count.end()) { 
    // not in map
    count.emplace({candidate.candidate, 0});
  } else {
    count[candidate.candidate]++;
  }
}

@zdavatz
Copy link
Author

zdavatz commented Apr 15, 2021

Where can I insert this code? I am currently using this command to start the tracking:
edgetpu_detect_server --model mobilenet_ssd_v2_coco_quant_postprocess_edgetpu.tflite --labels coco_labels.txt --filter person,car --color green --print --source /dev/video0:YUY2:640x480:30/1 from the following repository:
https://github.com/google-coral/example-object-tracker

@Namburger
Copy link
Owner

Namburger commented Apr 15, 2021

@zdavatz oh I see edgetpu_detect_server is a different project than this one. I was confused since you've posted in this project, that project is in python and is installed as the python3-edgetpuvision library on your dev board. You can see all files installed on it using this command:

mendel@bored-llama:~$ dpkg -L python3-edgetpuvision

Then in the file /usr/lib/python3/dist-packages/edgetpuvision/detect.py, there is a print_results function, in it, the same pseudo code applies, but in python instead of c++. You'll probably want a map of type int, int with the key being obj.id and the value is the number of occurances of that id.

@zdavatz
Copy link
Author

zdavatz commented Apr 15, 2021

ok, thank you! I will try and report back. Also with the --print option, how can I tell it is the same car passing by that is being detected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants