-
Notifications
You must be signed in to change notification settings - Fork 18
Create a visualization class and wire it through the code #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c40bd43
Create a visualization class and wire it through the code
NoureldinYosri 8f4b676
nit
NoureldinYosri 00942a3
fix test
NoureldinYosri 0edd321
Add missing files
NoureldinYosri f6c528a
nit
NoureldinYosri 6c9bc7b
fix
NoureldinYosri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
|
|
||
| #include "visualization.h" | ||
|
|
||
| void Visualizer::add_errors(const std::vector<common::Error>& errors) { | ||
| for (auto& error : errors) { | ||
| lines.push_back(error.str()); | ||
| } | ||
| } | ||
| void Visualizer::add_detector_coords(const std::vector<std::vector<double>>& detector_coords) { | ||
| for (size_t d = 0; d < detector_coords.size(); ++d) { | ||
| std::stringstream ss; | ||
| ss << "Detector D" << d << " coordinate ("; | ||
| size_t e = std::min(3ul, detector_coords[d].size()); | ||
| for (size_t i = 0; i < e; ++i) { | ||
| ss << detector_coords[d][i]; | ||
| if (i + 1 < e) ss << ", "; | ||
| } | ||
| ss << ")"; | ||
| lines.push_back(ss.str()); | ||
| } | ||
| } | ||
|
|
||
| void Visualizer::add_activated_errors(const std::vector<size_t>& activated_errors) { | ||
| std::stringstream ss; | ||
| ss << "activated_errors = "; | ||
| for (size_t oei : activated_errors) { | ||
| ss << oei << ", "; | ||
| } | ||
| lines.push_back(ss.str()); | ||
| } | ||
|
|
||
| void Visualizer::add_activated_detectors(const boost::dynamic_bitset<>& detectors, | ||
| size_t num_detectors) { | ||
| std::stringstream ss; | ||
| ss << "activated_detectors = "; | ||
| for (size_t d = 0; d < num_detectors; ++d) { | ||
| if (detectors[d]) { | ||
| ss << d << ", "; | ||
| } | ||
| } | ||
| lines.push_back(ss.str()); | ||
| } | ||
|
|
||
| void Visualizer::write(const char* fpath) { | ||
| FILE* fout = fopen(fpath, "w"); | ||
|
|
||
| for (std::string& line : lines) { | ||
| fprintf(fout, line.c_str()); | ||
| fputs("\n", fout); | ||
| } | ||
|
|
||
| fclose(fout); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef _VISUALIZATION_H | ||
| #define _VISUALIZATION_H | ||
|
|
||
| #include <boost/dynamic_bitset.hpp> | ||
| #include <list> | ||
| #include <vector> | ||
|
|
||
| #include "common.h" | ||
|
|
||
| struct Visualizer { | ||
| void add_detector_coords(const std::vector<std::vector<double>> &); | ||
| void add_errors(const std::vector<common::Error> &); | ||
| void add_activated_errors(const std::vector<size_t> &); | ||
| void add_activated_detectors(const boost::dynamic_bitset<> &, size_t); | ||
|
|
||
| void write(const char *fpath); | ||
|
|
||
| private: | ||
| std::list<std::string> lines; | ||
| }; | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #include <pybind11/iostream.h> | ||
| #include <pybind11/numpy.h> | ||
| #include <pybind11/operators.h> | ||
| #include <pybind11/pybind11.h> | ||
| #include <pybind11/stl.h> | ||
|
|
||
| #include "visualization.h" | ||
|
|
||
| namespace py = pybind11; | ||
|
|
||
| void add_visualization_module(py::module& root) { | ||
| auto m = root.def_submodule("viz", "Module containing the visualization tools"); | ||
| py::class_<Visualizer>(m, "Visualizer") | ||
| .def(py::init<>()) | ||
| .def("write", &Visualizer::write, py::arg("fpath")); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LalehB is it supposed to be activated_detectors or activated_dets ... the script seems to look for _dets
tesseract-decoder/viz/to_json.py
Line 49 in 0a7aa24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NoureldinYosri yeah amazing catch! it used to be
activated_detsand then in the code got changed toactivated_detectorsbut apparently the visualization did not get updated! thanks a lot!