Coder Social home page Coder Social logo

fernaper / cv2-tools Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 3.0 9 MB

v2.4.0 - Library to help the drawing process with OpenCV. Thought to add labels to the images. Classification of images and much more.

License: MIT License

Python 99.65% Dockerfile 0.35%
artificial-intelligence constraints cv2 library opencv python python3 tools

cv2-tools's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cv2-tools's Issues

Upgrade intelligence if theres not a perfect solution

The algorithm that calculates all tags positions solves the problem if there is a perfect solution (is possible to find a solution without coliding tags with other tags or frames).

But if there is no option, right now it just ignore all the constraints and decide in order of priority.

Im thinking about soft constraints. With them we can choose the option with less coliding tags.

StorageCV2 more versatile ussage

Make it possible to process half of a video in the first time, and reproduce the first half and process and save the second one

Bug constraint algorithm

Traceback (most recent call last):
File "/var/www/facesync/script/edit_cron.py", line 245, in
edit_folder(folder, people_store, remove_videos=True)
File "/var/www/facesync/script/edit_cron.py", line 182, in edit_folder
edit_file(**video)
File "/var/www/facesync/script/edit_cron.py", line 196, in edit_file
save = generate_video_without_audio(complete_path, tmp_video, people_store)
File "/var/www/facesync/script/edit_cron.py", line 112, in generate_video_without_audio
frame = selector.draw(frame)
File "/usr/local/lib/python3.4/dist-packages/cv2_tools/Selection.py", line 230, in draw
specific_properties=self.specific_properties)
File "/usr/local/lib/python3.4/dist-packages/cv2_tools/Utils.py", line 549, in select_multiple_zones
position = best_position[i]
IndexError: list index out of range

Detected wrong behaviour

Here we should check for all the zones with all the other ones, not just a zone with the next one.

Inside tags contraint:
image

Tags position

Change priority positions
If not tags position are provided:
- First try to put the text on the Bottom Rigth corner
- If it doesn't fit, try to put the text Bottom Left corner
- If it doesn't fit, try to put the text Inside the rectangle
- If it doesn't fit, try to put the text On top of the rectangle

Print Warnings

If something is going wrong its a good idea to print some warnings (in stderr).
This will be usefull for the users.

Bug drawing some times

Traceback (most recent call last):
...
frame = selector.draw(frame)
File "/usr/local/lib/python3.6/dist-packages/cv2_tools/Selection.py", line 230, in draw
specific_properties=self.specific_properties)
File "/usr/local/lib/python3.6/dist-packages/cv2_tools/Utils.py", line 565, in select_multiple_zones
frame = select_zone(frame, zone, tags=tags, tag_position=position,
UnboundLocalError: local variable 'position' referenced before assignment

Bug selecting zone

Traceback (most recent call last):
File "people_counter_ever.py", line 124, in
frame = selector.draw(frame)
File "/usr/local/lib/python3.6/dist-packages/cv2_tools/Selection.py", line 230, in draw
specific_properties=self.specific_properties)
File "/usr/local/lib/python3.6/dist-packages/cv2_tools/Utils.py", line 565, in select_multiple_zones
frame = select_zone(frame, zone, tags=tags, tag_position=position,
UnboundLocalError: local variable 'position' referenced before assignment

Bug changing margin

I don't know why, but if you change the default value of the parameter margin, it will do weird things.
For now, until it is fixed, just don't change this value.

Allow free tags options

We want co be capable to change the tag color, the alpha of the rectangle, and all that kind of features.
Also we will need to be capable to save and load this data

Create Setup.py

We want to be capable to install this package via pip, this is why we need to create the setup with all the dependencies.
The sooner the better to be able to add versions.

Basic example of each class

I think that some times an example is better than an explanation.
So, It could be a good idea to create a basic example with each class, independent with the others.
Then we can create examples with more than one class, and finally a complete example.

Object to manage video or streams

The objective of this library is to have a fast development using OpenCV, therefore we can create an object to manage videos or streams in an easiest way than the basic OpenCV.

Possible workflows:

  • MP4 File or Stream (passing FPS) -> play (It could generate a JSON)
  • MP4 File or Stream + Json File (To draw all the information) -> Play
  • MP4 File or Stream -> for (get each frame) -> detect or do what ever you want -> draw detections -> Visualize (if you want to)

Adapt cv2-tools with YOLOv3

This library will be amazing if it is capable to manage YOLOv3 Automatically.
I don't know if it is possible in an eassy way, but, as I said, it could be amazing.

Detected bug tags on topside

When the position selected is top, the distance of the tags depends on the number of tags and this is not how it is supossed to work.

Add utilities folder

Im thinking about adding utilities folder with multiple methods to help us to work with opencv.
For example, you may want to get all images with a determinate extension in folder and all subdirectories.
Or maybe you want to do it, but separating it in multiple classes.

Bug when checking FPS

print('FPS: {}'.format(manager_cv2.get_fps()))
File "/usr/local/lib/python3.6/dist-packages/cv2_tools/Management.py", line 222, in get_fps
return round(self.count_frames / (self.final_time - self.initial_time),3)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'float'

Polygons with tags

Right now we can add tags to polygons only if we attach a zone to them.
I want to be capable to add tags without a selection.

I think the easiest way to solve this problem is just to change the alpha value of the attached zone to 0, so it is completle invisible, while it exists (becouse, we need and want to have this rectangle, because it is necessary for selection the possition of each tag).

But I think, the better way to attack this problem is not saving the rectangle itself, just save the polygon, and make Utils.py generate the rectangle but only for the constraints algorithm.

Why the second idea could be better?
Because with the first option, we are drawing rectangles. Invisible ones, but at the end spending time in an unnecessary task.

Support different shapes

Right now we only support rectangles, therefore we can create an object capable to receive coordinates of points and draw the complete shape.

For the first aproximation of tagging this shapes we are going to create virtual rectangles (not necessarily drawed). Therefore the tagging logic will work with this rectangle (ignoring all the points).

Example of output:

image

If all of this works well we can set a parameter to generate smooth curves:

See link

Create SelectorCV2 class

We want to be capable to call all the methods just creating an object that manage most of the things for us.

Create method to select multiple zones

Right now we can call the method select_zone() to draw a zone with his tags.
If you want to select more than a zone you need to call this method multiple times.
This is okay, but it is not perfect becouse the "intelligence" to position the tags don't ask the rest of the calls to that method.
Therefore, I think it is a good idea to create a new method called select_multiple_zone().
This method will try to posicionate correctly all the tags knowing the other zones.

Porbably we will need to add another library to do this: https://labix.org/python-constraint

Negative coordinates with free tags

I think it could be a really good idea if we allow the user to pass negative coordinates to the shape.
So, if we indicated a tag to be in the coordinates (-10,-10), what we want is to draw the tag in te bottom right corner, with ten pixels of distance with both edges.
If you want to do it by hand it is not that easy, so we can try to help.

Bug loading JSON file

Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/cv2_tools/Storage.py", line 40, in json_unzip
compressed_dict = json.loads(compressed_dict)
File "/usr/lib/python3.5/json/init.py", line 312, in loads
s.class.name))
TypeError: the JSON object must be str, not 'bytes'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "send_test.py", line 145, in
load_video(sys.argv[2])
File "send_test.py", line 125, in load_video
storage_cv2 = StorageCV2(path='salida.json')
File "/usr/local/lib/python3.5/dist-packages/cv2_tools/Storage.py", line 120, in init
self.load_from_file(path)
File "/usr/local/lib/python3.5/dist-packages/cv2_tools/Storage.py", line 201, in load_from_file
self.complete_structure = json_unzip(json.load(json_file))
File "/usr/local/lib/python3.5/dist-packages/cv2_tools/Storage.py", line 42, in json_unzip
raise RuntimeError("Could interpret the unzipped contents")
RuntimeError: Could interpret the unzipped contents

Unexpected cv2 error

Some times, if you try to execute cv2.imshow, it will do it wrong, I found a way to solve it.
Just add cv2.waitKey(1) (somewhere inside the main loop).
I wan't to make it invisible to the user.

Create a Github Page

  • Create a folder called Docs
  • Inside this folder create a basic web with all of the documentation: It could be a good idea to use Sphinx to generate the documentation.

Option to assign colors to classes

When you are selecting items, you may want to select each class with a different color.
So it will be perfect if the library manage it for you (only if you specify that you want this functionality)

Bug positioning tags

Right tags, and left tags have also bugs.
Probably it will be the same as top tags.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.