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

Separation of Concern #8

Merged
merged 30 commits into from
Aug 14, 2024
Merged

Separation of Concern #8

merged 30 commits into from
Aug 14, 2024

Conversation

Agung-Krisna
Copy link
Collaborator

Separation of concerns

Separation of concern is important because right now the methods are very long and can contain different algorithm, each conveying different meaning. I want to further simplify it by breaking it into different classes and method. This has proven reduce the lines of code due to the removal of duplicating codes.

Another thing that I see is how related items are being treated as primitives, which leads into primitive obsession. I want to remediate that by encapsulating related items into singular class which can be instantiated using an object.

Long parameter list is also a symptom to lack of objects which can grow and become harder to maintain. Remediation plan for that is by creating sub methods that can reduce the number of parameter required for an object.

Moving on, by performing separation of concerns, development process can be made more streamlined as well as easier to maintain. This is mainly because our future endeavor for expanding the app is on the horizon, so ensuring that the development can be made as clear and as simple as possible is going to be a definite win.

Different concerns

AutoMapper should only have three methods, namely stream_using_cv2, stream_as_image, and generate_raw_outputs. Other methods should be delegated to different classes, according to their purpose.

  1. CV2Handler should handle tasks related to CV2 operations, such as calculating and drawing framerate, calculating bottom center, drawing detection boxes, and saving video result.
  2. ImageHandler should handle tasks related to the images used, namely the image2d and image3d. It should contain properties such as the image object itself, max height, and total width.
  3. HomographicHandler should handle tasks related to homographic transformation, which revolves around loading coordinates and transforming coordinates.
  4. Frame is a data class that holds properties such as the frame3d, frame2d, and frame count. Every used frame must be stored within the data class so that other methods can access and modify the same object.
  5. TrackerHandler should handle tasks related to tracking detected objects from the ModelInterpreter, it also needs to calculate bottom center automatically rather than processing it on the caller.

Notes on Backward Compatibility

I'm intentionally not removing the previous dot_vision.py and auto_mapper.py. Instead I took an initiative to create a new file to allow real time comparison between the previous version and the new version.

After all changes are accepted, I think it would not be necessary to keep the previous version of the code as all features have been fully recreated in the new version.

…and updating the process of getting p1 and p2 into tracker.top_left and tracker.bottom_right
…cv2(), .stream_as_image(), .generate_raw_outputs()
…ormation related tasks can be orchestrated through one place.
…e flask's app object to eliminate circular import
Copy link
Owner

@alvinwatner alvinwatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, great work Krisna! I know this is taking a lot of pain and sweat, but I bet it will be worth it down the road and we surely learn a lot from this. Just couple more things to be improved, look forward for the update!

auxiliary/cv2_handler.py Outdated Show resolved Hide resolved
auxiliary/cv2_handler.py Outdated Show resolved Hide resolved
auxiliary/debug_web_cv2.py Show resolved Hide resolved
auxiliary/new_auto_mapper.py Show resolved Hide resolved
@Nick-Achee
Copy link

Krishna this is a amazing ⚡️

@Agung-Krisna Agung-Krisna merged commit ccd90ab into main Aug 14, 2024
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

Successfully merging this pull request may close these issues.

3 participants