viame2coco 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- viame2coco-0.1.0/.gitignore +6 -0
- viame2coco-0.1.0/CODE_OF_CONDUCT.md +1 -0
- viame2coco-0.1.0/CONTRIBUTING.md +1 -0
- viame2coco-0.1.0/LICENSE +1 -0
- viame2coco-0.1.0/PKG-INFO +34 -0
- viame2coco-0.1.0/README.md +1 -0
- viame2coco-0.1.0/docs/.gitkeep +0 -0
- viame2coco-0.1.0/docs/CODE_OF_CONDUCT.md +46 -0
- viame2coco-0.1.0/docs/CONTRIBUTING.md +73 -0
- viame2coco-0.1.0/docs/LICENSE +132 -0
- viame2coco-0.1.0/docs/README.md +23 -0
- viame2coco-0.1.0/docs/api/index.md +0 -0
- viame2coco-0.1.0/docs/api/viame2coco.md +3 -0
- viame2coco-0.1.0/docs/api/viame_manual_annotations.md +3 -0
- viame2coco-0.1.0/docs/publish.sh +1 -0
- viame2coco-0.1.0/mkdocs.yml +30 -0
- viame2coco-0.1.0/notebooks/.gitkeep +0 -0
- viame2coco-0.1.0/notebooks/viame_output_playground.ipynb +154 -0
- viame2coco-0.1.0/pyproject.toml +19 -0
- viame2coco-0.1.0/requirements/common.txt +2 -0
- viame2coco-0.1.0/requirements/dev.txt +4 -0
- viame2coco-0.1.0/requirements/prod.txt +1 -0
- viame2coco-0.1.0/requirements.txt +1 -0
- viame2coco-0.1.0/tests/__init__.py +0 -0
- viame2coco-0.1.0/tests/test_docs.py +16 -0
- viame2coco-0.1.0/tests/utils.py +15 -0
- viame2coco-0.1.0/viame2coco/__init__.py +0 -0
- viame2coco-0.1.0/viame2coco/viame2coco.py +159 -0
- viame2coco-0.1.0/viame2coco/viame_manual_annotations.py +188 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
docs/CODE_OF_CONDUCT.md
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
docs/CONTRIBUTING.md
|
viame2coco-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
docs/LICENSE
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: viame2coco
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: tools to convert VIAME output to COCO format
|
|
5
|
+
Author: CScott Brown
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Requires-Dist: pycocowriter
|
|
9
|
+
Requires-Dist: opencv-python
|
|
10
|
+
|
|
11
|
+
# viame2coco
|
|
12
|
+
|
|
13
|
+
This package contains tools for converting VIAME-style annotation csv output into COCO format.
|
|
14
|
+
|
|
15
|
+
# Installation
|
|
16
|
+
|
|
17
|
+
`pip install viame2coco`
|
|
18
|
+
|
|
19
|
+
# Contributing
|
|
20
|
+
|
|
21
|
+
We would love to have your contributions that improve current functionality, fix bugs, or add new features. See [the contributing guidelines](CONTRIBUTING.md) for more info.
|
|
22
|
+
|
|
23
|
+
# Disclaimer
|
|
24
|
+
|
|
25
|
+
This repository is a scientific product and is not official communication of the National Oceanic and
|
|
26
|
+
Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project
|
|
27
|
+
code is provided on an ‘as is’ basis and the user assumes responsibility for its use. Any claims against the
|
|
28
|
+
Department of Commerce or Department of Commerce bureaus stemming from the use of this GitHub
|
|
29
|
+
project will be governed by all applicable Federal law. Any reference to specific commercial products,
|
|
30
|
+
processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or
|
|
31
|
+
imply their endorsement, recommendation or favoring by the Department of Commerce. The Department
|
|
32
|
+
of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to
|
|
33
|
+
imply endorsement of any commercial product or activity by DOC or the United States Government.
|
|
34
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
docs/README.md
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
This code of conduct was developed and adapted from the Atom code of conduct in October 2021.
|
|
4
|
+
|
|
5
|
+
## Our Pledge
|
|
6
|
+
|
|
7
|
+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
|
8
|
+
|
|
9
|
+
## Our Standards
|
|
10
|
+
|
|
11
|
+
Examples of behavior that contributes to creating a positive environment include:
|
|
12
|
+
|
|
13
|
+
* Using welcoming and inclusive language
|
|
14
|
+
* Being respectful of differing viewpoints and experiences
|
|
15
|
+
* Gracefully accepting constructive criticism
|
|
16
|
+
* Focusing on what is best for the community
|
|
17
|
+
* Showing empathy towards other community members
|
|
18
|
+
|
|
19
|
+
Examples of unacceptable behavior by participants include:
|
|
20
|
+
|
|
21
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
|
|
22
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
23
|
+
* Public or private harassment
|
|
24
|
+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
|
|
25
|
+
* Other conduct which could reasonably be considered inappropriate in a professional setting
|
|
26
|
+
|
|
27
|
+
## Our Responsibilities
|
|
28
|
+
|
|
29
|
+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
|
|
30
|
+
|
|
31
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
|
|
32
|
+
|
|
33
|
+
## Scope
|
|
34
|
+
|
|
35
|
+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
|
|
36
|
+
|
|
37
|
+
## Enforcement
|
|
38
|
+
|
|
39
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. Further details of specific enforcement policies may be posted separately.
|
|
40
|
+
|
|
41
|
+
## Attribution
|
|
42
|
+
|
|
43
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [https://contributor-covenant.org/version/1/4][version]
|
|
44
|
+
|
|
45
|
+
[homepage]: https://contributor-covenant.org
|
|
46
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Contributing Guidelines
|
|
2
|
+
|
|
3
|
+
*Pull requests, bug reports, and all other forms of contribution are welcomed and highly encouraged!*
|
|
4
|
+
|
|
5
|
+
### Contents
|
|
6
|
+
|
|
7
|
+
- [Code of Conduct](#code-of-conduct)
|
|
8
|
+
- [Bug Reports](#bug-reports)
|
|
9
|
+
- [Feature Requests](#feature-requests)
|
|
10
|
+
- [Submitting Pull Requests](#submitting-pull-requests)
|
|
11
|
+
- [Code Review](#code-review)
|
|
12
|
+
- [Coding Style](#coding-style)
|
|
13
|
+
- [Documentation](#documentation)
|
|
14
|
+
- [Certificate of Origin](#certificate-of-origin)
|
|
15
|
+
|
|
16
|
+
> **This guide serves to set clear expectations for everyone involved with the project so that we can improve it together while also creating a welcoming space for everyone to participate. Following these guidelines will help ensure a positive experience for contributors and maintainers.**
|
|
17
|
+
|
|
18
|
+
## Code of Conduct
|
|
19
|
+
|
|
20
|
+
Please review our [Code of Conduct](CODE_OF_CONDUCT.md). It is in effect at all times. We expect it to be honored by everyone who contributes to this project. Acting like an asshole will not be tolerated.
|
|
21
|
+
|
|
22
|
+
### Bug Reports
|
|
23
|
+
|
|
24
|
+
Please include a minimal reproducible example with your bug report.
|
|
25
|
+
|
|
26
|
+
## Feature Requests
|
|
27
|
+
|
|
28
|
+
Feature requests are welcome if they fit within the scope of the project.
|
|
29
|
+
|
|
30
|
+
Feature requests that you are willing to complete are especially welcome.
|
|
31
|
+
|
|
32
|
+
## Submitting Pull Requests
|
|
33
|
+
|
|
34
|
+
Please submit an issue first and get community buy-in for proposed changes before doing any work.
|
|
35
|
+
|
|
36
|
+
Please submit PRs in the smallest possible non-breaking chunks.
|
|
37
|
+
|
|
38
|
+
## Code Review
|
|
39
|
+
|
|
40
|
+
Any code pulled into this repo should be reviewed by a maintainer.
|
|
41
|
+
|
|
42
|
+
Remember:
|
|
43
|
+
|
|
44
|
+
- **Review the code, not the author.** Look for and suggest improvements without disparaging or insulting the author. Provide actionable feedback and explain your reasoning.
|
|
45
|
+
|
|
46
|
+
- **You are not your code.** When your code is critiqued, questioned, or constructively criticized, remember that you are not your code. Do not take code review personally.
|
|
47
|
+
|
|
48
|
+
## Coding Style
|
|
49
|
+
|
|
50
|
+
Follow the existing style. We use the VSCode autopep8 linter.
|
|
51
|
+
|
|
52
|
+
## Documentation
|
|
53
|
+
|
|
54
|
+
Please include typing and docstrings for any classes. We use [numpy style docstrings](https://numpydoc.readthedocs.io/en/latest/format.html). Our auto-documentation is configured to parse this style, so please follow this convention.
|
|
55
|
+
|
|
56
|
+
## Testing
|
|
57
|
+
|
|
58
|
+
Please write tests for your code. Tests should be discoverable or runnable on a file-by-file basis. Make sure all tests pass before submitting a pull request.
|
|
59
|
+
|
|
60
|
+
python -m unittest discover tests
|
|
61
|
+
|
|
62
|
+
## Certificate of Origin
|
|
63
|
+
|
|
64
|
+
WHEN YOU SUBMIT CODE TO THIS REPOSITORY, YOU AGREE TO LICENSE YOUR CODE UNDER [THE LICENSE](LICENSE)
|
|
65
|
+
|
|
66
|
+
*Developer's Certificate of Origin 1.1*
|
|
67
|
+
|
|
68
|
+
By making a contribution to this project, I certify that:
|
|
69
|
+
|
|
70
|
+
> 1. The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
|
|
71
|
+
> 1. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
|
|
72
|
+
> 1. The contribution was provided directly to me by some other person who certified (1), (2) or (3) and I have not modified it.
|
|
73
|
+
> 1. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
FOR ALL WORK SUBMITTED BY FEDERAL EMPLOYEES:
|
|
2
|
+
|
|
3
|
+
Software code created by U.S. Government employees is not subject to copyright in the United States
|
|
4
|
+
(17 U.S.C. §105). The United States/Department of Commerce reserve all rights to seek and obtain
|
|
5
|
+
copyright protection in countries other than the United States for Software authored in its entirety by the
|
|
6
|
+
Department of Commerce. To this end, the Department of Commerce hereby grants to Recipient a
|
|
7
|
+
royalty-free, nonexclusive license to use, copy, and create derivative works of the Software outside of the
|
|
8
|
+
United States.
|
|
9
|
+
|
|
10
|
+
FOR ALL WORK SUBMITTED BY NON-FEDERAL EMPLOYEES:
|
|
11
|
+
|
|
12
|
+
Creative Commons Legal Code
|
|
13
|
+
|
|
14
|
+
CC0 1.0 Universal
|
|
15
|
+
|
|
16
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
17
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
18
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
19
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
20
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
21
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
22
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
23
|
+
HEREUNDER.
|
|
24
|
+
|
|
25
|
+
Statement of Purpose
|
|
26
|
+
|
|
27
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
28
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
29
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
30
|
+
authorship and/or a database (each, a "Work").
|
|
31
|
+
|
|
32
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
33
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
34
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
35
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
36
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
37
|
+
and for any purposes, including without limitation commercial purposes.
|
|
38
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
39
|
+
culture and the further production of creative, cultural and scientific
|
|
40
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
41
|
+
part through the use and efforts of others.
|
|
42
|
+
|
|
43
|
+
For these and/or other purposes and motivations, and without any
|
|
44
|
+
expectation of additional consideration or compensation, the person
|
|
45
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
46
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
47
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
48
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
49
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
50
|
+
|
|
51
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
52
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
53
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
54
|
+
limited to, the following:
|
|
55
|
+
|
|
56
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
57
|
+
communicate, and translate a Work;
|
|
58
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
59
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
60
|
+
likeness depicted in a Work;
|
|
61
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
62
|
+
subject to the limitations in paragraph 4(a), below;
|
|
63
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
64
|
+
in a Work;
|
|
65
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
66
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
67
|
+
protection of databases, and under any national implementation
|
|
68
|
+
thereof, including any amended or successor version of such
|
|
69
|
+
directive); and
|
|
70
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
71
|
+
world based on applicable law or treaty, and any national
|
|
72
|
+
implementations thereof.
|
|
73
|
+
|
|
74
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
75
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
76
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
77
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
78
|
+
of action, whether now known or unknown (including existing as well as
|
|
79
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
80
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
81
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
82
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
83
|
+
including without limitation commercial, advertising or promotional
|
|
84
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
85
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
86
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
87
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
88
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
89
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
90
|
+
|
|
91
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
92
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
93
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
94
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
95
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
96
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
97
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
98
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
99
|
+
maximum duration provided by applicable law or treaty (including future
|
|
100
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
101
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
102
|
+
limitation commercial, advertising or promotional purposes (the
|
|
103
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
104
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
105
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
106
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
107
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
108
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
109
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
110
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
111
|
+
express Statement of Purpose.
|
|
112
|
+
|
|
113
|
+
4. Limitations and Disclaimers.
|
|
114
|
+
|
|
115
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
116
|
+
surrendered, licensed or otherwise affected by this document.
|
|
117
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
118
|
+
warranties of any kind concerning the Work, express, implied,
|
|
119
|
+
statutory or otherwise, including without limitation warranties of
|
|
120
|
+
title, merchantability, fitness for a particular purpose, non
|
|
121
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
122
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
123
|
+
the greatest extent permissible under applicable law.
|
|
124
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
125
|
+
that may apply to the Work or any use thereof, including without
|
|
126
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
127
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
128
|
+
consents, permissions or other rights required for any use of the
|
|
129
|
+
Work.
|
|
130
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
131
|
+
party to this document and has no duty or obligation with respect to
|
|
132
|
+
this CC0 or use of the Work.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# viame2coco
|
|
2
|
+
|
|
3
|
+
This package contains tools for converting VIAME-style annotation csv output into COCO format.
|
|
4
|
+
|
|
5
|
+
# Installation
|
|
6
|
+
|
|
7
|
+
`pip install viame2coco`
|
|
8
|
+
|
|
9
|
+
# Contributing
|
|
10
|
+
|
|
11
|
+
We would love to have your contributions that improve current functionality, fix bugs, or add new features. See [the contributing guidelines](CONTRIBUTING.md) for more info.
|
|
12
|
+
|
|
13
|
+
# Disclaimer
|
|
14
|
+
|
|
15
|
+
This repository is a scientific product and is not official communication of the National Oceanic and
|
|
16
|
+
Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project
|
|
17
|
+
code is provided on an ‘as is’ basis and the user assumes responsibility for its use. Any claims against the
|
|
18
|
+
Department of Commerce or Department of Commerce bureaus stemming from the use of this GitHub
|
|
19
|
+
project will be governed by all applicable Federal law. Any reference to specific commercial products,
|
|
20
|
+
processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or
|
|
21
|
+
imply their endorsement, recommendation or favoring by the Department of Commerce. The Department
|
|
22
|
+
of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to
|
|
23
|
+
imply endorsement of any commercial product or activity by DOC or the United States Government.
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mkdocs gh-deploy --config-file mkdocs.yml --remote-branch gh-pages
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
site_name: viame2coco
|
|
2
|
+
|
|
3
|
+
repo_url: https://github.com/nodd-tools/viame2coco
|
|
4
|
+
|
|
5
|
+
theme:
|
|
6
|
+
name: material
|
|
7
|
+
features:
|
|
8
|
+
- navigation.tabs
|
|
9
|
+
- content.code.annotate
|
|
10
|
+
markdown_extensions:
|
|
11
|
+
- markdown.extensions.admonition
|
|
12
|
+
- markdown.extensions.codehilite
|
|
13
|
+
- pymdownx.superfences
|
|
14
|
+
|
|
15
|
+
plugins:
|
|
16
|
+
- search
|
|
17
|
+
- mkdocstrings:
|
|
18
|
+
default_handler: python
|
|
19
|
+
handlers:
|
|
20
|
+
python:
|
|
21
|
+
options:
|
|
22
|
+
docstring_style: numpy
|
|
23
|
+
|
|
24
|
+
nav:
|
|
25
|
+
- Home: README.md
|
|
26
|
+
- Contributing: CONTRIBUTING.md
|
|
27
|
+
- Code of Conduct: CODE_OF_CONDUCT.md
|
|
28
|
+
- Code Reference:
|
|
29
|
+
- Viame2COCO: api/viame2coco.md
|
|
30
|
+
- Viame Manual Annotation Tools: api/viame_manual_annotations.md
|
|
File without changes
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cells": [
|
|
3
|
+
{
|
|
4
|
+
"cell_type": "code",
|
|
5
|
+
"execution_count": 1,
|
|
6
|
+
"id": "87dcd751-1366-4467-89a2-4cda1a483d97",
|
|
7
|
+
"metadata": {},
|
|
8
|
+
"outputs": [],
|
|
9
|
+
"source": [
|
|
10
|
+
"import cv2\n",
|
|
11
|
+
"import csv\n",
|
|
12
|
+
"import datetime\n",
|
|
13
|
+
"import os\n",
|
|
14
|
+
"import sys\n",
|
|
15
|
+
"sys.path.append(\"..\")\n",
|
|
16
|
+
"from viame2coco.viame2coco import *"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"cell_type": "code",
|
|
21
|
+
"execution_count": 2,
|
|
22
|
+
"id": "a97a6033-2975-4da8-a752-b3eb779ddc48",
|
|
23
|
+
"metadata": {},
|
|
24
|
+
"outputs": [],
|
|
25
|
+
"source": [
|
|
26
|
+
"DATA = os.path.join('..','data')\n",
|
|
27
|
+
"EXAMPLE_CSV = os.path.join(DATA, 'viame_video_output_2025_01_13.csv')\n",
|
|
28
|
+
"EXAMPLE_VIDEO = os.path.join(DATA, 'viame_video_sample_2025_01_13.mp4')"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"cell_type": "code",
|
|
33
|
+
"execution_count": 3,
|
|
34
|
+
"id": "19a733f1-fcd1-4682-8a88-27a0d67fd140",
|
|
35
|
+
"metadata": {},
|
|
36
|
+
"outputs": [
|
|
37
|
+
{
|
|
38
|
+
"name": "stdout",
|
|
39
|
+
"output_type": "stream",
|
|
40
|
+
"text": [
|
|
41
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.00.800000.jpg\n",
|
|
42
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.01.000000.jpg\n",
|
|
43
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.01.200000.jpg\n",
|
|
44
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.01.400000.jpg\n",
|
|
45
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.01.600000.jpg\n",
|
|
46
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.01.800000.jpg\n",
|
|
47
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.02.000000.jpg\n",
|
|
48
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.02.200000.jpg\n",
|
|
49
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.02.400000.jpg\n",
|
|
50
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.02.600000.jpg\n",
|
|
51
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.02.800000.jpg\n",
|
|
52
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.03.000000.jpg\n",
|
|
53
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.03.200000.jpg\n",
|
|
54
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.03.400000.jpg\n",
|
|
55
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.03.600000.jpg\n",
|
|
56
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.03.800000.jpg\n",
|
|
57
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.04.000000.jpg\n",
|
|
58
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.04.200000.jpg\n",
|
|
59
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.04.400000.jpg\n",
|
|
60
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.04.600000.jpg\n",
|
|
61
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.04.800000.jpg\n",
|
|
62
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.05.000000.jpg\n",
|
|
63
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.05.200000.jpg\n",
|
|
64
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.05.400000.jpg\n",
|
|
65
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.05.600000.jpg\n",
|
|
66
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.05.800000.jpg\n",
|
|
67
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.06.000000.jpg\n",
|
|
68
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.06.200000.jpg\n",
|
|
69
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.06.400000.jpg\n",
|
|
70
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.06.600000.jpg\n",
|
|
71
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.06.800000.jpg\n",
|
|
72
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.07.000000.jpg\n",
|
|
73
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.07.200000.jpg\n",
|
|
74
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.07.400000.jpg\n",
|
|
75
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.07.600000.jpg\n",
|
|
76
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.07.800000.jpg\n",
|
|
77
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.08.000000.jpg\n",
|
|
78
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.08.200000.jpg\n",
|
|
79
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.08.400000.jpg\n",
|
|
80
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.08.600000.jpg\n",
|
|
81
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.08.800000.jpg\n",
|
|
82
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.09.000000.jpg\n",
|
|
83
|
+
"../data/viame_video_sample_2025_01_13.mp4.00.00.09.200000.jpg\n"
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
"source": [
|
|
88
|
+
"coco = viame2coco(\n",
|
|
89
|
+
" EXAMPLE_CSV,\n",
|
|
90
|
+
" 'pickles',\n",
|
|
91
|
+
" video_file=EXAMPLE_VIDEO\n",
|
|
92
|
+
")"
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"cell_type": "raw",
|
|
97
|
+
"id": "138ff031-a124-4383-9db6-fd3cfe506b73",
|
|
98
|
+
"metadata": {},
|
|
99
|
+
"source": [
|
|
100
|
+
"with open(EXAMPLE_CSV, 'r') as f:\n",
|
|
101
|
+
" reader = csv.reader(f)\n",
|
|
102
|
+
" blah = list(\n",
|
|
103
|
+
" extract_viame_video_annotations(reader, EXAMPLE_VIDEO)\n",
|
|
104
|
+
" )"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"cell_type": "raw",
|
|
109
|
+
"id": "d39bc41e-f85a-4af3-a3c6-8084b6fd131a",
|
|
110
|
+
"metadata": {},
|
|
111
|
+
"source": [
|
|
112
|
+
"for row in blah:\n",
|
|
113
|
+
" print(row)"
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"cell_type": "code",
|
|
118
|
+
"execution_count": null,
|
|
119
|
+
"id": "1b73f026-fb2a-4bb4-80ca-01f755ad936f",
|
|
120
|
+
"metadata": {},
|
|
121
|
+
"outputs": [],
|
|
122
|
+
"source": []
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"cell_type": "code",
|
|
126
|
+
"execution_count": null,
|
|
127
|
+
"id": "3234f082-5aa8-48ef-ad86-4d6ac65d6dc4",
|
|
128
|
+
"metadata": {},
|
|
129
|
+
"outputs": [],
|
|
130
|
+
"source": []
|
|
131
|
+
}
|
|
132
|
+
],
|
|
133
|
+
"metadata": {
|
|
134
|
+
"kernelspec": {
|
|
135
|
+
"display_name": "Python 3 (ipykernel)",
|
|
136
|
+
"language": "python",
|
|
137
|
+
"name": "python3"
|
|
138
|
+
},
|
|
139
|
+
"language_info": {
|
|
140
|
+
"codemirror_mode": {
|
|
141
|
+
"name": "ipython",
|
|
142
|
+
"version": 3
|
|
143
|
+
},
|
|
144
|
+
"file_extension": ".py",
|
|
145
|
+
"mimetype": "text/x-python",
|
|
146
|
+
"name": "python",
|
|
147
|
+
"nbconvert_exporter": "python",
|
|
148
|
+
"pygments_lexer": "ipython3",
|
|
149
|
+
"version": "3.11.10"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"nbformat": 4,
|
|
153
|
+
"nbformat_minor": 5
|
|
154
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["flit_core >=3.2,<4"]
|
|
3
|
+
build-backend = "flit_core.buildapi"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "viame2coco"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "tools to convert VIAME output to COCO format"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "CScott Brown" },
|
|
11
|
+
]
|
|
12
|
+
dependencies = [
|
|
13
|
+
"pycocowriter",
|
|
14
|
+
"opencv-python"
|
|
15
|
+
]
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-r common.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
-r requirements/prod.txt
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import utils
|
|
3
|
+
import viame2coco.viame_manual_annotations
|
|
4
|
+
import viame2coco.viame2coco
|
|
5
|
+
|
|
6
|
+
def load_tests(loader, tests, ignore):
|
|
7
|
+
modules = [
|
|
8
|
+
viame2coco.viame_manual_annotations,
|
|
9
|
+
viame2coco.viame2coco
|
|
10
|
+
]
|
|
11
|
+
for module in modules:
|
|
12
|
+
tests = utils.doctests(module, tests)
|
|
13
|
+
return tests
|
|
14
|
+
|
|
15
|
+
if __name__ == '__main__':
|
|
16
|
+
unittest.main()
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import doctest
|
|
2
|
+
|
|
3
|
+
def doctests(module, tests):
|
|
4
|
+
"""
|
|
5
|
+
A helper function to combine unittest discovery with doctest suites.
|
|
6
|
+
|
|
7
|
+
Args:
|
|
8
|
+
module: The module to add doctests from.
|
|
9
|
+
tests: The existing TestSuite discovered by unittest.
|
|
10
|
+
|
|
11
|
+
Returns:
|
|
12
|
+
A combined TestSuite with doctests added.
|
|
13
|
+
"""
|
|
14
|
+
tests.addTests(doctest.DocTestSuite(module))
|
|
15
|
+
return tests
|
|
File without changes
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import pycocowriter
|
|
2
|
+
import csv
|
|
3
|
+
import json
|
|
4
|
+
import itertools
|
|
5
|
+
from collections.abc import Iterable
|
|
6
|
+
import pycocowriter.coco
|
|
7
|
+
from pycocowriter.csv2coco import Iterable2COCO, Iterable2COCOConfig
|
|
8
|
+
from pycocowriter.coco import COCOLicense, COCOInfo, COCOData
|
|
9
|
+
from .viame_manual_annotations import *
|
|
10
|
+
|
|
11
|
+
COCO_CC0_LICENSE = COCOLicense(
|
|
12
|
+
'CC0 1.0 Universal',
|
|
13
|
+
0,
|
|
14
|
+
'https://creativecommons.org/public-domain/cc0/'
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
viame_csv_config = {
|
|
18
|
+
'meta': {
|
|
19
|
+
'skiprows': 2
|
|
20
|
+
},
|
|
21
|
+
'filename': 1,
|
|
22
|
+
'label': 9,
|
|
23
|
+
'bbox_tlbr': {
|
|
24
|
+
'tlx': 2,
|
|
25
|
+
'tly': 3,
|
|
26
|
+
'brx': 4,
|
|
27
|
+
'bry': 5
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def passrows(iterable: Iterable, n: int = 0) -> Iterable:
|
|
32
|
+
'''
|
|
33
|
+
yield the first `n` rows in `iterable`.
|
|
34
|
+
Useful with `itertools.chain` and `map` to
|
|
35
|
+
apply a function to only certain rows of an iterable
|
|
36
|
+
|
|
37
|
+
Parameters
|
|
38
|
+
----------
|
|
39
|
+
iterable: Iterable
|
|
40
|
+
any iterable
|
|
41
|
+
n: int
|
|
42
|
+
the number of rows to skip
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
iterable: Iterable
|
|
47
|
+
the iterable arg, but starting from the n+1th row
|
|
48
|
+
'''
|
|
49
|
+
for i in range(n):
|
|
50
|
+
yield next(iterable)
|
|
51
|
+
|
|
52
|
+
def viame2coco_data(
|
|
53
|
+
viame_csv_file: str,
|
|
54
|
+
video_file: str | None = None,
|
|
55
|
+
video_frame_outfile_dir: str | None = None) -> tuple[
|
|
56
|
+
list[pycocowriter.coco.COCOImage],
|
|
57
|
+
list[pycocowriter.coco.COCOAnnotation],
|
|
58
|
+
list[pycocowriter.coco.COCOCategory]
|
|
59
|
+
]:
|
|
60
|
+
'''
|
|
61
|
+
extract the images, annotations, and categories from a VIAME-style
|
|
62
|
+
annotation csv, into COCO format. Filters the data to only MANUAL
|
|
63
|
+
annotations.
|
|
64
|
+
|
|
65
|
+
If the annotations are for a video file, also extract the images
|
|
66
|
+
for the manually-annotated frames
|
|
67
|
+
|
|
68
|
+
Parameters
|
|
69
|
+
----------
|
|
70
|
+
viame_csv_file: str
|
|
71
|
+
the file path location for the VIAME-style annotation csv
|
|
72
|
+
video_file: str | None
|
|
73
|
+
the file path location for the video which has been
|
|
74
|
+
annotated. If there is no video (i.e. the annotations
|
|
75
|
+
are for images), then this should be None
|
|
76
|
+
video_frame_outfile_dir: str | None
|
|
77
|
+
a directory to which the extracted frames are writ
|
|
78
|
+
|
|
79
|
+
Returns
|
|
80
|
+
-------
|
|
81
|
+
images: list[COCOImage]
|
|
82
|
+
a list of images contained in the CSV file, in COCO format,
|
|
83
|
+
with appropriately-generated surrogate keys
|
|
84
|
+
annotations: list[COCOAnnotation]
|
|
85
|
+
a list of the annotations contained in the CSV file, with
|
|
86
|
+
appropriate surrogate-key references to the images and categories
|
|
87
|
+
categories: list[COCOCategory]
|
|
88
|
+
a list of the categories contained in the CSV file, in COCO format,
|
|
89
|
+
with appropriately-generated surrogate keys
|
|
90
|
+
'''
|
|
91
|
+
with open(viame_csv_file, 'r') as f:
|
|
92
|
+
reader = csv.reader(f)
|
|
93
|
+
if video_file is not None:
|
|
94
|
+
reader = itertools.chain(
|
|
95
|
+
passrows(reader, 2),
|
|
96
|
+
extract_viame_video_annotations(
|
|
97
|
+
reader, video_file, outfile_dir=video_frame_outfile_dir
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
csv2coco = Iterable2COCO(
|
|
101
|
+
Iterable2COCOConfig(viame_csv_config)
|
|
102
|
+
)
|
|
103
|
+
images, annotations, categories = csv2coco.parse(reader)
|
|
104
|
+
return images, annotations, categories
|
|
105
|
+
|
|
106
|
+
def viame2coco(
|
|
107
|
+
viame_csv_file: str,
|
|
108
|
+
description: str,
|
|
109
|
+
video_file: str | None = None,
|
|
110
|
+
video_frame_outfile_dir: str | None = None,
|
|
111
|
+
license: pycocowriter.coco.COCOLicense = COCO_CC0_LICENSE,
|
|
112
|
+
version: str = '0.1') -> pycocowriter.coco.COCOData:
|
|
113
|
+
'''
|
|
114
|
+
Convert a VIAME-style annotation csv into COCO format
|
|
115
|
+
|
|
116
|
+
Parameters
|
|
117
|
+
----------
|
|
118
|
+
viame_csv_file: str
|
|
119
|
+
the file path location for the VIAME-style annotation csv
|
|
120
|
+
descriptions: str
|
|
121
|
+
the description of this dataset
|
|
122
|
+
video_file: str | None
|
|
123
|
+
the file path location for the video which has been
|
|
124
|
+
annotated. If there is no video (i.e. the annotations
|
|
125
|
+
are for images), then this should be None
|
|
126
|
+
video_frame_outfile_dir: str | None
|
|
127
|
+
a directory to which the extracted frames are writ
|
|
128
|
+
license: COCOLicense
|
|
129
|
+
the license under which these images are provided
|
|
130
|
+
Defaults to CC0 https://creativecommons.org/public-domain/cc0/
|
|
131
|
+
version: str
|
|
132
|
+
the version of this dataset, as a string
|
|
133
|
+
defaults to '0.1'
|
|
134
|
+
'''
|
|
135
|
+
|
|
136
|
+
now = datetime.datetime.now(datetime.timezone.utc)
|
|
137
|
+
coco_info = COCOInfo(
|
|
138
|
+
year = now.year,
|
|
139
|
+
version = version,
|
|
140
|
+
description = description,
|
|
141
|
+
date_created = now
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
#TODO probably should hoist this into a higher function
|
|
145
|
+
csv_location = os.path.split(viame_csv_file)[0]
|
|
146
|
+
if video_frame_outfile_dir is None:
|
|
147
|
+
video_frame_outfile_dir = csv_location
|
|
148
|
+
images, annotations, categories = viame2coco_data(
|
|
149
|
+
viame_csv_file, video_file=video_file,
|
|
150
|
+
video_frame_outfile_dir=video_frame_outfile_dir
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
return COCOData(
|
|
154
|
+
coco_info,
|
|
155
|
+
images,
|
|
156
|
+
annotations,
|
|
157
|
+
[license],
|
|
158
|
+
categories
|
|
159
|
+
)
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import os
|
|
3
|
+
import datetime
|
|
4
|
+
import numpy as np
|
|
5
|
+
from collections.abc import Sequence, Iterable
|
|
6
|
+
|
|
7
|
+
MS2S = 1000000
|
|
8
|
+
MS2M = MS2S*60
|
|
9
|
+
MS2H = MS2M*60
|
|
10
|
+
def time2micros(time: datetime.time) -> float:
|
|
11
|
+
'''
|
|
12
|
+
convert a datetime.time into total microseconds
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
>>> time2micros(datetime.time(1,1,1)) # 1 hour, 1 min, 1 sec
|
|
16
|
+
3661000000
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
time: datetime.time
|
|
23
|
+
the time to convert into microseconds
|
|
24
|
+
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
microseconds: float | int
|
|
28
|
+
the total number of microseconds in the time argument
|
|
29
|
+
'''
|
|
30
|
+
return time.hour * MS2H + time.minute * MS2M + time.second * MS2S + time.microsecond
|
|
31
|
+
|
|
32
|
+
def extract_frame_microseconds(
|
|
33
|
+
cv2_video_cap: cv2.VideoCapture,
|
|
34
|
+
microseconds: float,
|
|
35
|
+
outfile: str | None = None) -> np.ndarray | None:
|
|
36
|
+
'''
|
|
37
|
+
extract a frame from the provided cv2 video at the given number
|
|
38
|
+
of microseconds. Optionally write the frame to outfile.
|
|
39
|
+
|
|
40
|
+
Parameters
|
|
41
|
+
----------
|
|
42
|
+
cv2_video_cap: cv2.VideoCapture
|
|
43
|
+
the video from which to capture the frame
|
|
44
|
+
microseconds: float
|
|
45
|
+
the location in microseconds into the video
|
|
46
|
+
at which to extract the desired frame
|
|
47
|
+
outfile: str | None:
|
|
48
|
+
the optional filename to which the desired frame should
|
|
49
|
+
be writ
|
|
50
|
+
Returns
|
|
51
|
+
-------
|
|
52
|
+
image: numpy.ndarray | None
|
|
53
|
+
the video frame at the given number of microseconds, or None
|
|
54
|
+
if the frame read was unsuccessful. Additionally, the frame
|
|
55
|
+
may be written to a file as a side-effect if `outfile` was
|
|
56
|
+
passed as an argument.
|
|
57
|
+
'''
|
|
58
|
+
cv2_video_cap.set(cv2.CAP_PROP_POS_MSEC, microseconds // 1000)
|
|
59
|
+
success, image = cv2_video_cap.read()
|
|
60
|
+
if outfile is not None:
|
|
61
|
+
print(outfile)
|
|
62
|
+
cv2.imwrite(outfile, image)
|
|
63
|
+
return image
|
|
64
|
+
|
|
65
|
+
VIAME_CONFIDENCE_COL = 7
|
|
66
|
+
def viame_is_manual_annotation(viame_csv_row: Sequence) -> bool:
|
|
67
|
+
'''
|
|
68
|
+
returns whether a given row in a VIAME-style annotation output csv
|
|
69
|
+
represents a manual annotation or an automated annotation.
|
|
70
|
+
|
|
71
|
+
basically, just checks if the annotation confidence is 1
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
75
|
+
viame_csv_row: Sequence
|
|
76
|
+
a row read from a VIAME-style annotation csv
|
|
77
|
+
|
|
78
|
+
Returns
|
|
79
|
+
-------
|
|
80
|
+
is_manual_annotation: bool
|
|
81
|
+
a boolean representing whether this row is manual or not
|
|
82
|
+
'''
|
|
83
|
+
is_manual_annotation = (
|
|
84
|
+
(len(viame_csv_row) > VIAME_CONFIDENCE_COL)
|
|
85
|
+
and
|
|
86
|
+
(viame_csv_row[VIAME_CONFIDENCE_COL] == '1')
|
|
87
|
+
)
|
|
88
|
+
return is_manual_annotation
|
|
89
|
+
|
|
90
|
+
def construct_image_filename_from_video_frame(
|
|
91
|
+
video_filename: str,
|
|
92
|
+
time: datetime.time,
|
|
93
|
+
outfile_format: str | None,
|
|
94
|
+
outfile_dir: str | None) -> str:
|
|
95
|
+
'''
|
|
96
|
+
construct a filename from a given video file and frame time
|
|
97
|
+
|
|
98
|
+
Parameters
|
|
99
|
+
----------
|
|
100
|
+
video_filename: str
|
|
101
|
+
the file name of the video. This will be formatted into the
|
|
102
|
+
outfile_format as `video_filename`. See that arg for more details.
|
|
103
|
+
time: datetime.time
|
|
104
|
+
the time that locates the desired frame in the video
|
|
105
|
+
outfile_format: str | None
|
|
106
|
+
if None, defaults to '{video_filename}.%H.%M.%S.%f.jpg'
|
|
107
|
+
`video_filename` is the argument of this name to this function
|
|
108
|
+
The remainder is passed through a `strftime` from the time arg,
|
|
109
|
+
see the [`strftime` docs](https://docs.python.org/3/library/datetime.html#format-codes)
|
|
110
|
+
the extension `.jpg` will determine the output file format if this
|
|
111
|
+
filename is used to write an image file.
|
|
112
|
+
outfile_dir: str | None
|
|
113
|
+
if not None, this is simply path joined to the filename output
|
|
114
|
+
|
|
115
|
+
Returns
|
|
116
|
+
-------
|
|
117
|
+
frame_filename: str
|
|
118
|
+
a filename appropriate for the specified frame in the video
|
|
119
|
+
'''
|
|
120
|
+
if outfile_format is None:
|
|
121
|
+
outfile_format = '{video_filename}.%H.%M.%S.%f.jpg'
|
|
122
|
+
frame_filename = time.strftime(outfile_format).format(video_filename = video_filename)
|
|
123
|
+
if outfile_dir is not None:
|
|
124
|
+
frame_filename = os.path.join(outfile_dir, frame_filename)
|
|
125
|
+
return frame_filename
|
|
126
|
+
|
|
127
|
+
def filter_viame_manual_annotations(
|
|
128
|
+
viame_csv: Iterable[Sequence]) -> Iterable[Sequence]:
|
|
129
|
+
'''
|
|
130
|
+
filters an iterable of data rows read from a VIAME-style annotation csv
|
|
131
|
+
to only rows that contain manual annotations
|
|
132
|
+
|
|
133
|
+
Parameters
|
|
134
|
+
----------
|
|
135
|
+
viame_csv: Iterable[Sequence]
|
|
136
|
+
the data rows from a VIAME-style annotation csv
|
|
137
|
+
should not include the headers
|
|
138
|
+
|
|
139
|
+
Returns
|
|
140
|
+
-------
|
|
141
|
+
viame_csv: Iterable[Sequence]
|
|
142
|
+
the data rows in the input only when the annotations
|
|
143
|
+
are manual, skipping any automated annotations
|
|
144
|
+
'''
|
|
145
|
+
yield from filter(viame_is_manual_annotation, viame_csv)
|
|
146
|
+
|
|
147
|
+
VIAME_VIDEO_TIME_COL = 1
|
|
148
|
+
def extract_viame_video_annotations(
|
|
149
|
+
viame_csv: Iterable[Sequence],
|
|
150
|
+
video_file: str,
|
|
151
|
+
outfile_format: str | None = None,
|
|
152
|
+
outfile_dir: str | None = None) -> Iterable[Sequence]:
|
|
153
|
+
'''
|
|
154
|
+
extract the manual annotations and frames from a VIAME-style
|
|
155
|
+
annotaiton csv
|
|
156
|
+
|
|
157
|
+
Writes the frames to files.
|
|
158
|
+
|
|
159
|
+
Parameters
|
|
160
|
+
----------
|
|
161
|
+
viame_csv: Iterable[Sequence]
|
|
162
|
+
the data rows from a VIAME-style annotation csv
|
|
163
|
+
should not include the headers
|
|
164
|
+
video_filename: str
|
|
165
|
+
the file name of the video. This will be formatted into the
|
|
166
|
+
outfile_format as `video_filename`. See that arg for more details.
|
|
167
|
+
outfile_format: str | None
|
|
168
|
+
see `construct_image_filename_from_video_frame` signature
|
|
169
|
+
outfile_dir: str | None
|
|
170
|
+
see `construct_image_filename_from_video_frame` signature
|
|
171
|
+
|
|
172
|
+
Returns
|
|
173
|
+
-------
|
|
174
|
+
viame_csv: Iterable[Sequence]
|
|
175
|
+
the data rows in the input only when the annotations
|
|
176
|
+
are manual, skipping any automated annotations
|
|
177
|
+
'''
|
|
178
|
+
cap = cv2.VideoCapture(video_file)
|
|
179
|
+
video_filename_leaf = os.path.split(video_file)[1]
|
|
180
|
+
if outfile_dir is not None:
|
|
181
|
+
os.makedirs(outfile_dir, exist_ok=True)
|
|
182
|
+
for row in filter_viame_manual_annotations(viame_csv):
|
|
183
|
+
frame_time = datetime.time.fromisoformat(row[VIAME_VIDEO_TIME_COL])
|
|
184
|
+
microseconds = time2micros(frame_time)
|
|
185
|
+
frame_filename = construct_image_filename_from_video_frame(video_filename_leaf, frame_time, outfile_format, outfile_dir)
|
|
186
|
+
extract_frame_microseconds(cap, microseconds, frame_filename)
|
|
187
|
+
row[VIAME_VIDEO_TIME_COL] = frame_filename
|
|
188
|
+
yield row
|