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

class value and export coordinates to csv #30

Closed
nachonacho2 opened this issue Nov 25, 2020 · 7 comments
Closed

class value and export coordinates to csv #30

nachonacho2 opened this issue Nov 25, 2020 · 7 comments

Comments

@nachonacho2
Copy link

Hi, I have a question related to issue # 19:
I'm working through the detectron2 demo (detectron2_cars.py) to understand the code and wanted to change the detected class from cars to person. I found that changing row 32 to "if c == 0" does this. How do I export/print a list of the detected classes?

Also, I would like to export to a csv file the centroid/center coordinates for each tracked object for each frame (similar to print_objects_as_table, but ideally with the data from each frame in one row). Any suggestions?

@joaqo
Copy link
Collaborator

joaqo commented Nov 30, 2020

Hi.

For the first question, you would need to get a list of the mapping between class number and class name from the official COCO website, and then print them to the user.

For the second question, you would need to continously store the results you get from norfair as you iterate over a video in some data structure in memory, and then convert it into a CSV when you finish processing the video. Or you could just append to an CSV file on disk on each frame processed. It should be quite easy.

@nachonacho2
Copy link
Author

Thanks for your reply joaqo.

Following up on the second question, could you please help me understand the norfair results? I may well be approaching this in the wrong way (I am completely new to python).
I think the coordinates I want to export are saved as a numpy array within detection.points and possibly also last_detection of tracked_objects. For each frame, printing detections or tracked_objects gives me a list containing items like this: <norfair.tracker.Detection object at 0x7f792baa0940>
I assume this hexadecimal contains the coordinates and object ID? How to convert to 'human readable' format? (Or is there a better way to obtain the data?)
Otherwise, as you recommended, I think I'm okay with saving the results from each frame and converting into a CSV afterwards.

@joaqo
Copy link
Collaborator

joaqo commented Dec 3, 2020

Hi nacho!

On each frame processed, Norfair takes as inputs a list of Detection objects and returns as output a list of TrackedObjects. Your detector is in charge of producing the list of Detections to feed into norfair, and then it is your job to take the list of TrackedObject that Norfair produces and do something useful with them.

With regards to how to use these TrackedObjects, here you can see their attributes. The one you probably will be more interested in is estimate, as it is a numpy array containing the position Norfair estimates each point in that object to be in.

Regarding that hexadecimal number, its just the memory address of that object, just an internal python implementation detail and not really related to Norfair.

Please feel free to ask more questions.

@nachonacho2
Copy link
Author

Thanks again Joaqo! You helped push me in the right direction to have a working implementation using TrackedObject's estimate :)

It would be nice to have the actual Detection's coordinates whilst maintaining Norfair's ID for each object, but I can manage with the slight loss of accuracy.

I have another question unrelated to the above, so I'll open as a new issue...

@joaqo
Copy link
Collaborator

joaqo commented Dec 4, 2020

Hey @nachonacho2, you actually can access the Detection's coordinates, its listed in the link to TrackedObject's arguments I linked above, under last_detection.

@nachonacho2
Copy link
Author

Hey Joaqo, took me awhile but I got there...
Might be helpful for others in future:
Accessing last_detection just gave me the memory address as noted above. The x, y coordinates can be obtained from: obj.last_detection.points[0], obj.last_detection.points[1]
Their storage shape is slightly different to that of 'estimate', from which the x, y can be obtained from: obj.estimate[:, 0], obj.estimate[:, 1]

Thanks!

@joaqo
Copy link
Collaborator

joaqo commented Dec 4, 2020

Oh I now understand what you meant.

The property last_detection returns a Detection object, which contains several things inside it, among others is the points attribute, which stores the coordinates you needed. You can look at this part of the documentation to see what other attributes it contains.

Regarding the memory address you mention, last_detection wasn't returning its memory address to you, it was returning a Detection object, which python prints to console as a string, which among other things contains its memory address. Look into python's __repr__ method if you want to look deeper into this.

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