Skip to content

Commit

Permalink
CAP: working standalone + API base code, cmake library missing
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3 committed Jun 18, 2023
1 parent 61e84e0 commit 6d5c008
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 58 deletions.
40 changes: 9 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,42 +86,20 @@ gantt
# TTool
This is the repository hosting the API for TTool. It is a program able to detect the 6dof of a fix toolhead from the feed of a fix camera view.

```mermaid
flowchart TB
A(TTool API)
B(TSegment API) --> A
C(TSlet API) --> A
D(ML API*) --> A
## How to use

A --> E(Augmented Carpentry)
```bash
cmake -S . -B build && cmake --build build && ./build/ttool -c 0 -l "./assets/calibration_orange_A_1280_720_r.yml" -t -s
```
where,

## TTool Dataflow

```mermaid
graph TD;
cam[TTool::Camera]
uii["TTool::PoseInput / ML::PoseEstimator"]
seg[TSegment::Segmentation]
%% mle[ML::PoseEstimator]
tkr[TSLET::ObjectTracker]
cam--image-->seg
cam--image-->uii
seg--segmentationMask-->uii
seg--segmentationMask-->tkr
- `[-h,--help]`: print this message
- `[-c,--camera]`: camera index
- `[-l,--calib]`: calibration file for the camera
- `[-s,--save]`: record video of session, give custom path for output (default: ./default)
- `[-t,--trackPose]`: it saves all poses and objects in a log file


uii--initialPose-->tkr
uii--toolheadID-->tkr
%% uii<-->mle
tkr--refinedPose-->TTool::Visualizer
tkr--3DObject-->TTool::Visualizer
```

## CI/CD
If you commit and push some code that does not influence the compilation (e.g. readme, docs, etc), add one of these texts to your commit message, it will stop the run of the github action.
```
Expand Down
Binary file added img/logo_linux_green.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion run_cam.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
./build.sh
./build/ttool ./live_camera/config.yml
./build/ttool
5 changes: 0 additions & 5 deletions src/input.hh
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ namespace ttool
m_VisualizerPtr->ToggleShowKeymaps();
break;
}
case 'n':
{
m_VisualizerPtr->ToggleSavingImages();
break;
}
default:
break;
}
Expand Down
17 changes: 7 additions & 10 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ int main(int argc, char **argv)
"[-h,--help]: print this message\n" \
"[-c,--camera]: camera index\n" \
"[-l,--calib]: calibration file for the camera\n" \
"[-s,--save]: save image path\n" \
"[-s,--save]: record video of session\n" \
"[-t,--trackPose]: it saves all poses and objects in a log file\n";
int cameraID = 0;
std::string calibFilePath;
bool trackPose = false;
bool isVideoRecording = false;
std::string saveImagePath = "./debug/";
if (argc == 1)
{
Expand Down Expand Up @@ -69,17 +70,12 @@ int main(int argc, char **argv)
}
else if (arg == "-s" || arg == "--save")
{
isVideoRecording = true;
if (i + 1 < argc)
{
saveImagePath = argv[++i];
std::cout << "\033[1;35m[Info]: Save image path: " << saveImagePath << "\033[0m" << std::endl;
}
else
{
std::cout << "\033[1;31m[Error]: save image path is not specified\033[0m" << std::endl;
std::cout << helpMsg << std::endl;
return 1;
}
std::cout << "\033[1;35m[Info]: Save video path: " << saveImagePath << "\033[0m" << std::endl;
}
else if (arg == "-t" || arg == "--trackPose")
{
Expand Down Expand Up @@ -111,14 +107,15 @@ int main(int argc, char **argv)
ttool->GetModelManager(),
configPtr->GetConfigData().Zn,
configPtr->GetConfigData().Zf);
visualizerPtr->SetSaveImagePath(saveImagePath);
if (isVideoRecording) {visualizerPtr->SetSaveImagePath(saveImagePath);}
cameraPtr->UpdateCamera();
ttool::InputVisualizer inputVisualizer(visualizerPtr);

PoseWriter poseWriter = PoseWriter("trackingPose.log", __TTOOL_CONFIG_PATH__, configPtr->GetConfigData().ModelFiles);

// main thread
bool exit = false;
if (isVideoRecording) {visualizerPtr->ToggleSavingImages();}
while (!exit)
{
int fid = 0;
Expand Down Expand Up @@ -184,6 +181,6 @@ int main(int argc, char **argv)
}

cv::destroyAllWindows();
ttool::makeVideoFromAllSavedImages(saveImagePath);
if (isVideoRecording) {ttool::standaloneUtils::makeVideoFromAllSavedImages(saveImagePath);}

}
8 changes: 1 addition & 7 deletions src/util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ inline bool IsFileExist (const std::string& name) {

} // namespace tk

namespace ttool
namespace ttool::standaloneUtils
{
inline void createVideo(const std::filesystem::path& path)
{
Expand Down Expand Up @@ -60,19 +60,13 @@ namespace ttool
ss << std::put_time(&tm, "%Y-%m-%d");
std::string currentDate = ss.str();

// Check if the directory exists
if (std::filesystem::exists(directoryPath) && std::filesystem::is_directory(directoryPath)) {
// Iterate over the directory entries
for (const auto& entry : std::filesystem::directory_iterator(directoryPath)) {
// Check if the entry is a directory
if (entry.is_directory()) {
// Get the directory name and print it
std::string folderName = entry.path().filename().string();
if (startsWith(folderName, currentDate))
{
std::cout << "Folder: " << entry.path().string() << std::endl;

// Create the video
createVideoAndDeleteImages(entry.path().string());
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/visualizer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ namespace ttool::standaloneUtils
*/
void SetSaveImagePath(std::string path)
{
// if it doesn't exists create a folder
if (!std::filesystem::exists(path))
{
std::filesystem::create_directory(path);
}
m_ImageSavePath = path;
}

Expand Down Expand Up @@ -78,14 +83,13 @@ namespace ttool::standaloneUtils
else
{
m_IsSavingImages = true;
// Generate a folder name based on the current time

std::time_t t = std::time(nullptr);
std::tm tm = *std::localtime(&t);
std::stringstream ss;
ss << m_ImageSavePath << "/" << std::put_time(&tm, "%Y-%m-%d-%H-%M-%S") << "/";
std::string path = ss.str();

// Create the folder
std::filesystem::create_directory(path);
std::filesystem::create_directory(path + "/raw/");

Expand Down
3 changes: 1 addition & 2 deletions util/load_dataset_2_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def main(dataset_path : str, config_path : str) -> None:
new_lines_modelFiles : list[str] = []
new_lines_gtPoses : list[str] = []
for i in range(len(model_obj_paths)):
# load the model path from the file
new_model_path : str = ""
new_lines_modelFiles.append(" - \"{}\"\n".format(model_obj_paths[i]))

Expand All @@ -117,8 +118,6 @@ def main(dataset_path : str, config_path : str) -> None:
for line in lines:
new_model_path += line
new_lines_gtPoses.append("{}\n".format(new_model_path))
# identity_matrix : str = " - [ 1, 0, 0,\n 0, 1, 0,\n 0, 0, 1,\n 0, 0, 0 ]\n"
# new_lines_gtPoses.append(identity_matrix)

with open(config_path, "r+") as f:
lines = f.readlines()
Expand Down

0 comments on commit 6d5c008

Please sign in to comment.